HI guys, i have little problem with converting an old unity 2.6 d3d9 shader to unity 3 gles. I can't finde the right equivalent for the modulo function mod(x,y). I tried %, modf(x,y), x mod y. my includs are CGPROGRAM // Upgrade NOTE: excluded shader from Xbox360; has structs without semantics (struct v2f members uv,uv2) #pragma exclude_renderers xbox360 #pragma only_renderers gles #pragma vertex vert #pragma fragment frag #pragma multi_compile_builtin #pragma fragmentoption ARB_fog_exp2 #pragma fragmentoption ARB_precision_hint_fastest #include "UnityCG.cginc" #include "AutoLight.cginc" Does anyone know the right one? Thanks for your help and clues.
Hi, DomBomDom, the piece of code that you provided is not for GLSL, it is for a CG shader. take a look at this page: http://unity3d.com/support/documentation/Manual/Shaders.html and here you can find the function you need: http://http.developer.nvidia.com/CgTutorial/cg_tutorial_appendix_e.html Hope this helps.
Thanks a lot. it's fmod(x,y). I know that is it a CG shader. But Unity usually ports it to GLSL. Using fmod works fine. Don't know why it worked with mod before. By the way i reworte the shader to GLSL manually. I am looking forward to see the perfomrance differences on an i device. Don't have one here right now. I'll post it later. Thanks again...
DomBomDom, PM me or write here, about your test results on iDevice. i'm very interested in this. Thanks.
I too was attempting to convert a GLSL shader to CG. The original shader had a loop that iterated 255 times. I got an error that said I had exceeded the number of registers allowed (32). When I changed the loop to iterate fewer times the error went away. Is this a bug in the optimization code? I looked at the compiled version and it had: Code (csharp): while (true) { if ((i_1 >= 24)) { break; }; vec2 tmpvar_31; tmpvar_31.x = (vec2(((z.x * z.x) - (z.y * z.y)))).x; tmpvar_31.y = (vec2(((2.0 * z.x) * z.y))).y; vec2 tmpvar_32; tmpvar_32 = (cc + tmpvar_31); z = tmpvar_32; float tmpvar_33; tmpvar_33 = dot (tmpvar_32, tmpvar_32); m2 = tmpvar_33; if ((tmpvar_33 > 1024.0)) { break; }; co = (co + 1.0); i_1 = (i_1 + 1); }; The test for i_1 >= 24 being the change I had to make in order for it to compile. So... I copied the compiled version and created a new shader, pasting into my text editor the compiled version with the 24 changed to 256 and it let me do that, no errors. Strange workaround.