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)); } mat3 xll_constructMat3( mat4 m) { return mat3( vec3( m[0]), vec3( m[1]), vec3( m[2])); } struct v2f_vertex_lit { vec2 uv; vec4 diff; vec4 spec; }; struct v2f_img { vec4 pos; vec2 uv; }; struct appdata_img { vec4 vertex; vec2 texcoord; }; struct v2f { vec4 pos; vec4 uv; vec3 ray; }; struct appdata { vec4 vertex; vec3 texcoord; }; uniform sampler2D _CameraDepthTexture; uniform sampler2D _CameraNormalsTexture; uniform vec4 _LightColor; uniform vec4 _LightPos; uniform vec4 _LightPositionRange; uniform vec4 _LightShadowData; uniform samplerCube _LightTexture0; uniform sampler2D _LightTextureB0; uniform vec4 _ProjectionParams; uniform samplerCube _ShadowMapTexture; uniform mat4 _View2Shadow; uniform mat4 _ViewToCookie; uniform vec4 _ZBufferParams; uniform vec4 unity_LightmapFade; float Luminance( in vec3 c ); float Linear01Depth( in float z ); float DecodeFloatRGBA( in vec4 enc ); float SampleCubeDistance( in vec3 vec ); float unitySampleShadow( in vec3 vec, in float mydist ); float ComputeShadow( in vec3 vec, in vec2 uv ); vec4 frag( in v2f i ); float Luminance( in vec3 c ) { return dot( c, vec3( 0.220000, 0.707000, 0.0710000)); } float Linear01Depth( in float z ) { return (1.00000 / ((_ZBufferParams.x * z) + _ZBufferParams.y )); } float DecodeFloatRGBA( in vec4 enc ) { vec4 kDecodeDot = vec4( 1.00000, 0.00392157, 1.53787e-005, 6.22737e-009); return dot( enc, kDecodeDot); } float SampleCubeDistance( in vec3 vec ) { vec4 packDist; packDist = textureCube( _ShadowMapTexture, vec); return DecodeFloatRGBA( packDist); } float unitySampleShadow( in vec3 vec, in float mydist ) { float dist; dist = SampleCubeDistance( vec); return ( (dist < mydist) ) ? ( _LightShadowData.x ) : ( 1.00000 ); } float ComputeShadow( in vec3 vec, in vec2 uv ) { float fade; float mydist; fade = ((vec.z * _LightShadowData.z ) + _LightShadowData.w ); fade = xll_saturate( fade ); vec = ( xll_constructMat3( _View2Shadow) * vec ); mydist = (length( vec ) * _LightPositionRange.w ); mydist *= 0.970000; return unitySampleShadow( vec, mydist); return 1.00000; } vec4 frag( in v2f i ) { vec2 uv; vec4 nspec; vec3 normal; float depth; vec3 vpos; vec3 tolight; vec3 lightDir; float att; float atten; float diff; vec3 h; float spec; vec4 res; float fade; i.ray = (i.ray * (_ProjectionParams.z / i.ray.z )); uv = (i.uv.xy / i.uv.w ); nspec = texture2D( _CameraNormalsTexture, uv); normal = ((nspec.xyz * 2.00000) - 1.00000); normal = normalize( normal ); depth = texture2D( _CameraDepthTexture, uv).x ; depth = Linear01Depth( depth); vpos = (i.ray * depth); tolight = (_LightPos.xyz - vpos); lightDir = normalize( tolight ); att = (dot( tolight, tolight) * _LightPos.w ); atten = texture2D( _LightTextureB0, vec2( vec2( att))).w ; atten *= ComputeShadow( ( -tolight ), uv); atten *= textureCube( _LightTexture0, ( _ViewToCookie * vec4( vpos, 1.00000) ).xyz ).w ; diff = max( 0.000000, dot( lightDir, normal)); h = normalize( (lightDir - normalize( vpos )) ); spec = pow( max( 0.000000, dot( h, normal)), (nspec.w * 128.000)); spec *= xll_saturate( atten ); res.xyz = (_LightColor.xyz * (diff * atten)); res.w = (spec * Luminance( _LightColor.xyz )); fade = ((vpos.z * unity_LightmapFade.z ) + unity_LightmapFade.w ); res *= xll_saturate( (1.00000 - fade) ); return exp2( ( -res ) ); } void main() { vec4 xl_retval; v2f xlt_i; xlt_i.pos = vec4(0.0); xlt_i.uv = vec4( gl_TexCoord[0]); xlt_i.ray = vec3( gl_TexCoord[1]); xl_retval = frag( xlt_i); gl_FragData[0] = vec4( xl_retval); }