Home | History | Annotate | Download | only in ShaderLib
      1 #import "Common/ShaderLib/Common.glsllib"
      2 
      3 vec3 Texture_GetNormal(in sampler2D normalMap, in vec2 texCoord){
      4     #ifdef NORMAL_LATC
      5         return Common_UnpackNormalLA( texture2D(normalMap, texCoord) );
      6     #else
      7         return Common_UnpackNormal( texture2D(normalMap, texCoord).rgb );
      8     #endif
      9 }
     10 
     11 #ifdef DXT_YCOCG
     12 const mat4 ycocg_mat = mat4( 1.0, -1.0,  0.0,                 1.0,
     13                              0.0,  1.0, -0.5 * 256.0 / 255.0, 1.0,
     14                             -1.0, -1.0,        256.0 / 255.0, 1.0,
     15                              0.0,  0.0,  0.0,                 0.0 );
     16 #endif
     17 
     18 vec4 Texture_GetColor(in sampler2D colorMap, in vec2 texCoord){
     19     #ifdef DXT_YCOCG
     20         vec4 color = texture2D(colorMap, texCoord);
     21         // fast YCoCg decode:
     22         color.z = 1.0 / ((color.z * ( 255.0 / 8.0 )) + 1.0);
     23         color.xy *= color.z;
     24         return color * ycocg_mat;
     25 
     26         // slow decode:
     27         //float Y = color.a;
     28         //float scale = 1.0 / ((255.0 / 8.0) * color.b + 1.0);
     29         //const float offset = 128.0 / 255.0;
     30         //float Co = (color.r - offset) * scale;
     31         //float Cg = (color.g - offset) * scale;
     32 
     33         //float R = Y + Co - Cg;
     34         //float G = Y + Cg;
     35         //float B = Y - Co - Cg;
     36 
     37         //return vec4(R, G, B, 1.0);
     38     #else
     39         return texture2D(colorMap, texCoord);
     40     #endif
     41 }