mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-01 11:56:58 -05:00
148 lines
6 KiB
Text
148 lines
6 KiB
Text
struct appdata_full {
|
|
highp vec4 vertex;
|
|
highp vec4 tangent;
|
|
highp vec3 normal;
|
|
highp vec4 texcoord;
|
|
highp vec4 texcoord1;
|
|
highp vec4 color;
|
|
};
|
|
struct v2f_surf {
|
|
highp vec4 pos;
|
|
highp vec2 hip_pack0;
|
|
highp vec4 lop_color;
|
|
highp vec3 lightDir;
|
|
highp vec3 viewDir;
|
|
highp vec2 _LightCoord;
|
|
};
|
|
uniform highp mat4 _LightMatrix0;
|
|
uniform highp vec4 _MainTex_ST;
|
|
uniform highp mat4 _Object2World;
|
|
uniform highp vec4 _Scale;
|
|
uniform highp float _SquashAmount;
|
|
uniform highp vec4 _SquashPlaneNormal;
|
|
uniform highp vec4 _Time;
|
|
uniform highp vec4 _Wind;
|
|
uniform highp mat4 _World2Object;
|
|
uniform highp vec3 _WorldSpaceCameraPos;
|
|
uniform highp vec4 _WorldSpaceLightPos0;
|
|
uniform highp mat4 glstate_matrix_invtrans_modelview0;
|
|
uniform highp mat4 glstate_matrix_mvp;
|
|
uniform highp vec4 unity_Scale;
|
|
highp vec4 Squash( in highp vec4 pos );
|
|
void ExpandBillboard( in highp mat4 mat, inout highp vec4 pos, inout highp vec3 normal, inout highp vec4 tangent );
|
|
highp vec4 TriangleWave( in highp vec4 x );
|
|
highp vec4 SmoothCurve( in highp vec4 x );
|
|
highp vec4 SmoothTriangleWave( in highp vec4 x );
|
|
highp vec4 AnimateVertex( in highp vec4 pos, in highp vec3 normal, in highp vec4 animParams );
|
|
void TreeVertLeaf( inout appdata_full v );
|
|
highp vec3 ObjSpaceViewDir( in highp vec4 v );
|
|
highp vec3 ObjSpaceLightDir( in highp vec4 v );
|
|
v2f_surf xlat_main( in appdata_full v );
|
|
highp vec4 Squash( in highp vec4 pos ) {
|
|
highp vec3 planeNormal;
|
|
highp vec3 projectedVertex;
|
|
planeNormal = _SquashPlaneNormal.xyz ;
|
|
projectedVertex = (pos.xyz - ((dot( planeNormal, vec3( pos)) + _SquashPlaneNormal.w ) * planeNormal));
|
|
pos = vec4( mix( projectedVertex, pos.xyz , vec3( _SquashAmount)), 1.00000);
|
|
return pos;
|
|
}
|
|
void ExpandBillboard( in highp mat4 mat, inout highp vec4 pos, inout highp vec3 normal, inout highp vec4 tangent ) {
|
|
highp float isBillboard;
|
|
highp vec3 norb;
|
|
highp vec3 tanb;
|
|
isBillboard = (1.00000 - abs( tangent.w ));
|
|
norb = vec3( normalize( ( vec4( normal, 0.000000) * mat ) ));
|
|
tanb = vec3( normalize( ( vec4( tangent.xyz , 0.000000) * mat ) ));
|
|
pos += (( vec4( normal.xy , 0.000000, 0.000000) * mat ) * isBillboard);
|
|
normal = mix( normal, norb, vec3( isBillboard));
|
|
tangent = mix( tangent, vec4( tanb, -1.00000), vec4( isBillboard));
|
|
}
|
|
highp vec4 TriangleWave( in highp vec4 x ) {
|
|
return abs( ((fract( (x + 0.500000) ) * 2.00000) - 1.00000) );
|
|
}
|
|
highp vec4 SmoothCurve( in highp vec4 x ) {
|
|
return ((x * x) * (3.00000 - (2.00000 * x)));
|
|
}
|
|
highp vec4 SmoothTriangleWave( in highp vec4 x ) {
|
|
return SmoothCurve( TriangleWave( x));
|
|
}
|
|
highp vec4 AnimateVertex( in highp vec4 pos, in highp vec3 normal, in highp vec4 animParams ) {
|
|
highp float fDetailAmp = 0.100000;
|
|
highp float fBranchAmp = 0.300000;
|
|
highp float fObjPhase;
|
|
highp float fBranchPhase;
|
|
highp float fVtxPhase;
|
|
highp vec2 vWavesIn;
|
|
highp vec4 vWaves;
|
|
highp vec2 vWavesSum;
|
|
highp vec3 bend;
|
|
fObjPhase = dot( _Object2World[ 3 ].xyz , vec3( 1.00000));
|
|
fBranchPhase = (fObjPhase + animParams.x );
|
|
fVtxPhase = dot( pos.xyz , vec3( (animParams.y + fBranchPhase)));
|
|
vWavesIn = (_Time.yy + vec2( fVtxPhase, fBranchPhase));
|
|
vWaves = ((fract( (vWavesIn.xxyy * highp 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( glstate_matrix_invtrans_modelview0, 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( 1.00000, 1.00000, 1.00000, v.color.w );
|
|
v.normal = normalize( v.normal );
|
|
v.tangent.xyz = normalize( v.tangent.xyz );
|
|
}
|
|
highp vec3 ObjSpaceViewDir( in highp vec4 v ) {
|
|
highp vec3 objSpaceCameraPos;
|
|
objSpaceCameraPos = (( _World2Object * vec4( _WorldSpaceCameraPos.xyz , 1.00000) ).xyz * unity_Scale.w );
|
|
return (objSpaceCameraPos - v.xyz );
|
|
}
|
|
highp vec3 ObjSpaceLightDir( in highp vec4 v ) {
|
|
highp vec3 objSpaceLightPos;
|
|
objSpaceLightPos = ( _World2Object * _WorldSpaceLightPos0 ).xyz ;
|
|
return objSpaceLightPos.xyz ;
|
|
}
|
|
v2f_surf xlat_main( in appdata_full v ) {
|
|
v2f_surf o;
|
|
highp vec3 binormal;
|
|
highp mat3 rotation;
|
|
TreeVertLeaf( v);
|
|
o.pos = ( glstate_matrix_mvp * v.vertex );
|
|
o.hip_pack0.xy = ((v.texcoord.xy * _MainTex_ST.xy ) + _MainTex_ST.zw );
|
|
o.lop_color = v.color;
|
|
binormal = (cross( v.normal, v.tangent.xyz ) * v.tangent.w );
|
|
rotation = mat3( v.tangent.x , binormal.x , v.normal.x , v.tangent.y , binormal.y , v.normal.y , v.tangent.z , binormal.z , v.normal.z );
|
|
o.lightDir = ( rotation * ObjSpaceLightDir( v.vertex) );
|
|
o.viewDir = ( rotation * ObjSpaceViewDir( v.vertex) );
|
|
o._LightCoord = ( _LightMatrix0 * ( _Object2World * v.vertex ) ).xy ;
|
|
return o;
|
|
}
|
|
attribute vec4 TANGENT;
|
|
varying highp vec2 xlv_TEXCOORD0;
|
|
varying highp vec4 xlv_COLOR0;
|
|
varying highp vec3 xlv_TEXCOORD1;
|
|
varying highp vec3 xlv_TEXCOORD2;
|
|
varying highp vec2 xlv_TEXCOORD3;
|
|
void main() {
|
|
v2f_surf xl_retval;
|
|
appdata_full xlt_v;
|
|
xlt_v.vertex = highp vec4( gl_Vertex);
|
|
xlt_v.tangent = highp vec4( TANGENT);
|
|
xlt_v.normal = highp vec3( gl_Normal);
|
|
xlt_v.texcoord = highp vec4( gl_MultiTexCoord0);
|
|
xlt_v.texcoord1 = highp vec4( gl_MultiTexCoord1);
|
|
xlt_v.color = highp vec4( gl_Color);
|
|
xl_retval = xlat_main( xlt_v);
|
|
gl_Position = highp vec4( xl_retval.pos);
|
|
xlv_TEXCOORD0 = highp vec2( xl_retval.hip_pack0);
|
|
xlv_COLOR0 = highp vec4( xl_retval.lop_color);
|
|
xlv_TEXCOORD1 = highp vec3( xl_retval.lightDir);
|
|
xlv_TEXCOORD2 = highp vec3( xl_retval.viewDir);
|
|
xlv_TEXCOORD3 = highp vec2( xl_retval._LightCoord);
|
|
}
|