Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Almighty_gir · Sep 14, 2013 at 01:06 PM · shaderhlslbitwise

Bitwise operations in hlsl, is there an alternative method?

So, i'm writing a shader, and part of this shader involved IBL.

I'm trying to find a good way to sample from a hemisphere (cubemap) using importance sampling, and part of that involves using the Hammersley Point method, referenced here: http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html

the code in question is this, which is GLSL:

         float radicalInverse_VdC(uint bits) {
             bits = (bits << 16u) | (bits >> 16u);
             bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
             bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
             bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
             bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
             return float(bits) * 2.3283064365386963e-10; // / 0x100000000
             }
             //The ith point xi is then computed by            
              vec2 Hammersley(uint i, uint N) 
              {
             return vec2(float(i)/float(N), radicalInverse_VdC(i));
             }

the problem is, the rest of the shader is written in HLSL, and i don't want to rewrite it in GLSL. since bitwise operations are a shader model 4.0 and above feature, i'm wondering why i can't just do it in HLSL anyway. but that's not really the question here (although, if anyone can answer that would be great!). the question is - is there an alternate method of producing the same results?

cheers, Lee.

Comment
Add comment · Show 3
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 kevinmore · Jan 05, 2017 at 06:54 AM 0
Share

Did you find a solution?

avatar image Almighty_gir kevinmore · Jan 05, 2017 at 07:01 AM 0
Share

the solution i had was incredibly slow at the time, and that was to do the bitwise operation in a script and generate a lookup table for the shader to use.

it should be noted that i was doing this to create a PBR GGX shader in Unity, and while i succeeded, there's no point pursuing it now as it's the default for the current versions of Unity.

avatar image damart3d · Jan 05, 2018 at 04:36 PM 0
Share

Hi! When I was writing the importance sampling, the sampling itself, not the random or calculations was the bottleneck. Usage of pre-filtered importance sampling gave me significant speed boost(I think because of cache and bandwidth problems): http://damart3d.blogspot.com/2016/05/substance-painter-shader-unreal-engine.html

0 Replies

· Add your reply
  • Sort: 

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

sampler2d object has no methods 1 Answer

Bitwise & Operator in Shaders? 1 Answer

Creating a cup of water using Unity Pro Water 1 Answer

Shader float4 component values computing strangely 0 Answers

Add additional UV channel for Blit 1 Answer


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