diff --git a/js/regl/rainPass.js b/js/regl/rainPass.js index 8ceb6aa..1e0f04d 100644 --- a/js/regl/rainPass.js +++ b/js/regl/rainPass.js @@ -190,8 +190,8 @@ export default ({ regl, config, lkg }) => { glintTexture: glintTexture.texture, msdfPxRange: 4.0, - glyphMSDFSize: [glyphMSDF.width(), glyphMSDF.height()], - glintMSDFSize: [glintMSDF.width(), glintMSDF.height()], + glyphMSDFSize: () => [glyphMSDF.width(), glyphMSDF.height()], + glintMSDFSize: () => [glintMSDF.width(), glintMSDF.height()], camera: regl.prop("camera"), transform: regl.prop("transform"), diff --git a/js/regl/utils.js b/js/regl/utils.js index 6309afd..e18d619 100644 --- a/js/regl/utils.js +++ b/js/regl/utils.js @@ -36,8 +36,18 @@ const loadImage = (regl, url) => { } return texture; }, - width: () => (loaded ? texture.width : 1), - height: () => (loaded ? texture.height : 1), + width: () => { + if (!loaded && url != null) { + console.warn(`texture still loading: ${url}`); + } + return loaded ? texture.width : 1; + }, + height: () => { + if (!loaded && url != null) { + console.warn(`texture still loading: ${url}`); + } + return loaded ? texture.height : 1; + }, loaded: (async () => { if (url != null) { const data = new Image(); diff --git a/shaders/glsl/rainPass.frag.glsl b/shaders/glsl/rainPass.frag.glsl index 501c3cf..10b828c 100644 --- a/shaders/glsl/rainPass.frag.glsl +++ b/shaders/glsl/rainPass.frag.glsl @@ -117,7 +117,7 @@ vec2 getSymbol(vec2 uv, float index) { // MSDF: calculate brightness of fragment based on distance to shape vec2 symbol; { - vec2 unitRange = vec2(msdfPxRange) / (glyphMSDFSize * 1000.); // Not sure why this x1000 softening is necessary + vec2 unitRange = vec2(msdfPxRange) / glyphMSDFSize; vec2 screenTexSize = vec2(1.0) / fwidth(uv); float screenPxRange = max(0.5 * dot(unitRange, screenTexSize), 1.0); @@ -127,7 +127,7 @@ vec2 getSymbol(vec2 uv, float index) { } if (isolateGlint) { - vec2 unitRange = vec2(msdfPxRange) / (glintMSDFSize * 1000.); // Not sure why this x1000 softening is necessary + vec2 unitRange = vec2(msdfPxRange) / glintMSDFSize; vec2 screenTexSize = vec2(1.0) / fwidth(uv); float screenPxRange = max(0.5 * dot(unitRange, screenTexSize), 1.0); diff --git a/shaders/wgsl/rainPass.wgsl b/shaders/wgsl/rainPass.wgsl index c28d1a9..b953dfc 100644 --- a/shaders/wgsl/rainPass.wgsl +++ b/shaders/wgsl/rainPass.wgsl @@ -499,15 +499,14 @@ fn getSymbol(cellUV : vec2, index : i32) -> vec2 { uv += 0.5; uv = (uv + getSymbolUV(index)) / vec2(config.glyphTextureGridSize); - var symbol = vec2(); - // MSDF: calculate brightness of fragment based on distance to shape + var symbol = vec2(); { // var dist = textureSample(glyphMSDFTexture, linearSampler, uv).rgb; // var sigDist = median3(dist) - 0.5; // symbol.r = clamp(sigDist / fwidth(sigDist) + 0.5, 0.0, 1.0); - var unitRange = vec2(config.msdfPxRange) / (vec2(textureDimensions(glyphMSDFTexture)) * 1000.0); // Not sure why this x1000 softening is necessary + var unitRange = vec2(config.msdfPxRange) / vec2(textureDimensions(glyphMSDFTexture)); var screenTexSize = vec2(1.0) / fwidth(uv); var screenPxRange = max(0.5 * dot(unitRange, screenTexSize), 1.0); @@ -521,7 +520,7 @@ fn getSymbol(cellUV : vec2, index : i32) -> vec2 { // var sigDist = median3(dist) - 0.5; // symbol.g = clamp(sigDist / fwidth(sigDist) + 0.5, 0.0, 1.0); - var unitRange = vec2(config.msdfPxRange) / (vec2(textureDimensions(glintMSDFTexture)) * 1000.0); // Not sure why this x1000 softening is necessary + var unitRange = vec2(config.msdfPxRange) / vec2(textureDimensions(glintMSDFTexture)); var screenTexSize = vec2(1.0) / fwidth(uv); var screenPxRange = max(0.5 * dot(unitRange, screenTexSize), 1.0);