fix:TextInput support hot update;feat:add zero color and update
algorithm
This commit is contained in:
@@ -12,6 +12,7 @@ uniform vec2 uTexelSize;
|
||||
uniform vec2 uPlaneSize;
|
||||
uniform vec3 uCameraPos;
|
||||
uniform vec3 uLightDir;
|
||||
uniform vec3 uColorZero;
|
||||
uniform vec3 uColorLow;
|
||||
uniform vec3 uColorMid;
|
||||
uniform vec3 uColorHigh;
|
||||
@@ -22,6 +23,24 @@ float value01(float v) {
|
||||
return saturate((v - uMinV) / max(uMaxV - uMinV, 1e-6));
|
||||
}
|
||||
|
||||
float maxNeighborValue(vec2 uv) {
|
||||
vec2 texSizeF = 1.0 / uTexelSize;
|
||||
ivec2 texSizeI = ivec2(max(vec2(1.0), floor(texSizeF + 0.5)));
|
||||
ivec2 maxCoord = texSizeI - ivec2(1);
|
||||
|
||||
vec2 texelF = clamp(uv * texSizeF, vec2(0.0), vec2(maxCoord));
|
||||
ivec2 base = ivec2(floor(texelF));
|
||||
ivec2 base10 = min(base + ivec2(1, 0), maxCoord);
|
||||
ivec2 base01 = min(base + ivec2(0, 1), maxCoord);
|
||||
ivec2 base11 = min(base + ivec2(1, 1), maxCoord);
|
||||
|
||||
float v00 = texelFetch(uHeightTex, base, 0).r;
|
||||
float v10 = texelFetch(uHeightTex, base10, 0).r;
|
||||
float v01 = texelFetch(uHeightTex, base01, 0).r;
|
||||
float v11 = texelFetch(uHeightTex, base11, 0).r;
|
||||
return max(max(v00, v10), max(v01, v11));
|
||||
}
|
||||
|
||||
vec3 colorRamp(float t) {
|
||||
if (t < 0.5) {
|
||||
return mix(uColorLow, uColorMid, t / 0.5);
|
||||
@@ -31,8 +50,13 @@ vec3 colorRamp(float t) {
|
||||
|
||||
void main() {
|
||||
float vC = texture(uHeightTex, vUV).r;
|
||||
bool isZero = abs(vC) <= 1e-6;
|
||||
float t = value01(vC);
|
||||
vec3 base = colorRamp(t);
|
||||
float m = maxNeighborValue(vUV);
|
||||
float eps = max(1e-4, 0.001 * (uMaxV - uMinV));
|
||||
float force = smoothstep(uMaxV - eps, uMaxV, m);
|
||||
t = max(t, force);
|
||||
vec3 base = isZero ? uColorZero : colorRamp(t);
|
||||
|
||||
float vL = texture(uHeightTex, vUV - vec2(uTexelSize.x, 0.0)).r;
|
||||
float vR = texture(uHeightTex, vUV + vec2(uTexelSize.x, 0.0)).r;
|
||||
|
||||
Reference in New Issue
Block a user