45 lines
1.6 KiB
Plaintext
45 lines
1.6 KiB
Plaintext
shader_type canvas_item;
|
||
|
||
uniform float bulge_position : hint_range(0.0, 1.0) = 0.3;
|
||
uniform float bulge_height : hint_range(0.0, 1.0) = 0.2;
|
||
uniform float bulge_width : hint_range(0.01, 0.5) = 0.1;
|
||
uniform bool debug_mode = false;
|
||
|
||
void vertex() {
|
||
// 获取当前顶点在纹理中的水平位置(0-1范围)
|
||
float x_pos = UV.x;
|
||
|
||
// 计算距离隆起中心点的距离
|
||
float distance_from_center = abs(x_pos - bulge_position);
|
||
|
||
// 使用 smoothstep 创建从中心到边缘的平滑过渡
|
||
// 当 distance_from_center = 0 时,返回 1.0
|
||
// 当 distance_from_center >= bulge_width 时,返回 0.0
|
||
float bulge_factor = 1.0 - smoothstep(0.0, bulge_width, distance_from_center);
|
||
|
||
// 应用更自然的隆起曲线(抛物线型)
|
||
//bulge_factor = pow(bulge_factor, 2.0);
|
||
|
||
// 修改顶点位置,向上移动
|
||
VERTEX.y -= bulge_factor * bulge_height * 100.0; // 乘以100.0调整隆起幅度
|
||
}
|
||
|
||
|
||
//void fragment() {
|
||
//if (debug_mode) {
|
||
//// 调试模式:显示 UV.x 的值作为颜色
|
||
//COLOR = vec4(UV.x, 0.0, 0.0, 1.0);
|
||
//} else {
|
||
//float x_pos = UV.x;
|
||
//float distance_from_center = abs(x_pos - bulge_position);
|
||
//float bulge_factor = 1.0 - smoothstep(0.0, bulge_width, distance_from_center);
|
||
//
|
||
//// 在隆起区域显示不同颜色来验证计算
|
||
//vec4 original_color = texture(TEXTURE, UV);
|
||
//if (bulge_factor > 0.1) {
|
||
//COLOR = mix(original_color, vec4(1.0, 0.0, 0.0, 1.0), 0.3);
|
||
//} else {
|
||
//COLOR = original_color;
|
||
//}
|
||
//}
|
||
//} |