mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 09:08:22 -05:00
408 lines
8.1 KiB
Text
408 lines
8.1 KiB
Text
struct v2f {
|
|
vec4 pos;
|
|
vec4 uv;
|
|
vec3 ray;
|
|
};
|
|
uniform vec4 unity_LightmapFade;
|
|
uniform vec4 _ZBufferParams;
|
|
uniform mat4 _ViewToCookie;
|
|
uniform mat4 _View2Shadow;
|
|
uniform samplerCube _ShadowMapTexture;
|
|
uniform vec4 _ProjectionParams;
|
|
uniform sampler2D _LightTextureB0;
|
|
uniform samplerCube _LightTexture0;
|
|
uniform vec4 _LightShadowData;
|
|
uniform vec4 _LightPositionRange;
|
|
uniform vec4 _LightPos;
|
|
uniform vec4 _LightColor;
|
|
uniform sampler2D _CameraNormalsTexture;
|
|
uniform sampler2D _CameraDepthTexture;
|
|
float xll_saturate (
|
|
in float x
|
|
)
|
|
{
|
|
float tmpvar_1;
|
|
tmpvar_1 = clamp (x, 0.0, 1.0);
|
|
return tmpvar_1;
|
|
}
|
|
|
|
vec2 xll_saturate (
|
|
in vec2 x
|
|
)
|
|
{
|
|
vec2 tmpvar_1;
|
|
tmpvar_1 = clamp (x, 0.0, 1.0);
|
|
return tmpvar_1;
|
|
}
|
|
|
|
vec3 xll_saturate (
|
|
in vec3 x
|
|
)
|
|
{
|
|
vec3 tmpvar_1;
|
|
tmpvar_1 = clamp (x, 0.0, 1.0);
|
|
return tmpvar_1;
|
|
}
|
|
|
|
vec4 xll_saturate (
|
|
in vec4 x
|
|
)
|
|
{
|
|
vec4 tmpvar_1;
|
|
tmpvar_1 = clamp (x, 0.0, 1.0);
|
|
return tmpvar_1;
|
|
}
|
|
|
|
mat2 xll_saturate (
|
|
in mat2 m
|
|
)
|
|
{
|
|
vec2 tmpvar_1;
|
|
tmpvar_1 = clamp (m[0], 0.0, 1.0);
|
|
vec2 tmpvar_2;
|
|
tmpvar_2 = clamp (m[1], 0.0, 1.0);
|
|
mat2 tmpvar_3;
|
|
vec2 tmpvar_4;
|
|
tmpvar_4 = tmpvar_1;
|
|
tmpvar_3[0] = tmpvar_4;
|
|
vec2 tmpvar_5;
|
|
tmpvar_5 = tmpvar_2;
|
|
tmpvar_3[1] = tmpvar_5;
|
|
return tmpvar_3;
|
|
}
|
|
|
|
mat3 xll_saturate (
|
|
in mat3 m
|
|
)
|
|
{
|
|
vec3 tmpvar_1;
|
|
tmpvar_1 = clamp (m[0], 0.0, 1.0);
|
|
vec3 tmpvar_2;
|
|
tmpvar_2 = clamp (m[1], 0.0, 1.0);
|
|
vec3 tmpvar_3;
|
|
tmpvar_3 = clamp (m[2], 0.0, 1.0);
|
|
mat3 tmpvar_4;
|
|
vec3 tmpvar_5;
|
|
tmpvar_5 = tmpvar_1;
|
|
tmpvar_4[0] = tmpvar_5;
|
|
vec3 tmpvar_6;
|
|
tmpvar_6 = tmpvar_2;
|
|
tmpvar_4[1] = tmpvar_6;
|
|
vec3 tmpvar_7;
|
|
tmpvar_7 = tmpvar_3;
|
|
tmpvar_4[2] = tmpvar_7;
|
|
return tmpvar_4;
|
|
}
|
|
|
|
mat4 xll_saturate (
|
|
in mat4 m
|
|
)
|
|
{
|
|
vec4 tmpvar_1;
|
|
tmpvar_1 = clamp (m[0], 0.0, 1.0);
|
|
vec4 tmpvar_2;
|
|
tmpvar_2 = clamp (m[1], 0.0, 1.0);
|
|
vec4 tmpvar_3;
|
|
tmpvar_3 = clamp (m[2], 0.0, 1.0);
|
|
vec4 tmpvar_4;
|
|
tmpvar_4 = clamp (m[3], 0.0, 1.0);
|
|
mat4 tmpvar_5;
|
|
vec4 tmpvar_6;
|
|
tmpvar_6 = tmpvar_1;
|
|
tmpvar_5[0] = tmpvar_6;
|
|
vec4 tmpvar_7;
|
|
tmpvar_7 = tmpvar_2;
|
|
tmpvar_5[1] = tmpvar_7;
|
|
vec4 tmpvar_8;
|
|
tmpvar_8 = tmpvar_3;
|
|
tmpvar_5[2] = tmpvar_8;
|
|
vec4 tmpvar_9;
|
|
tmpvar_9 = tmpvar_4;
|
|
tmpvar_5[3] = tmpvar_9;
|
|
return tmpvar_5;
|
|
}
|
|
|
|
mat3 xll_constructMat3 (
|
|
in mat4 m
|
|
)
|
|
{
|
|
vec3 tmpvar_1;
|
|
tmpvar_1 = m[0].xyz;
|
|
vec3 tmpvar_2;
|
|
tmpvar_2 = m[1].xyz;
|
|
vec3 tmpvar_3;
|
|
tmpvar_3 = m[2].xyz;
|
|
mat3 tmpvar_4;
|
|
vec3 tmpvar_5;
|
|
tmpvar_5 = tmpvar_1;
|
|
tmpvar_4[0] = tmpvar_5;
|
|
vec3 tmpvar_6;
|
|
tmpvar_6 = tmpvar_2;
|
|
tmpvar_4[1] = tmpvar_6;
|
|
vec3 tmpvar_7;
|
|
tmpvar_7 = tmpvar_3;
|
|
tmpvar_4[2] = tmpvar_7;
|
|
return tmpvar_4;
|
|
}
|
|
|
|
float Luminance (
|
|
in vec3 c
|
|
)
|
|
{
|
|
float tmpvar_1;
|
|
tmpvar_1 = dot (c, vec3(0.22, 0.707, 0.071));
|
|
return tmpvar_1;
|
|
}
|
|
|
|
float Linear01Depth (
|
|
in float z
|
|
)
|
|
{
|
|
return (1.0 / ((_ZBufferParams.x * z) + _ZBufferParams.y));
|
|
}
|
|
|
|
float DecodeFloatRGBA (
|
|
in vec4 enc
|
|
)
|
|
{
|
|
vec4 kDecodeDot;
|
|
vec4 tmpvar_1;
|
|
tmpvar_1 = vec4(1.0, 0.00392157, 1.53787e-05, 0.0);
|
|
kDecodeDot = tmpvar_1;
|
|
float tmpvar_2;
|
|
tmpvar_2 = dot (enc, kDecodeDot);
|
|
return tmpvar_2;
|
|
}
|
|
|
|
float SampleCubeDistance (
|
|
in vec3 vec
|
|
)
|
|
{
|
|
vec4 packDist;
|
|
vec4 tmpvar_1;
|
|
tmpvar_1 = textureCube (_ShadowMapTexture, vec);
|
|
vec4 tmpvar_2;
|
|
tmpvar_2 = tmpvar_1;
|
|
packDist = tmpvar_2;
|
|
float tmpvar_3;
|
|
tmpvar_3 = DecodeFloatRGBA (packDist);
|
|
return tmpvar_3;
|
|
}
|
|
|
|
float unitySampleShadow (
|
|
in vec3 vec,
|
|
in float mydist
|
|
)
|
|
{
|
|
float dist;
|
|
float tmpvar_1;
|
|
tmpvar_1 = SampleCubeDistance (vec);
|
|
float tmpvar_2;
|
|
tmpvar_2 = tmpvar_1;
|
|
dist = tmpvar_2;
|
|
float tmpvar_3;
|
|
if ((dist < mydist)) {
|
|
tmpvar_3 = _LightShadowData.x;
|
|
} else {
|
|
tmpvar_3 = 1.0;
|
|
};
|
|
return tmpvar_3;
|
|
}
|
|
|
|
float ComputeShadow (
|
|
in vec3 vec,
|
|
in vec2 uv
|
|
)
|
|
{
|
|
float mydist;
|
|
float fade;
|
|
float tmpvar_1;
|
|
tmpvar_1 = ((vec.z * _LightShadowData.z) + _LightShadowData.w);
|
|
fade = tmpvar_1;
|
|
float tmpvar_2;
|
|
tmpvar_2 = xll_saturate (fade);
|
|
float tmpvar_3;
|
|
tmpvar_3 = tmpvar_2;
|
|
fade = tmpvar_3;
|
|
mat3 tmpvar_4;
|
|
tmpvar_4 = (xll_constructMat3 (_View2Shadow));
|
|
vec3 tmpvar_5;
|
|
tmpvar_5 = (tmpvar_4 * vec);
|
|
vec = tmpvar_5;
|
|
float tmpvar_6;
|
|
tmpvar_6 = length (vec);
|
|
float tmpvar_7;
|
|
tmpvar_7 = (tmpvar_6 * _LightPositionRange.w);
|
|
mydist = tmpvar_7;
|
|
float tmpvar_8;
|
|
tmpvar_8 = (mydist * 0.97);
|
|
mydist = tmpvar_8;
|
|
float tmpvar_9;
|
|
tmpvar_9 = unitySampleShadow (vec, mydist);
|
|
return tmpvar_9;
|
|
return 1.0;
|
|
}
|
|
|
|
vec4 frag (
|
|
in v2f i
|
|
)
|
|
{
|
|
float fade;
|
|
vec4 res;
|
|
float spec;
|
|
vec3 h;
|
|
float diff;
|
|
float atten;
|
|
float att;
|
|
vec3 lightDir;
|
|
vec3 tolight;
|
|
vec3 vpos;
|
|
float depth;
|
|
vec3 normal;
|
|
vec4 nspec;
|
|
vec2 uv;
|
|
vec3 tmpvar_1;
|
|
tmpvar_1 = (i.ray * (_ProjectionParams.z / i.ray.z));
|
|
i.ray = tmpvar_1;
|
|
vec2 tmpvar_2;
|
|
tmpvar_2 = (i.uv.xy / i.uv.w);
|
|
uv = tmpvar_2;
|
|
vec4 tmpvar_3;
|
|
tmpvar_3 = texture2D (_CameraNormalsTexture, uv);
|
|
vec4 tmpvar_4;
|
|
tmpvar_4 = tmpvar_3;
|
|
nspec = tmpvar_4;
|
|
vec3 tmpvar_5;
|
|
tmpvar_5 = ((nspec.xyz * 2.0) - 1.0);
|
|
normal = tmpvar_5;
|
|
vec3 tmpvar_6;
|
|
tmpvar_6 = normalize (normal);
|
|
vec3 tmpvar_7;
|
|
tmpvar_7 = tmpvar_6;
|
|
normal = tmpvar_7;
|
|
vec4 tmpvar_8;
|
|
tmpvar_8 = texture2D (_CameraDepthTexture, uv);
|
|
float tmpvar_9;
|
|
tmpvar_9 = tmpvar_8.x;
|
|
depth = tmpvar_9;
|
|
float tmpvar_10;
|
|
tmpvar_10 = Linear01Depth (depth);
|
|
float tmpvar_11;
|
|
tmpvar_11 = tmpvar_10;
|
|
depth = tmpvar_11;
|
|
vec3 tmpvar_12;
|
|
tmpvar_12 = (i.ray * depth);
|
|
vpos = tmpvar_12;
|
|
vec3 tmpvar_13;
|
|
tmpvar_13 = (_LightPos.xyz - vpos);
|
|
tolight = tmpvar_13;
|
|
vec3 tmpvar_14;
|
|
tmpvar_14 = normalize (tolight);
|
|
vec3 tmpvar_15;
|
|
tmpvar_15 = tmpvar_14;
|
|
lightDir = tmpvar_15;
|
|
float tmpvar_16;
|
|
tmpvar_16 = dot (tolight, tolight);
|
|
float tmpvar_17;
|
|
tmpvar_17 = (tmpvar_16 * _LightPos.w);
|
|
att = tmpvar_17;
|
|
vec2 tmpvar_18;
|
|
tmpvar_18 = vec2(att);
|
|
vec2 tmpvar_19;
|
|
tmpvar_19 = tmpvar_18.xy;
|
|
vec4 tmpvar_20;
|
|
tmpvar_20 = texture2D (_LightTextureB0, tmpvar_19);
|
|
float tmpvar_21;
|
|
tmpvar_21 = tmpvar_20.w;
|
|
atten = tmpvar_21;
|
|
float tmpvar_22;
|
|
tmpvar_22 = ComputeShadow (-(tolight), uv);
|
|
float tmpvar_23;
|
|
tmpvar_23 = (atten * tmpvar_22);
|
|
atten = tmpvar_23;
|
|
vec4 tmpvar_24;
|
|
tmpvar_24.w = 1.0;
|
|
tmpvar_24.xyz = vpos.xyz;
|
|
vec4 tmpvar_25;
|
|
tmpvar_25 = textureCube (_LightTexture0, (_ViewToCookie * tmpvar_24).xyz);
|
|
float tmpvar_26;
|
|
tmpvar_26 = (atten * tmpvar_25.w);
|
|
atten = tmpvar_26;
|
|
float tmpvar_27;
|
|
tmpvar_27 = dot (lightDir, normal);
|
|
float tmpvar_28;
|
|
tmpvar_28 = max (0.0, tmpvar_27);
|
|
float tmpvar_29;
|
|
tmpvar_29 = tmpvar_28;
|
|
diff = tmpvar_29;
|
|
vec3 tmpvar_30;
|
|
tmpvar_30 = normalize (vpos);
|
|
vec3 tmpvar_31;
|
|
tmpvar_31 = normalize ((lightDir - tmpvar_30));
|
|
vec3 tmpvar_32;
|
|
tmpvar_32 = tmpvar_31;
|
|
h = tmpvar_32;
|
|
float tmpvar_33;
|
|
tmpvar_33 = dot (h, normal);
|
|
float tmpvar_34;
|
|
tmpvar_34 = max (0.0, tmpvar_33);
|
|
float tmpvar_35;
|
|
tmpvar_35 = pow (tmpvar_34, (nspec.w * 128.0));
|
|
float tmpvar_36;
|
|
tmpvar_36 = tmpvar_35;
|
|
spec = tmpvar_36;
|
|
float tmpvar_37;
|
|
tmpvar_37 = xll_saturate (atten);
|
|
float tmpvar_38;
|
|
tmpvar_38 = (spec * tmpvar_37);
|
|
spec = tmpvar_38;
|
|
vec3 tmpvar_39;
|
|
tmpvar_39 = (_LightColor.xyz * (diff * atten));
|
|
res.xyz = tmpvar_39.xyz.xyz;
|
|
float tmpvar_40;
|
|
tmpvar_40 = Luminance (_LightColor.xyz);
|
|
float tmpvar_41;
|
|
tmpvar_41 = (spec * tmpvar_40);
|
|
res.w = vec4(tmpvar_41).w;
|
|
float tmpvar_42;
|
|
tmpvar_42 = ((vpos.z * unity_LightmapFade.z) + unity_LightmapFade.w);
|
|
fade = tmpvar_42;
|
|
float tmpvar_43;
|
|
tmpvar_43 = xll_saturate ((1.0 - fade));
|
|
vec4 tmpvar_44;
|
|
tmpvar_44 = (res * tmpvar_43);
|
|
res = tmpvar_44;
|
|
vec4 tmpvar_45;
|
|
tmpvar_45 = exp2 (-(res));
|
|
return tmpvar_45;
|
|
}
|
|
|
|
void main ()
|
|
{
|
|
v2f xlt_i;
|
|
vec4 xl_retval;
|
|
vec4 tmpvar_1;
|
|
tmpvar_1 = vec4(0.0, 0.0, 0.0, 0.0);
|
|
xlt_i.pos = tmpvar_1;
|
|
vec4 tmpvar_2;
|
|
tmpvar_2 = gl_TexCoord[0].xyzw;
|
|
vec4 tmpvar_3;
|
|
tmpvar_3 = tmpvar_2;
|
|
xlt_i.uv = tmpvar_3;
|
|
vec3 tmpvar_4;
|
|
tmpvar_4 = gl_TexCoord[1].xyz;
|
|
vec3 tmpvar_5;
|
|
tmpvar_5 = tmpvar_4;
|
|
xlt_i.ray = tmpvar_5;
|
|
vec4 tmpvar_6;
|
|
tmpvar_6 = frag (xlt_i);
|
|
vec4 tmpvar_7;
|
|
tmpvar_7 = tmpvar_6;
|
|
xl_retval = tmpvar_7;
|
|
vec4 tmpvar_8;
|
|
tmpvar_8 = xl_retval.xyzw;
|
|
vec4 tmpvar_9;
|
|
tmpvar_9 = tmpvar_8;
|
|
gl_FragData[0] = tmpvar_9;
|
|
}
|
|
|