mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 09:08:22 -05:00
529 lines
10 KiB
Text
529 lines
10 KiB
Text
struct v2f {
|
|
vec4 pos;
|
|
vec4 uv;
|
|
vec3 ray;
|
|
};
|
|
varying vec3 xlv_TEXCOORD1;
|
|
varying vec4 xlv_TEXCOORD0;
|
|
uniform vec4 unity_LightmapFade;
|
|
uniform vec4 _ZBufferParams;
|
|
uniform vec3 _WorldSpaceCameraPos;
|
|
uniform samplerCube _ShadowMapTexture;
|
|
uniform vec4 _ProjectionParams;
|
|
uniform sampler2D _LightTextureB0;
|
|
uniform samplerCube _LightTexture0;
|
|
uniform vec4 _LightShadowData;
|
|
uniform vec4 _LightPositionRange;
|
|
uniform vec4 _LightPos;
|
|
uniform mat4 _LightMatrix0;
|
|
uniform vec4 _LightColor;
|
|
uniform mat4 _CameraToWorld;
|
|
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;
|
|
}
|
|
|
|
vec2 xll_vecTSel (
|
|
in bvec2 a,
|
|
in vec2 b,
|
|
in vec2 c
|
|
)
|
|
{
|
|
float tmpvar_1;
|
|
if (a.x) {
|
|
tmpvar_1 = b.x;
|
|
} else {
|
|
tmpvar_1 = c.x;
|
|
};
|
|
float tmpvar_2;
|
|
if (a.y) {
|
|
tmpvar_2 = b.y;
|
|
} else {
|
|
tmpvar_2 = c.y;
|
|
};
|
|
vec2 tmpvar_3;
|
|
tmpvar_3.x = tmpvar_1;
|
|
tmpvar_3.y = tmpvar_2;
|
|
return tmpvar_3;
|
|
}
|
|
|
|
vec3 xll_vecTSel (
|
|
in bvec3 a,
|
|
in vec3 b,
|
|
in vec3 c
|
|
)
|
|
{
|
|
float tmpvar_1;
|
|
if (a.x) {
|
|
tmpvar_1 = b.x;
|
|
} else {
|
|
tmpvar_1 = c.x;
|
|
};
|
|
float tmpvar_2;
|
|
if (a.y) {
|
|
tmpvar_2 = b.y;
|
|
} else {
|
|
tmpvar_2 = c.y;
|
|
};
|
|
float tmpvar_3;
|
|
if (a.z) {
|
|
tmpvar_3 = b.z;
|
|
} else {
|
|
tmpvar_3 = c.z;
|
|
};
|
|
vec3 tmpvar_4;
|
|
tmpvar_4.x = tmpvar_1;
|
|
tmpvar_4.y = tmpvar_2;
|
|
tmpvar_4.z = tmpvar_3;
|
|
return tmpvar_4;
|
|
}
|
|
|
|
vec4 xll_vecTSel (
|
|
in bvec4 a,
|
|
in vec4 b,
|
|
in vec4 c
|
|
)
|
|
{
|
|
float tmpvar_1;
|
|
if (a.x) {
|
|
tmpvar_1 = b.x;
|
|
} else {
|
|
tmpvar_1 = c.x;
|
|
};
|
|
float tmpvar_2;
|
|
if (a.y) {
|
|
tmpvar_2 = b.y;
|
|
} else {
|
|
tmpvar_2 = c.y;
|
|
};
|
|
float tmpvar_3;
|
|
if (a.z) {
|
|
tmpvar_3 = b.z;
|
|
} else {
|
|
tmpvar_3 = c.z;
|
|
};
|
|
float tmpvar_4;
|
|
if (a.w) {
|
|
tmpvar_4 = b.w;
|
|
} else {
|
|
tmpvar_4 = c.w;
|
|
};
|
|
vec4 tmpvar_5;
|
|
tmpvar_5.x = tmpvar_1;
|
|
tmpvar_5.y = tmpvar_2;
|
|
tmpvar_5.z = tmpvar_3;
|
|
tmpvar_5.w = tmpvar_4;
|
|
return tmpvar_5;
|
|
}
|
|
|
|
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
|
|
)
|
|
{
|
|
vec4 shadows;
|
|
vec4 shadowVals;
|
|
float z;
|
|
float tmpvar_1;
|
|
tmpvar_1 = 0.0078125;
|
|
z = tmpvar_1;
|
|
vec3 tmpvar_2;
|
|
tmpvar_2.x = z;
|
|
tmpvar_2.y = z;
|
|
tmpvar_2.z = z;
|
|
float tmpvar_3;
|
|
tmpvar_3 = SampleCubeDistance ((vec + tmpvar_2));
|
|
float tmpvar_4;
|
|
tmpvar_4 = tmpvar_3;
|
|
shadowVals.x = tmpvar_4;
|
|
vec3 tmpvar_5;
|
|
tmpvar_5.x = -(z);
|
|
tmpvar_5.y = -(z);
|
|
tmpvar_5.z = z;
|
|
float tmpvar_6;
|
|
tmpvar_6 = SampleCubeDistance ((vec + tmpvar_5));
|
|
float tmpvar_7;
|
|
tmpvar_7 = tmpvar_6;
|
|
shadowVals.y = vec2(tmpvar_7).y;
|
|
vec3 tmpvar_8;
|
|
tmpvar_8.x = -(z);
|
|
tmpvar_8.y = z;
|
|
tmpvar_8.z = -(z);
|
|
float tmpvar_9;
|
|
tmpvar_9 = SampleCubeDistance ((vec + tmpvar_8));
|
|
float tmpvar_10;
|
|
tmpvar_10 = tmpvar_9;
|
|
shadowVals.z = vec3(tmpvar_10).z;
|
|
vec3 tmpvar_11;
|
|
tmpvar_11.x = z;
|
|
tmpvar_11.y = -(z);
|
|
tmpvar_11.z = -(z);
|
|
float tmpvar_12;
|
|
tmpvar_12 = SampleCubeDistance ((vec + tmpvar_11));
|
|
float tmpvar_13;
|
|
tmpvar_13 = tmpvar_12;
|
|
shadowVals.w = vec4(tmpvar_13).w;
|
|
vec4 tmpvar_14;
|
|
tmpvar_14 = vec4(mydist);
|
|
vec4 tmpvar_15;
|
|
tmpvar_15 = tmpvar_14.xyzw;
|
|
bvec4 tmpvar_16;
|
|
tmpvar_16 = lessThan (shadowVals, tmpvar_15);
|
|
vec4 tmpvar_17;
|
|
tmpvar_17 = _LightShadowData.xxxx.xyzw;
|
|
vec4 tmpvar_18;
|
|
tmpvar_18 = xll_vecTSel (tmpvar_16, tmpvar_17, vec4(1.0, 1.0, 1.0, 1.0));
|
|
vec4 tmpvar_19;
|
|
tmpvar_19 = tmpvar_18;
|
|
shadows = tmpvar_19;
|
|
float tmpvar_20;
|
|
tmpvar_20 = dot (shadows, vec4(0.25, 0.25, 0.25, 0.25));
|
|
return tmpvar_20;
|
|
}
|
|
|
|
float ComputeShadow (
|
|
in vec3 vec,
|
|
in float z,
|
|
in vec2 uv
|
|
)
|
|
{
|
|
float mydist;
|
|
float fade;
|
|
float tmpvar_1;
|
|
tmpvar_1 = ((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;
|
|
float tmpvar_4;
|
|
tmpvar_4 = length (vec);
|
|
float tmpvar_5;
|
|
tmpvar_5 = (tmpvar_4 * _LightPositionRange.w);
|
|
mydist = tmpvar_5;
|
|
float tmpvar_6;
|
|
tmpvar_6 = (mydist * 0.97);
|
|
mydist = tmpvar_6;
|
|
float tmpvar_7;
|
|
tmpvar_7 = unitySampleShadow (vec, mydist);
|
|
return tmpvar_7;
|
|
return 1.0;
|
|
}
|
|
|
|
vec4 xlat_main (
|
|
in v2f i
|
|
)
|
|
{
|
|
float fade;
|
|
vec4 res;
|
|
float spec;
|
|
vec3 h;
|
|
float diff;
|
|
float atten;
|
|
float att;
|
|
vec3 lightDir;
|
|
vec3 tolight;
|
|
vec3 wpos;
|
|
vec4 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;
|
|
vec4 tmpvar_12;
|
|
tmpvar_12.w = 1.0;
|
|
tmpvar_12.xyz = (i.ray * depth).xyz;
|
|
vec4 tmpvar_13;
|
|
tmpvar_13 = tmpvar_12;
|
|
vpos = tmpvar_13;
|
|
vec3 tmpvar_14;
|
|
tmpvar_14 = (_CameraToWorld * vpos).xyz;
|
|
wpos = tmpvar_14;
|
|
vec3 tmpvar_15;
|
|
tmpvar_15 = (wpos - _LightPos.xyz);
|
|
tolight = tmpvar_15;
|
|
vec3 tmpvar_16;
|
|
tmpvar_16 = normalize (tolight);
|
|
vec3 tmpvar_17;
|
|
tmpvar_17 = -(tmpvar_16);
|
|
lightDir = tmpvar_17;
|
|
float tmpvar_18;
|
|
tmpvar_18 = dot (tolight, tolight);
|
|
float tmpvar_19;
|
|
tmpvar_19 = (tmpvar_18 * _LightPos.w);
|
|
att = tmpvar_19;
|
|
vec2 tmpvar_20;
|
|
tmpvar_20 = vec2(att);
|
|
vec2 tmpvar_21;
|
|
tmpvar_21 = tmpvar_20.xy;
|
|
vec4 tmpvar_22;
|
|
tmpvar_22 = texture2D (_LightTextureB0, tmpvar_21);
|
|
float tmpvar_23;
|
|
tmpvar_23 = tmpvar_22.w;
|
|
atten = tmpvar_23;
|
|
float tmpvar_24;
|
|
tmpvar_24 = ComputeShadow (tolight, vpos.z, uv);
|
|
float tmpvar_25;
|
|
tmpvar_25 = (atten * tmpvar_24);
|
|
atten = tmpvar_25;
|
|
vec4 tmpvar_26;
|
|
tmpvar_26.w = 1.0;
|
|
tmpvar_26.xyz = wpos.xyz;
|
|
vec4 tmpvar_27;
|
|
tmpvar_27 = textureCube (_LightTexture0, (_LightMatrix0 * tmpvar_26).xyz);
|
|
float tmpvar_28;
|
|
tmpvar_28 = (atten * tmpvar_27.w);
|
|
atten = tmpvar_28;
|
|
float tmpvar_29;
|
|
tmpvar_29 = dot (lightDir, normal);
|
|
float tmpvar_30;
|
|
tmpvar_30 = max (0.0, tmpvar_29);
|
|
float tmpvar_31;
|
|
tmpvar_31 = tmpvar_30;
|
|
diff = tmpvar_31;
|
|
vec3 tmpvar_32;
|
|
tmpvar_32 = normalize ((wpos - _WorldSpaceCameraPos));
|
|
vec3 tmpvar_33;
|
|
tmpvar_33 = normalize ((lightDir - tmpvar_32));
|
|
vec3 tmpvar_34;
|
|
tmpvar_34 = tmpvar_33;
|
|
h = tmpvar_34;
|
|
float tmpvar_35;
|
|
tmpvar_35 = dot (h, normal);
|
|
float tmpvar_36;
|
|
tmpvar_36 = max (0.0, tmpvar_35);
|
|
float tmpvar_37;
|
|
tmpvar_37 = pow (tmpvar_36, (nspec.w * 128.0));
|
|
float tmpvar_38;
|
|
tmpvar_38 = tmpvar_37;
|
|
spec = tmpvar_38;
|
|
float tmpvar_39;
|
|
tmpvar_39 = xll_saturate (atten);
|
|
float tmpvar_40;
|
|
tmpvar_40 = (spec * tmpvar_39);
|
|
spec = tmpvar_40;
|
|
vec3 tmpvar_41;
|
|
tmpvar_41 = (_LightColor.xyz * (diff * atten));
|
|
res.xyz = tmpvar_41.xyz.xyz;
|
|
float tmpvar_42;
|
|
tmpvar_42 = Luminance (_LightColor.xyz);
|
|
float tmpvar_43;
|
|
tmpvar_43 = (spec * tmpvar_42);
|
|
res.w = vec4(tmpvar_43).w;
|
|
float tmpvar_44;
|
|
tmpvar_44 = ((vpos.z * unity_LightmapFade.z) + unity_LightmapFade.w);
|
|
fade = tmpvar_44;
|
|
float tmpvar_45;
|
|
tmpvar_45 = xll_saturate ((1.0 - fade));
|
|
vec4 tmpvar_46;
|
|
tmpvar_46 = (res * tmpvar_45);
|
|
res = tmpvar_46;
|
|
vec4 tmpvar_47;
|
|
tmpvar_47 = exp2 (-(res));
|
|
return tmpvar_47;
|
|
}
|
|
|
|
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 = xlv_TEXCOORD0.xyzw;
|
|
vec4 tmpvar_3;
|
|
tmpvar_3 = tmpvar_2;
|
|
xlt_i.uv = tmpvar_3;
|
|
vec3 tmpvar_4;
|
|
tmpvar_4 = xlv_TEXCOORD1.xyz;
|
|
vec3 tmpvar_5;
|
|
tmpvar_5 = tmpvar_4;
|
|
xlt_i.ray = tmpvar_5;
|
|
vec4 tmpvar_6;
|
|
tmpvar_6 = xlat_main (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;
|
|
}
|
|
|