common-vs.chunk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // IA Input->Intermediate
  2. void CCSurfacesVertexInput(out SurfacesStandardVertexIntermediate In)
  3. {
  4. In.position = vec4(a_position, 1.0);
  5. In.normal = a_normal;
  6. #if CC_SURFACES_USE_TANGENT_SPACE
  7. In.tangent = a_tangent;
  8. #endif
  9. #if CC_SURFACES_USE_VERTEX_COLOR
  10. In.color = a_color;
  11. #endif
  12. In.texCoord = a_texCoord;
  13. #if CC_SURFACES_USE_SECOND_UV
  14. In.texCoord1 = a_texCoord1;
  15. #endif
  16. }
  17. void CCSurfacesVertexOutput(in SurfacesStandardVertexIntermediate In)
  18. {
  19. gl_Position = In.clipPos;
  20. VSOutput_worldNormal = In.worldNormal.xyz;
  21. VSOutput_faceSideSign = In.worldNormal.w;
  22. VSOutput_worldPos = In.worldPos;
  23. #if CC_SURFACES_USE_TANGENT_SPACE
  24. VSOutput_worldTangent = In.worldTangent.xyz;
  25. // VSOutput_worldBitangent = In.worldBinormal;
  26. VSOutput_mirrorNormal = In.tangent.w > 0.0 ? 1.0 : -1.0; // for compatibility #14121
  27. #endif
  28. #if CC_SURFACES_USE_VERTEX_COLOR
  29. VSOutput_vertexColor = In.color;
  30. #endif
  31. VSOutput_texcoord = In.texCoord;
  32. #if CC_SURFACES_USE_SECOND_UV
  33. VSOutput_texcoord1 = In.texCoord1;
  34. #endif
  35. #if CC_USE_FOG != CC_FOG_NONE && !CC_USE_ACCURATE_FOG
  36. VSOutput_fogFactor = In.fogFactor;
  37. #endif
  38. #if CC_RECEIVE_SHADOW
  39. VSOutput_shadowBias = In.shadowBiasAndProbeId.xy;
  40. #endif
  41. #if CC_USE_REFLECTION_PROBE
  42. VSOutput_reflectionProbeId = In.shadowBiasAndProbeId.z;
  43. #if CC_USE_REFLECTION_PROBE == REFLECTION_PROBE_TYPE_BLEND || CC_USE_REFLECTION_PROBE == REFLECTION_PROBE_TYPE_BLEND_AND_SKYBOX
  44. VSOutput_reflectionProbeBlendId = In.shadowBiasAndProbeId.w;
  45. #endif
  46. #if USE_INSTANCING
  47. v_reflectionProbeData = a_reflectionProbeData;
  48. #endif
  49. #endif
  50. #if CC_USE_LIGHTMAP && !CC_FORWARD_ADD
  51. VSOutput_lightMapUV = In.lightmapUV;
  52. #endif
  53. #if CC_SURFACES_TRANSFER_LOCAL_POS
  54. VSOutput_localPos = In.position;
  55. #endif
  56. #if CC_SURFACES_TRANSFER_CLIP_POS
  57. VSOutput_clipPos = In.clipPos;
  58. #endif
  59. #if CC_USE_LIGHT_PROBE
  60. #if USE_INSTANCING
  61. v_sh_linear_const_r = a_sh_linear_const_r;
  62. v_sh_linear_const_g = a_sh_linear_const_g;
  63. v_sh_linear_const_b = a_sh_linear_const_b;
  64. #endif
  65. #endif
  66. }
  67. // Morph & Skinning
  68. void CCSurfacesVertexAnimation(inout SurfacesStandardVertexIntermediate In)
  69. {
  70. vec4 temp = vec4(0.0);
  71. #if CC_USE_MORPH
  72. #if CC_SURFACES_USE_TANGENT_SPACE
  73. applyMorph(In.position, In.normal, In.tangent);
  74. #else
  75. applyMorph(In.position, In.normal, temp);
  76. #endif
  77. #endif
  78. #if CC_USE_SKINNING
  79. #if CC_SURFACES_USE_TANGENT_SPACE
  80. CCSkin(In.position, In.normal, In.tangent);
  81. #else
  82. CCSkin(In.position, In.normal, temp);
  83. #endif
  84. #endif
  85. }
  86. // Space Transform
  87. void CCSurfacesVertexWorldTransform(inout SurfacesStandardVertexIntermediate In)
  88. {
  89. mat4 matWorld, matWorldIT;
  90. CCGetWorldMatrixFull(matWorld, matWorldIT);
  91. In.worldPos = (matWorld * In.position).xyz;
  92. In.worldNormal.xyz = normalize((matWorldIT * vec4(In.normal.xyz, 0.0)).xyz);
  93. #if CC_SURFACES_USE_TANGENT_SPACE
  94. In.worldTangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);
  95. In.worldBinormal = cross(In.worldNormal.xyz, In.worldTangent) * In.tangent.w; // note the cross order
  96. #endif
  97. }
  98. void CCSurfacesVertexTransformUV(inout SurfacesStandardVertexIntermediate In)
  99. {
  100. #if CC_SURFACES_FLIP_UV
  101. CC_HANDLE_RT_SAMPLE_FLIP(In.texCoord);
  102. #if CC_SURFACES_USE_SECOND_UV
  103. CC_HANDLE_RT_SAMPLE_FLIP(In.texCoord1);
  104. #endif
  105. #endif
  106. }
  107. // Shading
  108. void CCSurfacesVertexTransferFog(inout SurfacesStandardVertexIntermediate In)
  109. {
  110. #if CC_USE_FOG != CC_FOG_NONE && !CC_USE_ACCURATE_FOG
  111. CC_TRANSFER_FOG_BASE(vec4(In.worldPos, 1.0), In.fogFactor);
  112. #endif
  113. }
  114. void CCSurfacesVertexTransferShadow(inout SurfacesStandardVertexIntermediate In)
  115. {
  116. #if CC_RECEIVE_SHADOW || CC_USE_REFLECTION_PROBE
  117. In.shadowBiasAndProbeId = vec4(0.0);
  118. #endif
  119. #if CC_RECEIVE_SHADOW
  120. In.shadowBiasAndProbeId.xy = vec2(cc_shadowWHPBInfo.w, cc_shadowLPNNInfo.z);
  121. #if USE_INSTANCING
  122. In.shadowBiasAndProbeId.xy += a_localShadowBiasAndProbeId.xy;
  123. #else
  124. In.shadowBiasAndProbeId.xy += cc_localShadowBias.xy;
  125. #endif
  126. #endif
  127. #if CC_USE_REFLECTION_PROBE
  128. #if USE_INSTANCING
  129. In.shadowBiasAndProbeId.zw = a_localShadowBiasAndProbeId.zw;
  130. #else
  131. In.shadowBiasAndProbeId.zw = cc_localShadowBias.zw;
  132. #endif
  133. #endif
  134. }
  135. void CCSurfacesVertexTransferLightMapUV(inout SurfacesStandardVertexIntermediate In)
  136. {
  137. #if CC_USE_LIGHTMAP && !CC_FORWARD_ADD
  138. #if USE_INSTANCING
  139. In.lightmapUV.xy = a_lightingMapUVParam.xy + a_texCoord1 * a_lightingMapUVParam.z;
  140. In.lightmapUV.z = a_lightingMapUVParam.w;
  141. #else
  142. In.lightmapUV.xy = cc_lightingMapUVParam.xy + a_texCoord1 * cc_lightingMapUVParam.z;
  143. In.lightmapUV.z = cc_lightingMapUVParam.w;
  144. #endif
  145. #endif
  146. }