Hi,
i recently had to do some image heavy things. First i prototyped the idea in BlitzMax, rewrote it with threading out of curiosity just to see that it was still too slow. So i ended up using GLSL which did the job just fine. Finally and at some point i need such a solution in Unity as well.
I read that you can use HLSL, CG and GLSL in Unity. If i understood things right then a.o. for the sake of the Windows platform you shouldn’t use GLSL directly. Which leaves HLSL and CG. In which do you best write your shaders in Unity?
Some of the shader examples in the docs are older, some are newer, so i’m not sure if all the suggestions are still fine. Does there exist something like a specific shader which is written in several languages, for a comparison and to see the differences of each implementation? As i’m not using shaders on a daily basis i sometimes find it kind of confusing which example uses exactly what and i found that whilst certain intrinsic functions or ShaderLab built in values were working, others somehow didn’t.
Can you write HLSL shaders which run in Unity without any problems or should you use CG instead? When i understood things right, you should go with Surface shaders everywhere a flexible way of lightning is involved and for things like image effects you can go with CG/HLSL and setting up the vertex/fragment shaders on your own.
Last but but not least a few more specific questions:
#1 How do you obtain from an CG/HLSL/Surface shader the uv position of a projected textured surface? And can you get that relative position from the uv-space also if there isn’t a texture applied as well?
#2 What’s the equivalent to GLSL’s gl_FragCoord and how do you obtain the max resolution (_ScreenParams?)?
#3 How do you pass parameters from let’s say a fragment shader back to a script in Unity?
Thanks!