mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-04 21:31:11 -05:00
234 lines
7.5 KiB
Text
234 lines
7.5 KiB
Text
|
mat3 xll_constructMat3( mat4 m) {
|
||
|
return mat3( vec3( m[0]), vec3( m[1]), vec3( m[2]));
|
||
|
}
|
||
|
struct v2f_vertex_lit {
|
||
|
vec2 uv;
|
||
|
vec4 diff;
|
||
|
vec4 spec;
|
||
|
};
|
||
|
struct v2f_img {
|
||
|
vec4 pos;
|
||
|
vec2 uv;
|
||
|
};
|
||
|
struct appdata_img {
|
||
|
vec4 vertex;
|
||
|
vec2 texcoord;
|
||
|
};
|
||
|
struct SurfaceOutput {
|
||
|
vec3 Albedo;
|
||
|
vec3 Normal;
|
||
|
vec3 Emission;
|
||
|
float Specular;
|
||
|
float Gloss;
|
||
|
float Alpha;
|
||
|
};
|
||
|
struct appdata_full {
|
||
|
vec4 vertex;
|
||
|
vec4 tangent;
|
||
|
vec3 normal;
|
||
|
vec4 texcoord;
|
||
|
vec4 texcoord1;
|
||
|
vec4 color;
|
||
|
};
|
||
|
struct Input {
|
||
|
vec2 uv_MainTex;
|
||
|
vec4 color;
|
||
|
};
|
||
|
struct v2f_surf {
|
||
|
vec4 pos;
|
||
|
float fog;
|
||
|
vec2 hip_pack0;
|
||
|
vec4 lop_color;
|
||
|
vec3 normal;
|
||
|
vec3 vlight;
|
||
|
};
|
||
|
uniform vec4 _CameraPosition;
|
||
|
uniform vec3 _CameraRight;
|
||
|
uniform vec3 _CameraUp;
|
||
|
uniform vec4 _MainTex_ST;
|
||
|
uniform mat4 _Object2World;
|
||
|
uniform vec4 _WaveAndDistance;
|
||
|
uniform vec4 _WavingTint;
|
||
|
|
||
|
uniform vec4 unity_4LightAtten0;
|
||
|
uniform vec4 unity_4LightPosX0;
|
||
|
uniform vec4 unity_4LightPosY0;
|
||
|
uniform vec4 unity_4LightPosZ0;
|
||
|
uniform vec3 unity_LightColor0;
|
||
|
uniform vec3 unity_LightColor1;
|
||
|
uniform vec3 unity_LightColor2;
|
||
|
uniform vec3 unity_LightColor3;
|
||
|
uniform vec4 unity_SHAb;
|
||
|
uniform vec4 unity_SHAg;
|
||
|
uniform vec4 unity_SHAr;
|
||
|
uniform vec4 unity_SHBb;
|
||
|
uniform vec4 unity_SHBg;
|
||
|
uniform vec4 unity_SHBr;
|
||
|
uniform vec4 unity_SHC;
|
||
|
uniform vec4 unity_Scale;
|
||
|
void FastSinCos( in vec4 val, out vec4 s, out vec4 c );
|
||
|
void TerrainWaveGrass( inout vec4 vertex, in float waveAmount, in vec3 color, out vec4 outColor );
|
||
|
void TerrainBillboardGrass( inout vec4 pos, in vec2 offset );
|
||
|
void vert( inout appdata_full v );
|
||
|
vec3 ShadeSH9( in vec4 normal );
|
||
|
vec3 Shade4PointLights( in vec4 lightPosX, in vec4 lightPosY, in vec4 lightPosZ, in vec3 lightColor0, in vec3 lightColor1, in vec3 lightColor2, in vec3 lightColor3, in vec4 lightAttenSq, in vec3 pos, in vec3 normal );
|
||
|
void PositionFog( in vec4 v, out vec4 pos, out float fog );
|
||
|
v2f_surf vert_surf( in appdata_full v );
|
||
|
void FastSinCos( in vec4 val, out vec4 s, out vec4 c ) {
|
||
|
vec4 r5;
|
||
|
vec4 r6;
|
||
|
vec4 r7;
|
||
|
vec4 r8;
|
||
|
vec4 r1;
|
||
|
vec4 r2;
|
||
|
vec4 r3;
|
||
|
vec4 sin7 = vec4( 1.00000, -0.161616, 0.00833330, -0.000198410);
|
||
|
vec4 cos8 = vec4( -0.500000, 0.0416667, -0.00138889, 2.48016e-005);
|
||
|
val = ((val * 6.40885) - 3.14159);
|
||
|
r5 = (val * val);
|
||
|
r6 = (r5 * r5);
|
||
|
r7 = (r6 * r5);
|
||
|
r8 = (r6 * r5);
|
||
|
r1 = (r5 * val);
|
||
|
r2 = (r1 * r5);
|
||
|
r3 = (r2 * r5);
|
||
|
s = (((val + (r1 * sin7.y )) + (r2 * sin7.z )) + (r3 * sin7.w ));
|
||
|
c = ((((1.00000 + (r5 * cos8.x )) + (r6 * cos8.y )) + (r7 * cos8.z )) + (r8 * cos8.w ));
|
||
|
}
|
||
|
void TerrainWaveGrass( inout vec4 vertex, in float waveAmount, in vec3 color, out vec4 outColor ) {
|
||
|
vec4 _waveXSize;
|
||
|
vec4 _waveZSize;
|
||
|
vec4 waveSpeed = vec4( 1.20000, 2.00000, 1.60000, 4.80000);
|
||
|
vec4 _waveXmove = vec4( 0.0240000, 0.0400000, -0.120000, 0.0960000);
|
||
|
vec4 _waveZmove = vec4( 0.00600000, 0.0200000, -0.0200000, 0.100000);
|
||
|
vec4 waves;
|
||
|
vec4 s;
|
||
|
vec4 c;
|
||
|
float lighting;
|
||
|
vec3 waveMove = vec3( 0.000000, 0.000000, 0.000000);
|
||
|
vec3 waveColor;
|
||
|
_waveXSize = (vec4( 0.0120000, 0.0200000, 0.0600000, 0.0240000) * _WaveAndDistance.y );
|
||
|
_waveZSize = (vec4( 0.00600000, 0.0200000, 0.0200000, 0.0500000) * _WaveAndDistance.y );
|
||
|
waves = (vertex.x * _waveXSize);
|
||
|
waves += (vertex.z * _waveZSize);
|
||
|
waves += (_WaveAndDistance.x * waveSpeed);
|
||
|
waves = fract( waves );
|
||
|
FastSinCos( waves, s, c);
|
||
|
s = (s * s);
|
||
|
s = (s * s);
|
||
|
lighting = (dot( s, normalize( vec4( 1.00000, 1.00000, 0.400000, 0.200000) )) * 0.700000);
|
||
|
s = (s * waveAmount);
|
||
|
waveMove.x = dot( s, _waveXmove);
|
||
|
waveMove.z = dot( s, _waveZmove);
|
||
|
vertex.xz -= (waveMove.xz * _WaveAndDistance.z );
|
||
|
waveColor = mix( vec3( 0.500000, 0.500000, 0.500000), _WavingTint.xyz , vec3( lighting));
|
||
|
outColor.xyz = ((color * waveColor) * 2.00000);
|
||
|
outColor.w = 1.00000;
|
||
|
}
|
||
|
void TerrainBillboardGrass( inout vec4 pos, in vec2 offset ) {
|
||
|
vec3 grasspos;
|
||
|
grasspos = (pos.xyz - _CameraPosition.xyz );
|
||
|
if ( (dot( grasspos, grasspos) > _WaveAndDistance.w ) ){
|
||
|
offset = vec2( 0.000000);
|
||
|
}
|
||
|
pos.xyz += (offset.x * _CameraRight.xyz );
|
||
|
pos.xyz += (offset.y * _CameraUp.xyz );
|
||
|
}
|
||
|
void vert( inout appdata_full v ) {
|
||
|
float waveAmount;
|
||
|
vec4 color;
|
||
|
TerrainBillboardGrass( v.vertex, v.tangent.xy );
|
||
|
waveAmount = v.tangent.y ;
|
||
|
TerrainWaveGrass( v.vertex, waveAmount, v.color.xyz , color);
|
||
|
v.color = color;
|
||
|
}
|
||
|
vec3 ShadeSH9( in vec4 normal ) {
|
||
|
vec3 x1;
|
||
|
vec4 vB;
|
||
|
vec3 x2;
|
||
|
float vC;
|
||
|
vec3 x3;
|
||
|
x1.x = dot( unity_SHAr, normal);
|
||
|
x1.y = dot( unity_SHAg, normal);
|
||
|
x1.z = dot( unity_SHAb, normal);
|
||
|
vB = (normal.xyzz * normal.yzzx );
|
||
|
x2.x = dot( unity_SHBr, vB);
|
||
|
x2.y = dot( unity_SHBg, vB);
|
||
|
x2.z = dot( unity_SHBb, vB);
|
||
|
vC = ((normal.x * normal.x ) - (normal.y * normal.y ));
|
||
|
x3 = (unity_SHC.xyz * vC);
|
||
|
return ((x1 + x2) + x3);
|
||
|
}
|
||
|
vec3 Shade4PointLights( in vec4 lightPosX, in vec4 lightPosY, in vec4 lightPosZ, in vec3 lightColor0, in vec3 lightColor1, in vec3 lightColor2, in vec3 lightColor3, in vec4 lightAttenSq, in vec3 pos, in vec3 normal ) {
|
||
|
vec4 toLightX;
|
||
|
vec4 toLightY;
|
||
|
vec4 toLightZ;
|
||
|
vec4 lengthSq;
|
||
|
vec4 ndotl;
|
||
|
vec4 corr;
|
||
|
vec4 atten;
|
||
|
vec4 diff;
|
||
|
vec3 col;
|
||
|
toLightX = (lightPosX - pos.x );
|
||
|
toLightY = (lightPosY - pos.y );
|
||
|
toLightZ = (lightPosZ - pos.z );
|
||
|
lengthSq = vec4( 0.000000);
|
||
|
lengthSq += (toLightX * toLightX);
|
||
|
lengthSq += (toLightY * toLightY);
|
||
|
lengthSq += (toLightZ * toLightZ);
|
||
|
ndotl = vec4( 0.000000);
|
||
|
ndotl += (toLightX * normal.x );
|
||
|
ndotl += (toLightY * normal.y );
|
||
|
ndotl += (toLightZ * normal.z );
|
||
|
corr = inversesqrt( lengthSq );
|
||
|
ndotl = max( vec4( 0.000000, 0.000000, 0.000000, 0.000000), (ndotl * corr));
|
||
|
atten = (1.00000 / (1.00000 + (lengthSq * lightAttenSq)));
|
||
|
diff = (ndotl * atten);
|
||
|
col = vec3( 0.000000);
|
||
|
col += (lightColor0 * diff.x );
|
||
|
col += (lightColor1 * diff.y );
|
||
|
col += (lightColor2 * diff.z );
|
||
|
col += (lightColor3 * diff.w );
|
||
|
return col;
|
||
|
}
|
||
|
void PositionFog( in vec4 v, out vec4 pos, out float fog ) {
|
||
|
pos = ( gl_ModelViewProjectionMatrix * v );
|
||
|
fog = pos.z ;
|
||
|
}
|
||
|
v2f_surf vert_surf( in appdata_full v ) {
|
||
|
v2f_surf o;
|
||
|
vec3 worldN;
|
||
|
vec3 shlight;
|
||
|
vec3 worldPos;
|
||
|
vert( v);
|
||
|
PositionFog( v.vertex, o.pos, o.fog);
|
||
|
o.hip_pack0.xy = ((v.texcoord.xy * _MainTex_ST.xy ) + _MainTex_ST.zw );
|
||
|
o.lop_color = v.color;
|
||
|
worldN = ( xll_constructMat3( _Object2World) * (v.normal * unity_Scale.w ) );
|
||
|
o.normal = worldN;
|
||
|
shlight = ShadeSH9( vec4( worldN, 1.00000));
|
||
|
o.vlight = shlight;
|
||
|
worldPos = ( _Object2World * v.vertex ).xyz ;
|
||
|
o.vlight += Shade4PointLights( unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0, unity_LightColor0, unity_LightColor1, unity_LightColor2, unity_LightColor3, unity_4LightAtten0, worldPos, worldN);
|
||
|
return o;
|
||
|
}
|
||
|
attribute vec4 TANGENT;
|
||
|
varying vec4 xlv_FOG;
|
||
|
void main() {
|
||
|
v2f_surf xl_retval;
|
||
|
appdata_full xlt_v;
|
||
|
xlt_v.vertex = vec4( gl_Vertex);
|
||
|
xlt_v.tangent = vec4( TANGENT);
|
||
|
xlt_v.normal = vec3( gl_Normal);
|
||
|
xlt_v.texcoord = vec4( gl_MultiTexCoord0);
|
||
|
xlt_v.texcoord1 = vec4( gl_MultiTexCoord1);
|
||
|
xlt_v.color = vec4( gl_Color);
|
||
|
xl_retval = vert_surf( xlt_v);
|
||
|
gl_Position = vec4( xl_retval.pos);
|
||
|
xlv_FOG = vec4( xl_retval.fog, 0.0, 0.0, 0.0);
|
||
|
gl_TexCoord[0] = vec4( xl_retval.hip_pack0, 0.0, 0.0);
|
||
|
gl_FrontColor = vec4( xl_retval.lop_color);
|
||
|
gl_TexCoord[1] = vec4( xl_retval.normal, 0.0);
|
||
|
gl_TexCoord[2] = vec4( xl_retval.vlight, 0.0);
|
||
|
}
|