#version 450 layout (binding = 1) uniform sampler2D samplerColor; layout (binding = 2) uniform sampler2D samplerColor_ex; layout (location = 0) in vec2 inUV; layout (location = 1) in vec3 inNormal; layout (location = 0) out vec4 outFragColor; void main() { vec4 color = texture(samplerColor, inUV); vec4 color_ex = texture(samplerColor_ex, inUV); vec3 N = normalize(inNormal); // 计算与 (0,0,1) 的点乘 float ndot = dot(N, vec3(0.0, 0.0, -1.0)); // 保证结果 >= 0 ndot = max(ndot, 0.0); // 重新映射ndot值,让中间2/3部分进行融合 // 当ndot在[0.166, 0.833]范围内时进行混合,两端保持不变 float blendFactor; if (ndot < 0.0) { blendFactor = 0.0; // 完全使用color_ex } else if (ndot > 0.1) { blendFactor = 1.0; // 完全使用color } else { // 在中间2/3部分进行平滑过渡 blendFactor = (ndot - 0.0) / (1 - 0); } // 使用smoothstep创建中间2/3的融合区域 // 参数说明:smoothstep(edge0, edge1, x) // 当x < edge0时返回0,当x > edge1时返回1,在中间时平滑过渡 //float blendFactor = smoothstep(0.166, 0.833, ndot); // vec4 blendedColor = mix(color_ex, color, ndot); // outFragColor = blendedColor; if (ndot < 0.3){ outFragColor = color_ex; } else { outFragColor = color; } // outFragColor = vec4(1, 0, 0, 1); }