mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 17:18:12 -05:00
81 lines
2.5 KiB
Text
81 lines
2.5 KiB
Text
#version 300 es
|
|
struct v2f {
|
|
highp vec4 pos;
|
|
highp vec2 uv;
|
|
highp vec3 ray;
|
|
};
|
|
uniform sampler2D _CameraDepthTexture;
|
|
uniform highp vec4 _LightShadowData;
|
|
uniform highp vec4 _LightSplitsFar;
|
|
uniform highp vec4 _LightSplitsNear;
|
|
uniform sampler2D _ShadowMapTexture;
|
|
uniform highp mat4 _View2Shadow;
|
|
uniform highp mat4 _View2Shadow1;
|
|
uniform highp mat4 _View2Shadow2;
|
|
uniform highp mat4 _View2Shadow3;
|
|
uniform highp vec4 _ZBufferParams;
|
|
mediump float unitySampleShadow( in highp vec4 eyePos );
|
|
highp float Linear01Depth( in highp float z );
|
|
highp vec2 EncodeFloatRG( in highp float v );
|
|
mediump vec4 xlat_main( in v2f i );
|
|
mediump float unitySampleShadow( in highp vec4 eyePos ) {
|
|
highp vec3 sc0;
|
|
highp vec3 sc1;
|
|
highp vec3 sc2;
|
|
highp vec3 sc3;
|
|
highp float z;
|
|
highp vec4 near;
|
|
highp vec4 far;
|
|
highp vec4 weights;
|
|
highp vec4 coord;
|
|
mediump float shadow;
|
|
sc0 = ( _View2Shadow * eyePos ).xyz ;
|
|
sc1 = ( _View2Shadow1 * eyePos ).xyz ;
|
|
sc2 = ( _View2Shadow2 * eyePos ).xyz ;
|
|
sc3 = ( _View2Shadow3 * eyePos ).xyz ;
|
|
z = eyePos.z ;
|
|
near = vec4( greaterThanEqual( vec4( z ), _LightSplitsNear) );
|
|
far = vec4( lessThan( vec4( z ), _LightSplitsFar) );
|
|
weights = (near * far);
|
|
coord = vec4( ((((sc0 * weights.x ) + (sc1 * weights.y )) + (sc2 * weights.z )) + (sc3 * weights.w )), 1.00000);
|
|
shadow = ( (texture2D( _ShadowMapTexture, coord.xy ).x < coord.z ) ) ? ( _LightShadowData.x ) : ( 1.00000 );
|
|
return shadow;
|
|
}
|
|
highp float Linear01Depth( in highp float z ) {
|
|
return (1.00000 / ((_ZBufferParams.x * z) + _ZBufferParams.y ));
|
|
}
|
|
highp vec2 EncodeFloatRG( in highp float v ) {
|
|
highp vec2 kEncodeMul = vec2( 1.00000, 255.000);
|
|
highp float kEncodeBit = 0.00392157;
|
|
highp vec2 enc;
|
|
enc = (kEncodeMul * v);
|
|
enc = fract( enc );
|
|
enc.x -= (enc.y * kEncodeBit);
|
|
return enc;
|
|
}
|
|
mediump vec4 xlat_main( in v2f i ) {
|
|
highp float depth;
|
|
highp vec4 vpos;
|
|
mediump float shadow;
|
|
highp vec4 res;
|
|
depth = texture2D( _CameraDepthTexture, i.uv).x ;
|
|
depth = Linear01Depth( depth);
|
|
vpos = vec4( (i.ray * depth), 1.00000);
|
|
shadow = unitySampleShadow( vpos);
|
|
res.x = shadow;
|
|
res.y = 1.00000;
|
|
res.zw = EncodeFloatRG( (1.00000 - depth));
|
|
return res;
|
|
}
|
|
in highp vec2 xlv_TEXCOORD0;
|
|
in highp vec3 xlv_TEXCOORD1;
|
|
out mediump vec4 _fragData;
|
|
void main() {
|
|
mediump vec4 xl_retval;
|
|
v2f xlt_i;
|
|
xlt_i.pos = vec4(0.0);
|
|
xlt_i.uv = vec2( xlv_TEXCOORD0);
|
|
xlt_i.ray = vec3( xlv_TEXCOORD1);
|
|
xl_retval = xlat_main( xlt_i);
|
|
_fragData = vec4( xl_retval);
|
|
}
|