mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-11 08:41:31 -05:00
102 lines
2.8 KiB
Text
102 lines
2.8 KiB
Text
|
#version 300 es
|
||
|
|
||
|
#define gl_FragColor _glesFragData[0]
|
||
|
#define gl_FragData _glesFragData
|
||
|
layout(location = 0) out mediump vec4 _glesFragData[4];
|
||
|
|
||
|
struct SurfaceOutput {
|
||
|
lowp vec3 Albedo;
|
||
|
lowp vec3 Normal;
|
||
|
lowp vec3 Emission;
|
||
|
mediump float Specular;
|
||
|
lowp float Gloss;
|
||
|
lowp float Alpha;
|
||
|
};
|
||
|
struct Input {
|
||
|
highp vec2 uv_MainTex;
|
||
|
};
|
||
|
struct v2f_surf {
|
||
|
highp vec4 pos;
|
||
|
highp vec2 pack0;
|
||
|
lowp vec3 worldNormal;
|
||
|
highp vec3 worldPos;
|
||
|
};
|
||
|
struct appdata_full {
|
||
|
highp vec4 vertex;
|
||
|
highp vec4 tangent;
|
||
|
highp vec3 normal;
|
||
|
highp vec4 texcoord;
|
||
|
highp vec4 texcoord1;
|
||
|
highp vec4 texcoord2;
|
||
|
highp vec4 texcoord3;
|
||
|
lowp vec4 color;
|
||
|
};
|
||
|
uniform highp vec4 _WorldSpaceLightPos0;
|
||
|
uniform lowp vec4 _LightColor0;
|
||
|
uniform sampler2D _LightTexture0;
|
||
|
uniform mediump mat4 _LightMatrix0;
|
||
|
uniform sampler2D _LightTextureB0;
|
||
|
uniform sampler2D _MainTex;
|
||
|
uniform highp vec4 _MainTex_ST;
|
||
|
|
||
|
lowp vec4 LightingLambert( in SurfaceOutput s, in lowp vec3 lightDir, in lowp float atten )
|
||
|
{
|
||
|
lowp float diff = max( 0.0, dot( s.Normal, lightDir));
|
||
|
lowp vec4 c;
|
||
|
c.xyz = ((s.Albedo * _LightColor0.xyz) * ((diff * atten) * 2.0));
|
||
|
c.w = s.Alpha;
|
||
|
return c;
|
||
|
}
|
||
|
lowp float UnitySpotAttenuate( in mediump vec3 LightCoord )
|
||
|
{
|
||
|
return texture( _LightTextureB0, vec2( dot( LightCoord, LightCoord))).w;
|
||
|
}
|
||
|
lowp float UnitySpotCookie( in mediump vec4 LightCoord )
|
||
|
{
|
||
|
return texture( _LightTexture0, ((LightCoord.xy / LightCoord.w) + 0.5)).w;
|
||
|
}
|
||
|
highp vec3 UnityWorldSpaceLightDir( in highp vec3 worldPos )
|
||
|
{
|
||
|
return (_WorldSpaceLightPos0.xyz - worldPos);
|
||
|
}
|
||
|
void surf( in Input IN, inout SurfaceOutput o )
|
||
|
{
|
||
|
mediump vec4 c = texture( _MainTex, IN.uv_MainTex);
|
||
|
o.Albedo = c.xyz;
|
||
|
o.Alpha = c.w;
|
||
|
}
|
||
|
lowp vec4 frag_surf( in v2f_surf IN )
|
||
|
{
|
||
|
Input surfIN;
|
||
|
surfIN.uv_MainTex = IN.pack0.xy;
|
||
|
highp vec3 worldPos = IN.worldPos;
|
||
|
highp vec3 lightDir = normalize(UnityWorldSpaceLightDir( worldPos));
|
||
|
SurfaceOutput o;
|
||
|
o.Albedo = vec3( 0.0);
|
||
|
o.Emission = vec3( 0.0);
|
||
|
o.Specular = 0.0;
|
||
|
o.Alpha = 0.0;
|
||
|
o.Gloss = 0.0;
|
||
|
o.Normal = IN.worldNormal;
|
||
|
surf( surfIN, o);
|
||
|
mediump vec4 lightCoord = (_LightMatrix0 * vec4( worldPos, 1.0));
|
||
|
lowp float atten = (((float((lightCoord.z > 0.0)) * UnitySpotCookie( lightCoord)) * UnitySpotAttenuate( lightCoord.xyz)) * 1.0);
|
||
|
lowp vec4 c = vec4( 0.0);
|
||
|
c += LightingLambert( o, lightDir, atten);
|
||
|
c.w = 0.0;
|
||
|
return c;
|
||
|
}
|
||
|
in highp vec2 xlv_TEXCOORD0;
|
||
|
in lowp vec3 xlv_TEXCOORD1;
|
||
|
in highp vec3 xlv_TEXCOORD2;
|
||
|
void main() {
|
||
|
lowp vec4 xl_retval;
|
||
|
v2f_surf xlt_IN;
|
||
|
xlt_IN.pos = vec4(0.0);
|
||
|
xlt_IN.pack0 = vec2(xlv_TEXCOORD0);
|
||
|
xlt_IN.worldNormal = vec3(xlv_TEXCOORD1);
|
||
|
xlt_IN.worldPos = vec3(xlv_TEXCOORD2);
|
||
|
xl_retval = frag_surf( xlt_IN);
|
||
|
gl_FragData[0] = vec4(xl_retval);
|
||
|
}
|