Files
cocos4/editor/assets/chunks/surfaces/module-functions/common-vs.chunk
T
jk20012001 0ecaa8db51 add surface shader (#11048)
* add surface shader

* remove unused item

* arrange main-functions

* arrange main-functions

* fix compatible lighting mode
2022-05-13 21:18:22 +08:00

143 lines
3.8 KiB
Plaintext

// IA Input->Intermediate
void CCSurfacesVertexInput(out SurfacesStandardVertexIntermediate In)
{
In.position = vec4(a_position, 1.0);
In.normal = a_normal;
#if CC_SURFACES_USE_TANGENT_SPACE
In.tangent = a_tangent;
#endif
#if CC_SURFACES_USE_VERTEX_COLOR
In.color = a_color;
#endif
In.texCoord = a_texCoord;
#if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP
In.texCoord1 = a_texCoord1;
#endif
}
void CCSurfacesVertexOutput(in SurfacesStandardVertexIntermediate In)
{
gl_Position = In.clipPos;
VSOutput_worldNormal = In.worldNormal.xyz;
VSOutput_faceSideSign = In.worldNormal.w;
VSOutput_worldPos = In.worldPos;
#if CC_SURFACES_USE_TANGENT_SPACE
VSOutput_worldTangent = In.worldTangent.xyz;
// VSOutput_worldBitangent = In.worldBinormal;
VSOutput_mirrorNormal = In.tangent.w;
#endif
#if CC_SURFACES_USE_VERTEX_COLOR
VSOutput_vertexColor = In.color;
#endif
VSOutput_texcoord = In.texCoord;
#if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP
VSOutput_texcoord1 = In.texCoord1;
#endif
#if !CC_USE_ACCURATE_FOG
VSOutput_fogFactor = In.fogFactor;
#endif
#if CC_RECEIVE_SHADOW
VSOutput_shadowPos = In.shadowPos;
#if CC_SURFACES_USE_INSTANCING
VSOutput_shadowBias = In.shadowBias;
#endif
#endif
#if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD
VSOutput_lightMapUV = In.lightmapUV;
#endif
#if CC_SURFACES_TRANSFER_LOCAL_POS
VSOutput_localPos = In.position;
#endif
}
// Morph & Skinning
void CCSurfacesVertexAnimation(inout SurfacesStandardVertexIntermediate In)
{
vec4 temp = vec4(0.0);
#if CC_USE_MORPH
#if CC_SURFACES_USE_TANGENT_SPACE
applyMorph(In.position, In.normal, In.tangent);
#else
applyMorph(In.position, In.normal, temp);
#endif
#endif
#if CC_USE_SKINNING
#if CC_SURFACES_USE_TANGENT_SPACE
CCSkin(In.position, In.normal, In.tangent);
#else
CCSkin(In.position, In.normal, temp);
#endif
#endif
}
// Space Transform
void CCSurfacesVertexWorldTransform(inout SurfacesStandardVertexIntermediate In)
{
mat4 matWorld, matWorldIT;
CCGetWorldMatrixFull(matWorld, matWorldIT);
In.worldPos = (matWorld * In.position).xyz;
In.worldNormal.xyz = normalize((matWorldIT * vec4(In.normal.xyz, 0.0)).xyz);
#if CC_SURFACES_USE_TANGENT_SPACE
In.worldTangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);
In.worldBinormal = cross(In.worldNormal.xyz, In.worldTangent) * In.tangent.w; // note the cross order
#endif
}
void CCSurfacesVertexTransformUV(inout SurfacesStandardVertexIntermediate In)
{
#if SAMPLE_FROM_RT
CC_HANDLE_RT_SAMPLE_FLIP(In.texCoord);
#if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP
CC_HANDLE_RT_SAMPLE_FLIP(In.texCoord1);
#endif
#endif
}
// Shading
void CCSurfacesVertexTransferFog(inout SurfacesStandardVertexIntermediate In)
{
#if !CC_USE_ACCURATE_FOG
CC_TRANSFER_FOG_BASE(vec4(In.worldPos, 1.0), In.fogFactor);
#endif
}
void CCSurfacesVertexTransferShadow(inout SurfacesStandardVertexIntermediate In)
{
#if CC_RECEIVE_SHADOW
In.shadowPos = cc_matLightViewProj * vec4(In.worldPos, 1.0);
In.shadowBias = vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);
#if CC_SURFACES_USE_INSTANCING
In.shadowBias = vec2(a_localShadowBias.x + cc_shadowWHPBInfo.w, a_localShadowBias.y + cc_shadowLPNNInfo.z);
#elif !CC_SURFACES_USE_BATCHING
In.shadowBias += cc_localShadowBias.xy;
#endif
#endif
}
void CCSurfacesVertexTransferLightMapUV(inout SurfacesStandardVertexIntermediate In)
{
#if CC_SURFACES_USE_LIGHT_MAP && !CC_SURFACES_USE_BATCHING && !CC_FORWARD_ADD
#if CC_SURFACES_USE_INSTANCING
In.lightmapUV.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;
In.lightmapUV.z = a_lightingMapUVParam.w;
#else
In.lightmapUV.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;
In.lightmapUV.z = cc_lightingMapUVParam.w;
#endif
#endif
}