Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by moshev · Dec 23, 2016 at 09:59 AM · shadersshaderlabprecision

How to use double-precision floats in a shader

I want to build a platform for exploring 3D fractals in Unity. These are usually drawn using raycasting and distance marching, so all the interesting algorithms are going to be implemented in shader code. I've done some experimenting and it seems Unity will fit the bill, but I would really like to do the computations using 64-bit double-precision floats, instead of the default 32-bit ones.

Is there any way I can specify double-precision floats for a piece of shader code? I just need a few specific inner loops to run with double precision, while everything else - input parameters, output values, etc. can be standard floats. I'm obviously aiming to run my code on mid/high-end desktop GPUs.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Dec 23, 2016 at 01:57 PM

Well, GPUs are designed around the 32 bit floating point type. The support depends on the used shader language. Also for example the cg language "allows profiles to treat double as float", so using double in your shader code does not necessarily mean the GPU conducts calculations in double precision. Only a few GPUs actually have hardware support for double. Apart from having support for double, certain calculations might still be calculated in SP (single precision) like most transcendental operations (sqrt, "e^x", pow, log, sin, cos, ...).

So unless you are sure that you have a specific hardware that actually supports double precision floats, it's probably not worth using them. Again GPUs are optimised for 32 bit floating point. It might even "elevate" half or fixed variables to float or "degrade" double to float.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Dec 23, 2016 at 01:58 PM 0
Share

That said i personally have never tried to use double in a shader (and never was in need ^^). I've done some mandelbrot rendering in Unity, however conducted on the CPU. For example this one in webGL. I only calculate one iteration per frame to get the nice "animation". This simply uses doubles so no infinite zoom ^^. In the future the link might no longer work as this is a simple free hoster. Unfortunately Dropbox now prevents to directly showing html files and soon they drop the support for the old public folder so i'm sill searching for an alternative ^^. I've posted so many links here on UA and soon they all will fail.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use AlphaTest with a CGPROGRAM 1 Answer

How do I keep an object lit when a light moves past it? 0 Answers

Found undocumented ZTest mode, unity_GUIZTestMode for Shader. What kind of ZTest mode this is? 3 Answers

shader unlit transparent + tint settings 0 Answers

How to use Unity3d shader to mask another two-pass shader? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges