mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-01 11:56:58 -05:00
178 lines
5.6 KiB
Text
178 lines
5.6 KiB
Text
|
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 LeafSurfaceOutput {
|
||
|
vec3 Albedo;
|
||
|
vec3 Normal;
|
||
|
vec3 Emission;
|
||
|
vec3 Translucency;
|
||
|
float Specular;
|
||
|
float Gloss;
|
||
|
float Alpha;
|
||
|
};
|
||
|
struct Input {
|
||
|
vec2 uv_MainTex;
|
||
|
vec4 color;
|
||
|
};
|
||
|
struct v2f_surf {
|
||
|
vec4 pos;
|
||
|
vec3 _ShadowCoord0;
|
||
|
vec3 _ShadowCoord1;
|
||
|
vec3 _ShadowCoord2;
|
||
|
vec3 _ShadowCoord3;
|
||
|
vec2 _ShadowZFade;
|
||
|
vec2 hip_pack0;
|
||
|
vec4 lop_color;
|
||
|
};
|
||
|
uniform vec4 _Color;
|
||
|
uniform vec4 _LightShadowData;
|
||
|
uniform vec4 _MainTex_ST;
|
||
|
uniform mat4 _Object2World;
|
||
|
uniform vec4 _Scale;
|
||
|
uniform float _SquashAmount;
|
||
|
uniform vec4 _SquashPlaneNormal;
|
||
|
uniform float _TimeX;
|
||
|
uniform vec4 _Wind;
|
||
|
uniform mat4 _World2Shadow;
|
||
|
uniform mat4 _World2Shadow1;
|
||
|
uniform mat4 _World2Shadow2;
|
||
|
uniform mat4 _World2Shadow3;
|
||
|
|
||
|
|
||
|
|
||
|
vec4 Squash( in vec4 pos );
|
||
|
void ExpandBillboard( in mat4 mat, inout vec4 pos, inout vec3 normal, inout vec4 tangent );
|
||
|
vec4 TriangleWave( in vec4 x );
|
||
|
vec4 SmoothCurve( in vec4 x );
|
||
|
vec4 SmoothTriangleWave( in vec4 x );
|
||
|
vec4 AnimateVertex( in vec4 pos, in vec3 normal, in vec4 animParams );
|
||
|
void TreeVertLeaf( inout appdata_full v );
|
||
|
v2f_surf vert_surf( in appdata_full v );
|
||
|
vec4 Squash( in vec4 pos ) {
|
||
|
vec3 projectedVertex;
|
||
|
vec3 planePoint;
|
||
|
vec3 planeNormal;
|
||
|
projectedVertex = pos.xyz ;
|
||
|
planePoint = vec3( 0.000000, _SquashPlaneNormal.w , 0.000000);
|
||
|
planeNormal = _SquashPlaneNormal.xyz ;
|
||
|
projectedVertex += (dot( planeNormal, (planePoint - vec3( pos))) * planeNormal);
|
||
|
pos = vec4( mix( projectedVertex, pos.xyz , vec3( _SquashAmount)), 1.00000);
|
||
|
return pos;
|
||
|
}
|
||
|
void ExpandBillboard( in mat4 mat, inout vec4 pos, inout vec3 normal, inout vec4 tangent ) {
|
||
|
float isBillboard;
|
||
|
vec3 norb;
|
||
|
vec3 tanb;
|
||
|
isBillboard = (1.00000 - abs( tangent.w ));
|
||
|
norb = vec3( normalize( ( vec4( normal, 0.000000) * mat ) ));
|
||
|
tanb = vec3( normalize( ( vec4( normal.z , 0.000000, ( -normal.x ), 0.000000) * mat ) ));
|
||
|
pos += (( tangent * mat ) * isBillboard);
|
||
|
normal = mix( normal, norb, vec3( isBillboard));
|
||
|
tangent = mix( tangent, vec4( tanb, -1.00000), vec4( isBillboard));
|
||
|
}
|
||
|
vec4 TriangleWave( in vec4 x ) {
|
||
|
return abs( ((fract( (x + 0.500000) ) * 2.00000) - 1.00000) );
|
||
|
}
|
||
|
vec4 SmoothCurve( in vec4 x ) {
|
||
|
return ((x * x) * (3.00000 - (2.00000 * x)));
|
||
|
}
|
||
|
vec4 SmoothTriangleWave( in vec4 x ) {
|
||
|
return SmoothCurve( TriangleWave( x));
|
||
|
}
|
||
|
vec4 AnimateVertex( in vec4 pos, in vec3 normal, in vec4 animParams ) {
|
||
|
float fDetailAmp = 0.100000;
|
||
|
float fBranchAmp = 0.300000;
|
||
|
float fObjPhase;
|
||
|
float fBranchPhase;
|
||
|
float fVtxPhase;
|
||
|
vec2 vWavesIn;
|
||
|
vec4 vWaves;
|
||
|
vec2 vWavesSum;
|
||
|
vec3 bend;
|
||
|
fObjPhase = dot( _Object2World[ 3 ].xyz , vec3( 1.00000));
|
||
|
fBranchPhase = (fObjPhase + animParams.x );
|
||
|
fVtxPhase = dot( pos.xyz , vec3( (animParams.y + fBranchPhase)));
|
||
|
vWavesIn = (_TimeX + vec2( fVtxPhase, fBranchPhase));
|
||
|
vWaves = ((fract( (vWavesIn.xxyy * vec4( 1.97500, 0.793000, 0.375000, 0.193000)) ) * 2.00000) - 1.00000);
|
||
|
vWaves = SmoothTriangleWave( vWaves);
|
||
|
vWavesSum = (vWaves.xz + vWaves.yw );
|
||
|
bend = ((animParams.y * fDetailAmp) * normal.xyz );
|
||
|
bend.y = (animParams.w * fBranchAmp);
|
||
|
pos.xyz += (((vWavesSum.xyx * bend) + ((_Wind.xyz * vWavesSum.y ) * animParams.w )) * _Wind.w );
|
||
|
pos.xyz += (animParams.z * _Wind.xyz );
|
||
|
return pos;
|
||
|
}
|
||
|
void TreeVertLeaf( inout appdata_full v ) {
|
||
|
ExpandBillboard( gl_ModelViewMatrixInverseTranspose, v.vertex, v.normal, v.tangent);
|
||
|
v.vertex.xyz *= _Scale.xyz ;
|
||
|
v.vertex = AnimateVertex( v.vertex, v.normal, vec4( v.color.xy , v.texcoord1.xy ));
|
||
|
v.vertex = Squash( v.vertex);
|
||
|
v.color = vec4( (v.color.w * _Color.xyz ), _Color.w );
|
||
|
v.normal = normalize( v.normal );
|
||
|
v.tangent.xyz = normalize( v.tangent.xyz );
|
||
|
}
|
||
|
v2f_surf vert_surf( in appdata_full v ) {
|
||
|
v2f_surf o;
|
||
|
float z;
|
||
|
vec4 wpos;
|
||
|
TreeVertLeaf( v);
|
||
|
o.hip_pack0.xy = ((v.texcoord.xy * _MainTex_ST.xy ) + _MainTex_ST.zw );
|
||
|
o.lop_color = v.color;
|
||
|
o.pos = ( gl_ModelViewProjectionMatrix * v.vertex );
|
||
|
z = ( -( gl_ModelViewMatrix * v.vertex ).z );
|
||
|
o._ShadowZFade.x = z;
|
||
|
o._ShadowZFade.y = ((z * _LightShadowData.z ) + _LightShadowData.w );
|
||
|
wpos = ( _Object2World * v.vertex );
|
||
|
o._ShadowCoord0 = ( _World2Shadow * wpos ).xyz ;
|
||
|
o._ShadowCoord1 = ( _World2Shadow1 * wpos ).xyz ;
|
||
|
o._ShadowCoord2 = ( _World2Shadow2 * wpos ).xyz ;
|
||
|
o._ShadowCoord3 = ( _World2Shadow3 * wpos ).xyz ;
|
||
|
return o;
|
||
|
}
|
||
|
attribute vec4 TANGENT;
|
||
|
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);
|
||
|
gl_TexCoord[0] = vec4( xl_retval._ShadowCoord0, 0.0);
|
||
|
gl_TexCoord[1] = vec4( xl_retval._ShadowCoord1, 0.0);
|
||
|
gl_TexCoord[2] = vec4( xl_retval._ShadowCoord2, 0.0);
|
||
|
gl_TexCoord[3] = vec4( xl_retval._ShadowCoord3, 0.0);
|
||
|
gl_TexCoord[4] = vec4( xl_retval._ShadowZFade, 0.0, 0.0);
|
||
|
gl_TexCoord[5] = vec4( xl_retval.hip_pack0, 0.0, 0.0);
|
||
|
gl_FrontColor = vec4( xl_retval.lop_color);
|
||
|
}
|