Thursday, August 18, 2011

Unity GPU Noise (Part 2)

Sheesh! Yet another 5 months have passed by!

When I was creating the demo of GPU Noise in Unity, I kept getting a "function 'tex2Dlod' not supported in this profile" error. I couldn't figure out why except that it was an OpenGL issue. So, I simply forced my shaders to exclude OpenGL and OpenGL ES renderers (#pragma exclude_renderers opengl gles). Obviously this is not the best solution, so I decided to dive into it again.

It turns out that the error goes away if you instead force the shader to compile to GLSL (#pragma glsl). I have no idea why this fixes the problem, since it was an OpenGL issue in the first place, but whatever. Forcing the shaders to compile to GLSL brought up two other issues that I had to fix.

1) GLSL doesn't support default parameters (Cg and HLSL do). This means that I had to go duplicate all of my shader functions that used them, which were a lot.

2) GLSL doesn't support the switch statement. I had to go manually unroll my switch statements to be if-else trees. This one really confused me because all of the GLSL documentation seems to indicate that switch is indeed in the language, so this might just be a Unity issue.

You can check out the updated demo here:

Hopefully it works on Mac now, but I haven't been able to test it out yet. Feel free to let me know!