Added textures to base and glint shapes.

This commit is contained in:
Rezmason
2022-09-17 13:51:48 -07:00
parent eddbd12c36
commit e2be02c498
12 changed files with 167 additions and 48 deletions

View File

@@ -6,7 +6,8 @@ precision lowp float;
uniform sampler2D raindropState, symbolState, effectState;
uniform float numColumns, numRows;
uniform sampler2D glyphTex, glintTex;
uniform sampler2D glyphMSDF, glintMSDF, baseTexture, glintTexture;
uniform bool hasBaseTexture, hasGlintTexture;
uniform float glyphHeightToWidth, glyphSequenceLength, glyphEdgeCrop;
uniform float baseContrast, baseBrightness, glintContrast, glintBrightness;
uniform float brightnessOverride, brightnessThreshold;
@@ -58,7 +59,7 @@ vec2 getUV(vec2 uv) {
return uv;
}
vec3 getBrightness(vec4 raindrop, vec4 effect, float quadDepth) {
vec3 getBrightness(vec4 raindrop, vec4 effect, float quadDepth, vec2 uv) {
float base = raindrop.r;
bool isCursor = bool(raindrop.g) && isolateCursor;
@@ -66,8 +67,15 @@ vec3 getBrightness(vec4 raindrop, vec4 effect, float quadDepth) {
float multipliedEffects = effect.r;
float addedEffects = effect.g;
vec2 textureUV = fract(uv * vec2(numColumns, numRows));
base = base * baseContrast + baseBrightness;
if (hasBaseTexture) {
base *= texture2D(baseTexture, textureUV).r;
}
glint = glint * glintContrast + glintBrightness;
if (hasGlintTexture) {
glint *= texture2D(glintTexture, textureUV).r;
}
// Modes that don't fade glyphs set their actual brightness here
if (brightnessOverride > 0. && base > brightnessThreshold && !isCursor) {
@@ -107,13 +115,13 @@ vec2 getSymbol(vec2 uv, float index) {
// MSDF: calculate brightness of fragment based on distance to shape
vec2 symbol;
{
vec3 dist = texture2D(glyphTex, uv).rgb;
vec3 dist = texture2D(glyphMSDF, uv).rgb;
float sigDist = median3(dist) - 0.5;
symbol.r = clamp(sigDist / fwidth(sigDist) + 0.5, 0., 1.);
}
if (isolateGlint) {
vec3 dist = texture2D(glintTex, uv).rgb;
vec3 dist = texture2D(glintMSDF, uv).rgb;
float sigDist = median3(dist) - 0.5;
symbol.g = clamp(sigDist / fwidth(sigDist) + 0.5, 0., 1.);
}
@@ -133,7 +141,8 @@ void main() {
vec3 brightness = getBrightness(
raindropData,
effectData,
vDepth
vDepth,
uv
);
vec2 symbol = getSymbol(uv, symbolData.r);
@@ -142,8 +151,8 @@ void main() {
vec3(
raindropData.g,
vec2(
1. - (raindropData.r * 3.),
1. - (raindropData.r * 8.)
1. - ((1.0 - raindropData.r) * 3.),
1. - ((1.0 - raindropData.r) * 8.)
) * (1. - raindropData.g)
) * symbol.r,
1.

View File

@@ -31,6 +31,8 @@ struct Config {
baseContrast : f32,
glintBrightness : f32,
glintContrast : f32,
hasBaseTexture: i32,
hasGlintTexture: i32,
glyphVerticalSpacing : f32,
glyphEdgeCrop : f32,
isPolar : i32,
@@ -80,7 +82,9 @@ struct CellData {
@group(0) @binding(3) var linearSampler : sampler;
@group(0) @binding(4) var msdfTexture : texture_2d<f32>;
@group(0) @binding(5) var glintMSDFTexture : texture_2d<f32>;
@group(0) @binding(6) var<storage, read> cells_RO : CellData;
@group(0) @binding(6) var baseTexture : texture_2d<f32>;
@group(0) @binding(7) var glintTexture : texture_2d<f32>;
@group(0) @binding(8) var<storage, read> cells_RO : CellData;
// Shader params
@@ -373,7 +377,7 @@ fn getUV(inputUV : vec2<f32>) -> vec2<f32> {
return uv;
}
fn getBrightness(raindrop : vec4<f32>, effect : vec4<f32>, quadDepth : f32) -> vec3<f32> {
fn getBrightness(raindrop : vec4<f32>, effect : vec4<f32>, uv : vec2<f32>, quadDepth : f32) -> vec3<f32> {
var base = raindrop.r;
var isCursor = bool(raindrop.g) && bool(config.isolateCursor);
@@ -381,8 +385,15 @@ fn getBrightness(raindrop : vec4<f32>, effect : vec4<f32>, quadDepth : f32) -> v
var multipliedEffects = effect.r;
var addedEffects = effect.g;
var textureUV = fract(uv * config.gridSize);
base = base * config.baseContrast + config.baseBrightness;
if (bool(config.hasBaseTexture)) {
base *= textureSample(baseTexture, linearSampler, textureUV).r;
}
glint = glint * config.glintContrast + config.glintBrightness;
if (bool(config.hasGlintTexture)) {
glint *= textureSample(glintTexture, linearSampler, textureUV).r;
}
// Modes that don't fade glyphs set their actual brightness here
if (config.brightnessOverride > 0. && base > config.brightnessThreshold && !isCursor) {
@@ -451,6 +462,7 @@ fn getSymbol(cellUV : vec2<f32>, index : i32) -> vec2<f32> {
var brightness = getBrightness(
cell.raindrop,
cell.effect,
uv,
input.quadDepth
);
var symbol = getSymbol(uv, i32(cell.symbol.r));
@@ -462,8 +474,8 @@ fn getSymbol(cellUV : vec2<f32>, index : i32) -> vec2<f32> {
vec3<f32>(
cell.raindrop.g,
vec2<f32>(
1.0 - (cell.raindrop.r * 3.0),
1.0 - (cell.raindrop.r * 8.0)
1.0 - ((1.0 - cell.raindrop.r) * 3.0),
1.0 - ((1.0 - cell.raindrop.r) * 8.0)
) * (1.0 - cell.raindrop.g)
) * symbol.r,
1.0