添加非线性颜色过滤
This commit is contained in:
@@ -6,26 +6,40 @@ layout (binding = 2) uniform sampler2D samplerColor_ex;
|
|||||||
layout (location = 0) in vec2 inUV;
|
layout (location = 0) in vec2 inUV;
|
||||||
layout (location = 1) in vec3 inNormal;
|
layout (location = 1) in vec3 inNormal;
|
||||||
|
|
||||||
|
|
||||||
layout (location = 0) out vec4 outFragColor;
|
layout (location = 0) out vec4 outFragColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 color = texture(samplerColor, inUV);
|
vec4 color = texture(samplerColor, inUV);
|
||||||
vec4 color_ex = texture(samplerColor_ex, inUV);
|
vec4 color_ex = texture(samplerColor_ex, inUV);
|
||||||
|
|
||||||
vec3 N = normalize(inNormal);
|
vec3 N = normalize(inNormal);
|
||||||
|
|
||||||
vec4 textureColor = color;
|
// 计算与 (0,0,1) 的点乘
|
||||||
|
|
||||||
// 计算与 (0,0,1) 的点乘
|
|
||||||
float ndot = dot(N, vec3(0.0, 0.0, -1.0));
|
float ndot = dot(N, vec3(0.0, 0.0, -1.0));
|
||||||
|
|
||||||
// 保证结果 >= 0
|
// 保证结果 >= 0
|
||||||
ndot = max(ndot, 0.0);
|
ndot = max(ndot, 0.0);
|
||||||
|
|
||||||
vec4 blendedColor = mix(color_ex, color, ndot);
|
// 重新映射ndot值,让中间2/3部分进行融合
|
||||||
|
// 当ndot在[0.166, 0.833]范围内时进行混合,两端保持不变
|
||||||
|
float blendFactor;
|
||||||
|
if (ndot < 0.166) {
|
||||||
|
blendFactor = 0.0; // 完全使用color_ex
|
||||||
|
} else if (ndot > 0.833) {
|
||||||
|
blendFactor = 1.0; // 完全使用color
|
||||||
|
} else {
|
||||||
|
// 在中间2/3部分进行平滑过渡
|
||||||
|
blendFactor = (ndot - 0.166) / (0.833 - 0.166);
|
||||||
|
}
|
||||||
|
|
||||||
outFragColor = blendedColor;
|
// 使用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, blendFactor);
|
||||||
|
|
||||||
|
outFragColor = blendedColor;
|
||||||
}
|
}
|
||||||
Binary file not shown.
Reference in New Issue
Block a user