mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 09:08:22 -05:00
326 lines
6.3 KiB
Text
326 lines
6.3 KiB
Text
|
struct SurfaceOutput {
|
||
|
vec3 Albedo;
|
||
|
vec3 Normal;
|
||
|
vec3 Emission;
|
||
|
float Specular;
|
||
|
float Gloss;
|
||
|
float Alpha;
|
||
|
};
|
||
|
struct Input {
|
||
|
vec2 uv_MainTex;
|
||
|
vec3 worldPos;
|
||
|
};
|
||
|
struct v2f_surf {
|
||
|
vec4 pos;
|
||
|
vec3 _ShadowCoord0;
|
||
|
vec3 _ShadowCoord1;
|
||
|
vec3 _ShadowCoord2;
|
||
|
vec3 _ShadowCoord3;
|
||
|
vec2 _ShadowZFade;
|
||
|
vec3 worldPos;
|
||
|
};
|
||
|
uniform sampler2D _ShadowMapTexture;
|
||
|
uniform vec4 _ProjectionParams;
|
||
|
uniform sampler2D _MainTex;
|
||
|
uniform vec4 _LightSplitsNear;
|
||
|
uniform vec4 _LightSplitsFar;
|
||
|
uniform vec4 _LightShadowData;
|
||
|
void xll_clip (
|
||
|
in float x
|
||
|
)
|
||
|
{
|
||
|
if ((x < 0.0)) {
|
||
|
discard;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
void surf (
|
||
|
in Input IN,
|
||
|
inout SurfaceOutput o
|
||
|
)
|
||
|
{
|
||
|
float tmpvar_1;
|
||
|
tmpvar_1 = fract (((IN.worldPos.y + (IN.worldPos.z * 0.1)) * 5.0));
|
||
|
xll_clip ((tmpvar_1 - 0.5));
|
||
|
vec4 tmpvar_2;
|
||
|
tmpvar_2 = texture2D (_MainTex, IN.uv_MainTex);
|
||
|
vec3 tmpvar_3;
|
||
|
tmpvar_3 = tmpvar_2.xyz;
|
||
|
o.Albedo = tmpvar_3;
|
||
|
}
|
||
|
|
||
|
vec2 EncodeFloatRG (
|
||
|
in float v
|
||
|
)
|
||
|
{
|
||
|
vec2 enc;
|
||
|
float kEncodeBit;
|
||
|
vec2 kEncodeMul;
|
||
|
vec2 tmpvar_1;
|
||
|
tmpvar_1 = vec2(1.0, 255.0);
|
||
|
kEncodeMul = tmpvar_1;
|
||
|
float tmpvar_2;
|
||
|
tmpvar_2 = 0.00392157;
|
||
|
kEncodeBit = tmpvar_2;
|
||
|
vec2 tmpvar_3;
|
||
|
tmpvar_3 = (kEncodeMul * v);
|
||
|
enc = tmpvar_3;
|
||
|
vec2 tmpvar_4;
|
||
|
tmpvar_4 = fract (enc);
|
||
|
vec2 tmpvar_5;
|
||
|
tmpvar_5 = tmpvar_4;
|
||
|
enc = tmpvar_5;
|
||
|
float tmpvar_6;
|
||
|
tmpvar_6 = (enc.x - (enc.y * kEncodeBit));
|
||
|
enc.x = tmpvar_6;
|
||
|
return enc;
|
||
|
}
|
||
|
|
||
|
vec4 frag_surf (
|
||
|
in v2f_surf IN
|
||
|
)
|
||
|
{
|
||
|
vec4 res;
|
||
|
float faded;
|
||
|
float shadow;
|
||
|
vec4 coord;
|
||
|
vec4 weights;
|
||
|
vec4 far;
|
||
|
vec4 near;
|
||
|
vec4 z;
|
||
|
SurfaceOutput o;
|
||
|
Input surfIN;
|
||
|
vec3 tmpvar_1;
|
||
|
tmpvar_1 = IN.worldPos;
|
||
|
surfIN.worldPos = tmpvar_1;
|
||
|
vec3 tmpvar_2;
|
||
|
tmpvar_2 = vec3(0.0, 0.0, 0.0);
|
||
|
o.Albedo = tmpvar_2;
|
||
|
vec3 tmpvar_3;
|
||
|
tmpvar_3 = vec3(0.0, 0.0, 0.0);
|
||
|
o.Emission = tmpvar_3;
|
||
|
float tmpvar_4;
|
||
|
tmpvar_4 = 0.0;
|
||
|
o.Specular = tmpvar_4;
|
||
|
float tmpvar_5;
|
||
|
tmpvar_5 = 0.0;
|
||
|
o.Alpha = tmpvar_5;
|
||
|
float tmpvar_6;
|
||
|
tmpvar_6 = 0.0;
|
||
|
o.Gloss = tmpvar_6;
|
||
|
surf (surfIN, o);
|
||
|
vec4 tmpvar_7;
|
||
|
tmpvar_7 = vec4(IN._ShadowZFade.x);
|
||
|
vec4 tmpvar_8;
|
||
|
tmpvar_8 = tmpvar_7;
|
||
|
z = tmpvar_8;
|
||
|
bvec4 tmpvar_9;
|
||
|
tmpvar_9 = greaterThanEqual (z, _LightSplitsNear);
|
||
|
vec4 tmpvar_10;
|
||
|
tmpvar_10 = vec4(tmpvar_9).xyzw;
|
||
|
vec4 tmpvar_11;
|
||
|
tmpvar_11 = tmpvar_10;
|
||
|
near = tmpvar_11;
|
||
|
bvec4 tmpvar_12;
|
||
|
tmpvar_12 = lessThan (z, _LightSplitsFar);
|
||
|
vec4 tmpvar_13;
|
||
|
tmpvar_13 = vec4(tmpvar_12).xyzw;
|
||
|
vec4 tmpvar_14;
|
||
|
tmpvar_14 = tmpvar_13;
|
||
|
far = tmpvar_14;
|
||
|
vec4 tmpvar_15;
|
||
|
tmpvar_15 = (near * far);
|
||
|
weights = tmpvar_15;
|
||
|
vec4 tmpvar_16;
|
||
|
tmpvar_16.w = 1.0;
|
||
|
tmpvar_16.xyz = ((((IN._ShadowCoord0 * weights.x) + (IN._ShadowCoord1 * weights.y)) + (IN._ShadowCoord2 * weights.z)) + (IN._ShadowCoord3 * weights.w)).xyz;
|
||
|
vec4 tmpvar_17;
|
||
|
tmpvar_17 = tmpvar_16;
|
||
|
coord = tmpvar_17;
|
||
|
vec4 tmpvar_18;
|
||
|
tmpvar_18 = texture2D (_ShadowMapTexture, coord.xy);
|
||
|
float tmpvar_19;
|
||
|
if ((tmpvar_18.x < coord.z)) {
|
||
|
tmpvar_19 = _LightShadowData.x;
|
||
|
} else {
|
||
|
tmpvar_19 = 1.0;
|
||
|
};
|
||
|
float tmpvar_20;
|
||
|
tmpvar_20 = tmpvar_19;
|
||
|
shadow = tmpvar_20;
|
||
|
float tmpvar_21;
|
||
|
tmpvar_21 = xll_saturate (IN._ShadowZFade.y);
|
||
|
float tmpvar_22;
|
||
|
tmpvar_22 = xll_saturate ((shadow + tmpvar_21));
|
||
|
float tmpvar_23;
|
||
|
tmpvar_23 = tmpvar_22;
|
||
|
faded = tmpvar_23;
|
||
|
float tmpvar_24;
|
||
|
tmpvar_24 = faded;
|
||
|
res.x = tmpvar_24;
|
||
|
float tmpvar_25;
|
||
|
tmpvar_25 = 1.0;
|
||
|
res.y = vec2(tmpvar_25).y;
|
||
|
vec2 tmpvar_26;
|
||
|
tmpvar_26 = EncodeFloatRG ((1.0 - (z * _ProjectionParams.w)).x);
|
||
|
vec2 tmpvar_27;
|
||
|
tmpvar_27 = tmpvar_26;
|
||
|
res.zw = tmpvar_27.xxxy.zw;
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
void main ()
|
||
|
{
|
||
|
v2f_surf xlt_IN;
|
||
|
vec4 xl_retval;
|
||
|
vec4 tmpvar_1;
|
||
|
tmpvar_1 = vec4(0.0, 0.0, 0.0, 0.0);
|
||
|
xlt_IN.pos = tmpvar_1;
|
||
|
vec3 tmpvar_2;
|
||
|
tmpvar_2 = gl_TexCoord[0].xyz;
|
||
|
vec3 tmpvar_3;
|
||
|
tmpvar_3 = tmpvar_2;
|
||
|
xlt_IN._ShadowCoord0 = tmpvar_3;
|
||
|
vec3 tmpvar_4;
|
||
|
tmpvar_4 = gl_TexCoord[1].xyz;
|
||
|
vec3 tmpvar_5;
|
||
|
tmpvar_5 = tmpvar_4;
|
||
|
xlt_IN._ShadowCoord1 = tmpvar_5;
|
||
|
vec3 tmpvar_6;
|
||
|
tmpvar_6 = gl_TexCoord[2].xyz;
|
||
|
vec3 tmpvar_7;
|
||
|
tmpvar_7 = tmpvar_6;
|
||
|
xlt_IN._ShadowCoord2 = tmpvar_7;
|
||
|
vec3 tmpvar_8;
|
||
|
tmpvar_8 = gl_TexCoord[3].xyz;
|
||
|
vec3 tmpvar_9;
|
||
|
tmpvar_9 = tmpvar_8;
|
||
|
xlt_IN._ShadowCoord3 = tmpvar_9;
|
||
|
vec2 tmpvar_10;
|
||
|
tmpvar_10 = gl_TexCoord[4].xy;
|
||
|
vec2 tmpvar_11;
|
||
|
tmpvar_11 = tmpvar_10;
|
||
|
xlt_IN._ShadowZFade = tmpvar_11;
|
||
|
vec3 tmpvar_12;
|
||
|
tmpvar_12 = gl_TexCoord[5].xyz;
|
||
|
vec3 tmpvar_13;
|
||
|
tmpvar_13 = tmpvar_12;
|
||
|
xlt_IN.worldPos = tmpvar_13;
|
||
|
vec4 tmpvar_14;
|
||
|
tmpvar_14 = frag_surf (xlt_IN);
|
||
|
vec4 tmpvar_15;
|
||
|
tmpvar_15 = tmpvar_14;
|
||
|
xl_retval = tmpvar_15;
|
||
|
vec4 tmpvar_16;
|
||
|
tmpvar_16 = xl_retval.xyzw;
|
||
|
vec4 tmpvar_17;
|
||
|
tmpvar_17 = tmpvar_16;
|
||
|
gl_FragData[0] = tmpvar_17;
|
||
|
}
|
||
|
|