GLSL export from Unity concerns.

edited August 2016 in GLSL / Shaders

Hey Guys,

GLSL Noob here.

Working in Unity, when it compiles our shaders into GLSL we start to get shader which to me seem unoptimized.

In the following shader i am completely confused as to what the point is of declaring and assigning the variables tmpvar_33 or tmpvar_34 as we already have the value tmpvar_32 which these are just "subsets" of.

In some of our other shaders variables are declared and then only used once more when the value could have simply been used where you needed it.

Am I ignorant of something?

uniform vec4 _Color;
uniform vec4 _LightColor0;
uniform sampler2D _MainTex;
uniform vec4 _WorldSpaceLightPos0;
void main ()
{
    vec4 c;
    vec4 tmpvar_32;
    tmpvar_32 = texture2D (_MainTex, gl_TexCoord[0].xy) * _Color;
    vec3 tmpvar_33;
    tmpvar_33 = tmpvar_32.xyz;
    float tmpvar_34;
    tmpvar_34 = tmpvar_32.w;
    vec4 c_i0_i1;
    c_i0_i1.xyz = ((tmpvar_33 * _LightColor0.xyz) *
        (max (0.0, dot (gl_TexCoord[1].xyz, _WorldSpaceLightPos0.xyz)) * 2.0)).xyz;
    c_i0_i1.w = (vec4(tmpvar_34)).w;
    c = c_i0_i1;
    c.xyz = (c_i0_i1.xyz + (tmpvar_33 * gl_TexCoord[2].xyz)).xyz;
    c.w = (vec4(tmpvar_34)).w;
    gl_FragData[0] = c.xyzw;
}

Thanks for your time.

Tagged:

Answers

  • edited August 2016

    This is a processing forum, not a unity forum or a glsl forum.

    That said, I guess it's just the unity generator making things easier for itself. You could probably tidy up the result slightly or just put a comment at the top saying they were generated and might look a bit weird.

Sign In or Register to comment.