mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-29 02:55:36 -05:00
136 lines
3.9 KiB
Text
136 lines
3.9 KiB
Text
#version 300 es
|
|
|
|
// A variant produced by Unity's directional lightmap;
|
|
// has an inline medium precision matrix constructor,
|
|
// but even if unity_DirBasis is declared as mediump
|
|
// some code was promoting it to high precision.
|
|
|
|
#define gl_FragColor _glesFragData[0]
|
|
#define gl_FragData _glesFragData
|
|
layout(location = 0)out mediump vec4 _glesFragData[4];
|
|
|
|
mat3 xll_transpose_mf3x3(mat3 m) {
|
|
return mat3( m[0][0], m[1][0], m[2][0],
|
|
m[0][1], m[1][1], m[2][1],
|
|
m[0][2], m[1][2], m[2][2]);
|
|
}
|
|
vec3 xll_saturate_vf3( vec3 x) {
|
|
return clamp( x, 0.0, 1.0);
|
|
}
|
|
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 tSpace0;
|
|
lowp vec3 tSpace1;
|
|
lowp vec3 tSpace2;
|
|
highp vec4 lmap;
|
|
};
|
|
uniform mediump vec4 _WorldSpaceLightPos0;
|
|
uniform sampler2D unity_Lightmap;
|
|
uniform sampler2D unity_LightmapInd;
|
|
uniform lowp vec4 _LightColor0;
|
|
uniform lowp vec4 _SpecColor;
|
|
uniform sampler2D _MainTex;
|
|
uniform highp vec4 _MainTex_ST;
|
|
lowp vec3 DecodeLightmapDoubleLDR( in lowp vec4 color ) {
|
|
return (2.0 * color.xyz);
|
|
}
|
|
lowp vec3 DecodeLightmap( in lowp vec4 color ) {
|
|
|
|
return DecodeLightmapDoubleLDR( color);
|
|
}
|
|
mediump vec3 DirLightmapDiffuse( in mediump mat3 dirBasis, in lowp vec4 color, in lowp vec4 scale, in mediump vec3 normal, in bool surfFuncWritesNormal, out mediump vec3 scalePerBasisVector ) {
|
|
mediump vec3 lm = DecodeLightmap( color);
|
|
|
|
scalePerBasisVector = DecodeLightmap( scale);
|
|
if (surfFuncWritesNormal){
|
|
|
|
mediump vec3 normalInRnmBasis = xll_saturate_vf3((dirBasis * normal));
|
|
lm *= dot( normalInRnmBasis, scalePerBasisVector);
|
|
}
|
|
|
|
return lm;
|
|
}
|
|
mediump vec4 LightingLambert_DirLightmap( in SurfaceOutput s, in lowp vec4 color, in lowp vec4 scale, in bool surfFuncWritesNormal ) {
|
|
mediump mat3 unity_DirBasis = xll_transpose_mf3x3(mat3( vec3( 0.8164966, 0.0, 0.5773503), vec3( -0.4082483, 0.7071068, 0.5773503), vec3( -0.4082483, -0.7071068, 0.5773503)));
|
|
mediump vec3 scalePerBasisVector;
|
|
|
|
mediump vec4 c;
|
|
c.xyz = DirLightmapDiffuse( unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
|
|
c.w = 0.0;
|
|
|
|
return c;
|
|
}
|
|
void surf( in Input IN, inout SurfaceOutput o ) {
|
|
mediump vec4 c = texture( _MainTex, IN.uv_MainTex);
|
|
o.Albedo = c.xyz;
|
|
o.Alpha = c.w;
|
|
|
|
o.Normal = ((c.xyz * 2.0) - 1.0);
|
|
}
|
|
lowp vec4 frag_surf( in v2f_surf IN ) {
|
|
Input surfIN;
|
|
|
|
surfIN.uv_MainTex = IN.pack0.xy;
|
|
highp vec3 lightDir = _WorldSpaceLightPos0.xyz;
|
|
|
|
SurfaceOutput o;
|
|
o.Albedo = vec3( 0.0);
|
|
o.Emission = vec3( 0.0);
|
|
|
|
o.Specular = 0.0;
|
|
o.Alpha = 0.0;
|
|
o.Gloss = 0.0;
|
|
lowp vec3 normalWorldVertex = vec3( 0.0, 0.0, 1.0);
|
|
|
|
surf( surfIN, o);
|
|
lowp float atten = 1.0;
|
|
|
|
lowp vec4 c = vec4( 0.0);
|
|
|
|
lowp vec4 lmtex = texture( unity_Lightmap, IN.lmap.xy);
|
|
lowp vec4 lmIndTex = texture( unity_LightmapInd, IN.lmap.xy);
|
|
mediump vec3 lm = LightingLambert_DirLightmap( o, lmtex, lmIndTex, true).xyz;
|
|
|
|
lowp vec3 worldN;
|
|
worldN.x = dot( IN.tSpace0.xyz, o.Normal);
|
|
worldN.y = dot( IN.tSpace1.xyz, o.Normal);
|
|
worldN.z = dot( IN.tSpace2.xyz, o.Normal);
|
|
|
|
o.Normal = worldN;
|
|
|
|
c.w = o.Alpha;
|
|
|
|
c.xyz += (o.Albedo * lm);
|
|
|
|
c.w = 1.0;
|
|
return c;
|
|
}
|
|
in highp vec2 xlv_TEXCOORD0;
|
|
in lowp vec3 xlv_TEXCOORD1;
|
|
in lowp vec3 xlv_TEXCOORD2;
|
|
in lowp vec3 xlv_TEXCOORD3;
|
|
in highp vec4 xlv_TEXCOORD4;
|
|
void main() {
|
|
lowp vec4 xl_retval;
|
|
v2f_surf xlt_IN;
|
|
xlt_IN.pos = vec4(0.0);
|
|
xlt_IN.pack0 = vec2(xlv_TEXCOORD0);
|
|
xlt_IN.tSpace0 = vec3(xlv_TEXCOORD1);
|
|
xlt_IN.tSpace1 = vec3(xlv_TEXCOORD2);
|
|
xlt_IN.tSpace2 = vec3(xlv_TEXCOORD3);
|
|
xlt_IN.lmap = vec4(xlv_TEXCOORD4);
|
|
xl_retval = frag_surf( xlt_IN);
|
|
gl_FragData[0] = vec4(xl_retval);
|
|
}
|