bgfx/3rdparty/glsl-optimizer/tests/fragment/complex-treeleaf-inES.txt
Branimir Karadzic dee3fe5266 Initial commit.
2012-04-03 20:30:07 -07:00

137 lines
4.6 KiB
Text

void xll_clip(float x) {
if ( x<0.0 ) discard;
}
float xll_saturate( float x) {
return clamp( x, 0.0, 1.0);
}
vec2 xll_saturate( vec2 x) {
return clamp( x, 0.0, 1.0);
}
vec3 xll_saturate( vec3 x) {
return clamp( x, 0.0, 1.0);
}
vec4 xll_saturate( vec4 x) {
return clamp( x, 0.0, 1.0);
}
mat2 xll_saturate(mat2 m) {
return mat2( clamp(m[0], 0.0, 1.0), clamp(m[1], 0.0, 1.0));
}
mat3 xll_saturate(mat3 m) {
return mat3( clamp(m[0], 0.0, 1.0), clamp(m[1], 0.0, 1.0), clamp(m[2], 0.0, 1.0));
}
mat4 xll_saturate(mat4 m) {
return mat4( clamp(m[0], 0.0, 1.0), clamp(m[1], 0.0, 1.0), clamp(m[2], 0.0, 1.0), clamp(m[3], 0.0, 1.0));
}
struct LeafSurfaceOutput {
mediump vec3 Albedo;
mediump vec3 Normal;
mediump vec3 Emission;
mediump float Translucency;
mediump float ShadowOffset;
mediump float Specular;
mediump float Gloss;
mediump float Alpha;
};
struct Input {
highp vec2 uv_MainTex;
highp vec4 color;
};
struct v2f_surf {
highp vec4 pos;
highp vec2 hip_pack0;
highp vec4 lop_color;
highp vec3 lightDir;
highp vec3 viewDir;
highp vec2 _LightCoord;
};
uniform sampler2D _BumpSpecMap;
uniform highp vec4 _Color;
uniform highp float _Cutoff;
uniform highp vec4 _LightColor0;
uniform sampler2D _LightTexture0;
uniform sampler2D _MainTex;
uniform mediump float _ShadowStrength;
uniform mediump vec3 _TranslucencyColor;
uniform sampler2D _TranslucencyMap;
uniform mediump float _TranslucencyViewDependency;
mediump vec4 UnpackNormal( in mediump vec4 packednormal );
void surf( in Input IN, inout LeafSurfaceOutput o );
mediump vec4 LightingTreeLeaf( in LeafSurfaceOutput s, in mediump vec3 lightDir, in mediump vec3 viewDir, in mediump float atten );
mediump vec4 xlat_main( in v2f_surf IN );
mediump vec4 UnpackNormal( in mediump vec4 packednormal ) {
mediump vec4 normal;
normal.xy = ((packednormal.wy * 2.00000) - 1.00000);
normal.z = sqrt( ((1.00000 - (normal.x * normal.x )) - (normal.y * normal.y )) );
return normal;
}
void surf( in Input IN, inout LeafSurfaceOutput o ) {
mediump vec4 c;
mediump vec4 trngls;
mediump vec4 norspc;
c = texture2D( _MainTex, IN.uv_MainTex);
o.Albedo = ((c.xyz * _Color.xyz ) * IN.color.w );
trngls = texture2D( _TranslucencyMap, IN.uv_MainTex);
o.Translucency = trngls.z ;
o.Gloss = (trngls.w * _Color.x );
o.Alpha = c.w ;
norspc = texture2D( _BumpSpecMap, IN.uv_MainTex);
o.Specular = norspc.x ;
o.ShadowOffset = norspc.z ;
o.Normal = vec3( UnpackNormal( norspc));
}
mediump vec4 LightingTreeLeaf( in LeafSurfaceOutput s, in mediump vec3 lightDir, in mediump vec3 viewDir, in mediump float atten ) {
mediump vec3 h;
mediump float nl;
mediump float nh;
mediump float spec;
mediump float backContrib;
mediump vec3 translucencyColor;
mediump vec4 c;
h = normalize( (lightDir + viewDir) );
nl = dot( s.Normal, lightDir);
nh = max( 0.000000, dot( s.Normal, h));
spec = (pow( nh, (s.Specular * 128.000)) * s.Gloss);
backContrib = xll_saturate( dot( viewDir, ( -lightDir )) );
backContrib = mix( xll_saturate( ( -nl ) ), backContrib, _TranslucencyViewDependency);
translucencyColor = ((backContrib * s.Translucency) * _TranslucencyColor);
nl = max( 0.000000, ((nl * 0.600000) + 0.400000));
c.xyz = (s.Albedo * ((translucencyColor * 2.00000) + nl));
c.xyz = ((c.xyz * _LightColor0.xyz ) + spec);
c.xyz *= mix( 2.00000, (atten * 2.00000), _ShadowStrength);
return c;
}
mediump vec4 xlat_main( in v2f_surf IN ) {
Input surfIN;
LeafSurfaceOutput o;
mediump vec3 lightDir;
mediump vec4 c;
surfIN.uv_MainTex = IN.hip_pack0.xy ;
surfIN.color = IN.lop_color;
o.Albedo = vec3( 0.000000);
o.Emission = vec3( 0.000000);
o.Specular = 0.000000;
o.Alpha = 0.000000;
surf( surfIN, o);
xll_clip( (o.Alpha - _Cutoff) );
lightDir = IN.lightDir;
c = LightingTreeLeaf( o, lightDir, normalize( vec3( IN.viewDir) ), (texture2D( _LightTexture0, IN._LightCoord).w * 1.00000));
c.w = o.Alpha;
return c;
}
varying highp vec2 xlv_TEXCOORD0;
varying highp vec4 xlv_COLOR0;
varying highp vec3 xlv_TEXCOORD1;
varying highp vec3 xlv_TEXCOORD2;
varying highp vec2 xlv_TEXCOORD3;
void main() {
mediump vec4 xl_retval;
v2f_surf xlt_IN;
xlt_IN.pos = highp vec4(0.0);
xlt_IN.hip_pack0 = highp vec2( xlv_TEXCOORD0);
xlt_IN.lop_color = highp vec4( xlv_COLOR0);
xlt_IN.lightDir = highp vec3( xlv_TEXCOORD1);
xlt_IN.viewDir = highp vec3( xlv_TEXCOORD2);
xlt_IN._LightCoord = highp vec2( xlv_TEXCOORD3);
xl_retval = xlat_main( xlt_IN);
gl_FragData[0] = mediump vec4( xl_retval);
}