mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
[optimize] shadow pass texture sampling without alpha test (#12005)
This commit is contained in:
@@ -3,8 +3,9 @@ in highp vec2 v_clip_depth;
|
||||
layout(location = 0) out vec4 fragColorX;
|
||||
|
||||
void main () {
|
||||
// for alpha clip
|
||||
SurfacesFragmentModifyBaseColorAndTransparency();
|
||||
// better performance than SurfacesFragmentModifyBaseColorAndTransparency
|
||||
SurfacesFragmentAlphaClipOnly();
|
||||
|
||||
|
||||
highp float clipDepth = v_clip_depth.x / v_clip_depth.y * 0.5 + 0.5;
|
||||
// spot use linear
|
||||
|
||||
@@ -5,6 +5,13 @@ vec4 SurfacesFragmentModifyBaseColorAndTransparency()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
|
||||
// for base shape without color usage, such as render-to-shadow
|
||||
void SurfacesFragmentAlphaClipOnly()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
|
||||
vec3 SurfacesFragmentModifyWorldNormal()
|
||||
|
||||
@@ -368,11 +368,10 @@ CCProgram shadow-caster-fs %{
|
||||
vec4 frag () {
|
||||
vec4 baseColor = albedo;
|
||||
|
||||
#if USE_ALBEDO_MAP
|
||||
baseColor *= texture(albedoMap, ALBEDO_UV);
|
||||
#endif
|
||||
|
||||
#if USE_ALPHA_TEST
|
||||
#if USE_ALBEDO_MAP
|
||||
baseColor *= texture(albedoMap, ALBEDO_UV);
|
||||
#endif
|
||||
if (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -309,11 +309,11 @@ CCProgram shadow-caster-fs %{
|
||||
|
||||
vec4 frag () {
|
||||
vec4 baseColor = baseColor;
|
||||
#if USE_BASE_COLOR_MAP
|
||||
baseColor *= texture(baseColorMap, v_uv);
|
||||
#endif
|
||||
|
||||
#if USE_ALPHA_TEST
|
||||
#if USE_BASE_COLOR_MAP
|
||||
baseColor *= texture(baseColorMap, v_uv);
|
||||
#endif
|
||||
if (baseColor.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ CCEffect %{
|
||||
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
||||
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
alphaSource: { value: 1.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
alphaSourceMap: { value: grey, editor: { parent: USE_OPACITY_MAP } }
|
||||
- name: transparent
|
||||
passes:
|
||||
- vert: standard-vs
|
||||
@@ -435,19 +437,33 @@ CCProgram shadow-caster-fs %{
|
||||
#pragma define-meta ALBEDO_UV options([v_uv, v_uv1])
|
||||
#endif
|
||||
|
||||
#if USE_ALPHA_TEST
|
||||
#pragma define-meta ALPHA_TEST_CHANNEL options([a, r])
|
||||
#pragma define-meta TEXTURE_UV options([v_uv, v_uv1])
|
||||
|
||||
#if USE_OPACITY_MAP
|
||||
#pragma define-meta ALPHA_SOURCE_CHANNEL options([r, g, b, a])
|
||||
uniform sampler2D alphaSourceMap;
|
||||
#endif
|
||||
|
||||
vec4 frag () {
|
||||
vec4 baseColor = albedo;
|
||||
|
||||
#if USE_ALBEDO_MAP
|
||||
baseColor *= texture(albedoMap, ALBEDO_UV);
|
||||
#endif
|
||||
|
||||
#if USE_ALPHA_TEST
|
||||
if (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;
|
||||
float alpha = albedo.a;
|
||||
#if USE_ALBEDO_MAP
|
||||
alpha = texture(albedoMap, TEXTURE_UV).a;
|
||||
#endif
|
||||
#if ALPHA_SOURCE_IS_OPACITY
|
||||
#if USE_OPACITY_MAP
|
||||
alpha = 1.0 - texture(alphaSourceMap, TEXTURE_UV).ALPHA_SOURCE_CHANNEL;
|
||||
#else
|
||||
alpha = 1.0 - alphaSource;
|
||||
#endif
|
||||
#else
|
||||
#if USE_OPACITY_MAP
|
||||
alpha = texture(alphaSourceMap, TEXTURE_UV).ALPHA_SOURCE_CHANNEL;
|
||||
#else
|
||||
alpha = alphaSource;
|
||||
#endif
|
||||
#endif
|
||||
if (alpha < albedoScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
|
||||
highp float clipDepth = v_clip_depth.x / v_clip_depth.y * 0.5 + 0.5;
|
||||
|
||||
@@ -52,11 +52,13 @@ CCEffect %{
|
||||
rasterizerState:
|
||||
cullMode: front
|
||||
properties:
|
||||
tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
|
||||
mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
|
||||
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
||||
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
|
||||
mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
|
||||
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
||||
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
transparencyMap: { value: grey, editor: { displayName: TransparencyMap } }
|
||||
transparencyFactor: { value: 1.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
- name: transparent
|
||||
passes:
|
||||
- vert: standard-vs
|
||||
@@ -446,19 +448,13 @@ CCProgram shadow-caster-fs %{
|
||||
#endif
|
||||
|
||||
vec4 frag () {
|
||||
vec4 baseColor = diffuseColor;
|
||||
#if USE_ALBEDO_MAP
|
||||
vec4 texColor = texture(albedoMap, TEXTURE_UV);
|
||||
baseColor *= texColor;
|
||||
#endif
|
||||
|
||||
#if USE_TRANSPARENCY_MAP
|
||||
baseColor.a = texture(transparencyMap, TEXTURE_UV).a * transparencyFactor;
|
||||
#endif
|
||||
|
||||
#if USE_ALPHA_TEST
|
||||
if (baseColor.a < albedoScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
#if USE_ALPHA_TEST
|
||||
float alpha = 1.0;
|
||||
#if USE_TRANSPARENCY_MAP
|
||||
alpha = texture(transparencyMap, TEXTURE_UV).a * transparencyFactor;
|
||||
#endif
|
||||
if (alpha < albedoScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
|
||||
highp float clipDepth = v_clip_depth.x / v_clip_depth.y * 0.5 + 0.5;
|
||||
// spot use linear
|
||||
|
||||
@@ -57,6 +57,8 @@ CCEffect %{
|
||||
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
||||
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
alphaSource: { value: 1.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
alphaSourceMap: { value: grey, editor: { parent: USE_OPACITY_MAP } }
|
||||
- name: transparent
|
||||
passes:
|
||||
- vert: standard-vs
|
||||
@@ -225,6 +227,33 @@ CCProgram surface-fragment %{
|
||||
return baseColor;
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
|
||||
void SurfacesFragmentAlphaClipOnly()
|
||||
{
|
||||
#if USE_ALPHA_TEST
|
||||
float alpha = albedo.a;
|
||||
#if USE_ALBEDO_MAP
|
||||
alpha = texture(albedoMap, TEXTURE_UV).a;
|
||||
#endif
|
||||
|
||||
#if ALPHA_SOURCE_IS_OPACITY
|
||||
#if USE_OPACITY_MAP
|
||||
alpha = 1.0 - texture(alphaSourceMap, TEXTURE_UV).ALPHA_SOURCE_CHANNEL;
|
||||
#else
|
||||
alpha = 1.0 - alphaSource;
|
||||
#endif
|
||||
#else
|
||||
#if USE_OPACITY_MAP
|
||||
alpha = texture(alphaSourceMap, TEXTURE_UV).ALPHA_SOURCE_CHANNEL;
|
||||
#else
|
||||
alpha = alphaSource;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (alpha < albedoScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
|
||||
vec3 SurfacesFragmentModifyWorldNormal()
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ CCEffect %{
|
||||
specularMap: { value: grey, editor: { parent: '!HAS_EXPORTED_METALLIC' } }
|
||||
specularFactor: { value: 1.0, editor: { parent: '!HAS_EXPORTED_METALLIC' } }
|
||||
transparencyMap: { value: grey, editor: { displayName: TransparencyMap } }
|
||||
transparencyFactor: { value: 0.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
transparencyFactor: { value: 1.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
|
||||
normalStrength: { value: 1.0, target: normalScale, editor: { displayName: bumpFactor, parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } }
|
||||
normalMap: { value: normal }
|
||||
@@ -52,11 +52,13 @@ CCEffect %{
|
||||
rasterizerState:
|
||||
cullMode: front
|
||||
properties:
|
||||
tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
|
||||
mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
|
||||
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
||||
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
|
||||
mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
|
||||
albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
|
||||
alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
|
||||
mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
|
||||
transparencyMap: { value: grey, editor: { displayName: TransparencyMap } }
|
||||
transparencyFactor: { value: 1.0, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
|
||||
- name: transparent
|
||||
passes:
|
||||
- vert: standard-vs
|
||||
@@ -238,6 +240,18 @@ CCProgram surface-fragment %{
|
||||
return baseColor;
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
|
||||
void SurfacesFragmentAlphaClipOnly()
|
||||
{
|
||||
#if USE_ALPHA_TEST
|
||||
float alpha = 1.0;
|
||||
#if USE_TRANSPARENCY_MAP
|
||||
alpha = texture(transparencyMap, TEXTURE_UV).a * transparencyFactor;
|
||||
#endif
|
||||
if (alpha < albedoScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
|
||||
vec3 SurfacesFragmentModifyWorldNormal()
|
||||
{
|
||||
|
||||
@@ -193,7 +193,7 @@ CCProgram surface-fragment %{
|
||||
baseColor.rgb *= SRGBToLinear(FSInput_vertexColor.rgb); // use linear
|
||||
baseColor.a *= FSInput_vertexColor.a;
|
||||
#endif
|
||||
|
||||
|
||||
#if USE_ALBEDO_MAP
|
||||
vec4 texColor = texture(albedoMap, ALBEDO_UV);
|
||||
texColor.rgb = SRGBToLinear(texColor.rgb);
|
||||
@@ -208,10 +208,26 @@ CCProgram surface-fragment %{
|
||||
return baseColor;
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
|
||||
void SurfacesFragmentAlphaClipOnly()
|
||||
{
|
||||
#if USE_ALPHA_TEST
|
||||
float alpha = albedo.ALPHA_TEST_CHANNEL;
|
||||
#if USE_VERTEX_COLOR
|
||||
alpha *= FSInput_vertexColor.a;
|
||||
#endif
|
||||
#if USE_ALBEDO_MAP
|
||||
alpha = texture(albedoMap, ALBEDO_UV).ALPHA_TEST_CHANNEL;
|
||||
#endif
|
||||
|
||||
if (alpha < albedoScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
|
||||
vec3 SurfacesFragmentModifyWorldNormal()
|
||||
{
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
#if USE_NORMAL_MAP
|
||||
vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal);
|
||||
@@ -223,8 +239,8 @@ CCProgram surface-fragment %{
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_ANISOTROPY_PARAMS
|
||||
vec4 SurfacesFragmentModifyAnisotropyParams()
|
||||
{
|
||||
float anisotropyRotation = anisotropyParam.y;
|
||||
float anisotropyShape = anisotropyParam.x;
|
||||
float anisotropyRotation = anisotropyParam.y;
|
||||
float anisotropyShape = anisotropyParam.x;
|
||||
#if IS_ANISOTROPY && USE_ANISOTROPY_ROTATION_MAP
|
||||
anisotropyRotation = fract(anisotropyRotation + texture(anisotropyRotationMap, DEFAULT_UV).x);
|
||||
#endif
|
||||
|
||||
@@ -171,28 +171,23 @@ CCProgram surface-fragment %{
|
||||
#endif
|
||||
}
|
||||
|
||||
// only for render-to-shadow-map or misc usage
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY
|
||||
vec4 SurfacesFragmentModifyBaseColorAndTransparency()
|
||||
#define CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
|
||||
void SurfacesFragmentAlphaClipOnly()
|
||||
{
|
||||
vec4 color = baseColor;
|
||||
#if USE_BASE_COLOR_MAP
|
||||
vec4 texColor = texture(baseColorMap, FSInput_texcoord);
|
||||
texColor.rgb = SRGBToLinear(texColor.rgb);
|
||||
color *= texColor;
|
||||
#endif
|
||||
|
||||
#if USE_ALPHA_TEST
|
||||
if (color.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;
|
||||
float alpha = baseColor.ALPHA_TEST_CHANNEL;
|
||||
#if USE_BASE_COLOR_MAP
|
||||
alpha = texture(baseColorMap, FSInput_texcoord).ALPHA_TEST_CHANNEL;
|
||||
#endif
|
||||
|
||||
if (alpha < colorScaleAndCutoff.w) discard;
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
|
||||
vec3 SurfacesFragmentModifyWorldNormal()
|
||||
{
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
vec3 normal = FSInput_worldNormal;
|
||||
#if USE_NORMAL_MAP
|
||||
vec3 nmmp = texture(normalMap, FSInput_texcoord).xyz - vec3(0.5);
|
||||
normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleAndStrenth.w, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal);
|
||||
|
||||
Reference in New Issue
Block a user