Search Unity

Modulo GLSL

Discussion in 'Shaders' started by DomBomDom, Oct 3, 2010.

  1. DomBomDom

    DomBomDom

    Joined:
    Mar 19, 2010
    Posts:
    9
    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.
     
  2. robotive

    robotive

    Joined:
    Apr 17, 2009
    Posts:
    59
  3. DomBomDom

    DomBomDom

    Joined:
    Mar 19, 2010
    Posts:
    9
    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...
     
    Tonymotion likes this.
  4. robotive

    robotive

    Joined:
    Apr 17, 2009
    Posts:
    59
    DomBomDom, PM me or write here, about your test results on iDevice. i'm very interested in this.

    Thanks.
     
  5. CrystalVisions

    CrystalVisions

    Joined:
    Sep 11, 2007
    Posts:
    61
    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):
    1.  while (true) {
    2.     if ((i_1 >= 24)) {
    3.       break;
    4.     };
    5.     vec2 tmpvar_31;
    6.     tmpvar_31.x = (vec2(((z.x * z.x) - (z.y * z.y)))).x;
    7.     tmpvar_31.y = (vec2(((2.0 * z.x) * z.y))).y;
    8.     vec2 tmpvar_32;
    9.     tmpvar_32 = (cc + tmpvar_31);
    10.     z = tmpvar_32;
    11.     float tmpvar_33;
    12.     tmpvar_33 = dot (tmpvar_32, tmpvar_32);
    13.     m2 = tmpvar_33;
    14.     if ((tmpvar_33 > 1024.0)) {
    15.       break;
    16.     };
    17.     co = (co + 1.0);
    18.     i_1 = (i_1 + 1);
    19.   };
    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.