fix(image-pipeline): align detail-adjust grain seed parity

This commit is contained in:
Matthias
2026-04-04 22:42:51 +02:00
parent 65e96cbdf1
commit 46b7aeb26e
4 changed files with 58 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ uniform float uDenoiseLuma;
uniform float uDenoiseColor;
uniform float uGrainAmount;
uniform float uGrainScale;
uniform float uImageWidth;
float pseudoNoise(float seed) {
float x = sin(seed * 12.9898) * 43758.5453;
@@ -36,7 +37,10 @@ void main() {
}
if (uGrainAmount > 0.0) {
float grainSeed = (gl_FragCoord.y * 4096.0 + gl_FragCoord.x) / max(0.5, uGrainScale);
float pixelX = floor(gl_FragCoord.x);
float pixelY = floor(gl_FragCoord.y);
float pixelIndex = ((pixelY * max(1.0, uImageWidth)) + pixelX) * 4.0;
float grainSeed = (pixelIndex + 1.0) / max(0.5, uGrainScale);
float grain = (pseudoNoise(grainSeed) - 0.5) * uGrainAmount * 40.0;
rgb += vec3(grain);
}

View File

@@ -274,6 +274,11 @@ function applyStepUniforms(
if (grainScaleLocation) {
gl.uniform1f(grainScaleLocation, Math.max(0.5, detail.grain.size));
}
const imageWidthLocation = gl.getUniformLocation(shaderProgram, "uImageWidth");
if (imageWidthLocation) {
gl.uniform1f(imageWidthLocation, request.width);
}
}
}