diff --git a/js/config.js b/js/config.js index c67f0cd..ce42806 100644 --- a/js/config.js +++ b/js/config.js @@ -3,29 +3,29 @@ const fonts = { // The script the Gnostic codices were written in glyphTexURL: "assets/coptic_msdf.png", glyphSequenceLength: 32, - glyphTextureColumns: 8, + glyphTextureGridSize: [8, 8], }, gothic: { // The script the Codex Argenteus was written in glyphTexURL: "assets/gothic_msdf.png", glyphSequenceLength: 27, - glyphTextureColumns: 8, + glyphTextureGridSize: [8, 8], }, matrixcode: { // The glyphs seen in the film trilogy glyphTexURL: "assets/matrixcode_msdf.png", glyphSequenceLength: 57, - glyphTextureColumns: 8, + glyphTextureGridSize: [8, 8], }, huberfishA: { glyphTexURL: "assets/huberfish_a_msdf.png", glyphSequenceLength: 34, - glyphTextureColumns: 6, + glyphTextureGridSize: [6, 6], }, huberfishD: { glyphTexURL: "assets/huberfish_d_msdf.png", glyphSequenceLength: 34, - glyphTextureColumns: 6, + glyphTextureGridSize: [6, 6], }, }; diff --git a/js/regl/rainPass.js b/js/regl/rainPass.js index e8ec541..c5a9a53 100644 --- a/js/regl/rainPass.js +++ b/js/regl/rainPass.js @@ -40,7 +40,7 @@ export default ({ regl, config }) => { const showComputationTexture = config.effect === "none"; const commonUniforms = { - ...extractEntries(config, ["animationSpeed", "glyphHeightToWidth", "glyphSequenceLength", "glyphTextureColumns", "resurrectingCodeRatio"]), + ...extractEntries(config, ["animationSpeed", "glyphHeightToWidth", "glyphSequenceLength", "glyphTextureGridSize", "resurrectingCodeRatio"]), numColumns, numRows, showComputationTexture, diff --git a/shaders/glsl/rainPass.frag.glsl b/shaders/glsl/rainPass.frag.glsl index cf2c666..4b82175 100644 --- a/shaders/glsl/rainPass.frag.glsl +++ b/shaders/glsl/rainPass.frag.glsl @@ -7,7 +7,8 @@ precision lowp float; uniform sampler2D state; uniform float numColumns, numRows; uniform sampler2D glyphTex; -uniform float glyphHeightToWidth, glyphSequenceLength, glyphTextureColumns, glyphEdgeCrop; +uniform float glyphHeightToWidth, glyphSequenceLength, glyphEdgeCrop; +uniform vec2 glyphTextureGridSize; uniform vec2 slantVec; uniform float slantScale; uniform bool isPolar; @@ -24,8 +25,8 @@ float median3(vec3 i) { vec2 getSymbolUV(float glyphCycle) { float symbol = floor(glyphSequenceLength * glyphCycle); - float symbolX = mod(symbol, glyphTextureColumns); - float symbolY = glyphTextureColumns - floor(symbol / glyphTextureColumns); + float symbolX = mod(symbol, glyphTextureGridSize.x); + float symbolY = floor(symbol / glyphTextureGridSize.y); return vec2(symbolX, symbolY); } @@ -71,7 +72,7 @@ void main() { glyphUV -= 0.5; glyphUV *= clamp(1.0 - glyphEdgeCrop, 0.0, 1.0); glyphUV += 0.5; - vec2 msdfUV = (glyphUV + symbolUV) / glyphTextureColumns; + vec2 msdfUV = (glyphUV + symbolUV) / glyphTextureGridSize; // MSDF: calculate brightness of fragment based on distance to shape vec3 dist = texture2D(glyphTex, msdfUV).rgb; diff --git a/shaders/wgsl/rainPass.wgsl b/shaders/wgsl/rainPass.wgsl index d45c027..ed6514f 100644 --- a/shaders/wgsl/rainPass.wgsl +++ b/shaders/wgsl/rainPass.wgsl @@ -5,7 +5,7 @@ // common properties used for compute and rendering animationSpeed : f32; glyphSequenceLength : i32; - glyphTextureColumns : i32; + glyphTextureGridSize : vec2; glyphHeightToWidth : f32; resurrectingCodeRatio : f32; gridSize : vec2; @@ -361,8 +361,8 @@ fn median3(i : vec3) -> f32 { fn getSymbolUV(glyphCycle : f32) -> vec2 { var symbol = i32(f32(config.glyphSequenceLength) * glyphCycle); - var symbolX = symbol % config.glyphTextureColumns; - var symbolY = symbol / config.glyphTextureColumns; + var symbolX = symbol % config.glyphTextureGridSize.x; + var symbolY = symbol / config.glyphTextureGridSize.y; return vec2(f32(symbolX), f32(symbolY)); } @@ -420,7 +420,7 @@ fn getSymbolUV(glyphCycle : f32) -> vec2 { glyphUV = glyphUV - 0.5; glyphUV = glyphUV * clamp(1.0 - config.glyphEdgeCrop, 0.0, 1.0); glyphUV = glyphUV + 0.5; - var msdfUV = (glyphUV + symbolUV) / f32(config.glyphTextureColumns); + var msdfUV = (glyphUV + symbolUV) / vec2(config.glyphTextureGridSize); // MSDF : calculate brightness of fragment based on distance to shape var dist = textureSample(msdfTexture, linearSampler, msdfUV).rgb;