magical new dots
This commit is contained in:
@@ -7,6 +7,7 @@ $input v_wpos
|
||||
|
||||
SAMPLER2D(s_texColor, 0);
|
||||
SAMPLER3D(s_ditherSampler, 1);
|
||||
SAMPLER2D(s_rampSampler, 2);
|
||||
uniform vec4 u_time;
|
||||
uniform vec4 u_testColor;
|
||||
|
||||
@@ -29,19 +30,35 @@ vec3 desaturate(vec3 color)
|
||||
|
||||
void main()
|
||||
{
|
||||
// setup
|
||||
float globalScale = 6.0;
|
||||
float testRadius = 30.0;
|
||||
float testSpeed = 1.0;
|
||||
vec3 testOffset = vec3(0.0, 0.0, 50.0);
|
||||
float3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius);
|
||||
vec2 inputUv = v_uv0;
|
||||
vec3 texColor = u_testColor.x > 0.1 ? u_testColor.xyz : texture2D(s_texColor, v_uv0).xyz;
|
||||
|
||||
// lighting
|
||||
// float brightness = calcBrightness(lightPos, v_wpos, v_normal);
|
||||
float brightness = calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal);
|
||||
brightness = 1.0;
|
||||
// brightness = sin(u_time.x) * 0.5 + 0.5;
|
||||
float brightness = lerp(0.5, 0.9, calcBrightnessDirectional(vec3(0.5, 0.3, 1.0), v_normal));
|
||||
// float brightness = 0.5;
|
||||
// brightness = lerp(0.2, 1.0, sin(u_time.x) * 0.5 + 0.5);
|
||||
|
||||
// constants
|
||||
float dotsPerSide = 2;
|
||||
float dotsTotal = dotsPerSide * dotsPerSide;
|
||||
float xRes = 32;
|
||||
float invXRes = 1 / xRes;
|
||||
float zRes = dotsTotal;
|
||||
float invZRes = 1 / zRes;
|
||||
|
||||
float2 rampLookupUv = vec2((0.5 * invXRes + (1 - invXRes) * brightness), 0.5);
|
||||
float brightnessCurve = texture2D(s_rampSampler, rampLookupUv).r;
|
||||
|
||||
// Magic dot frequency calculation
|
||||
float baseScale = 8.0;
|
||||
float2 dx = ddx(v_uv0 * baseScale);
|
||||
float2 dy = ddy(v_uv0 * baseScale);
|
||||
float2 dx = ddx(inputUv);
|
||||
float2 dy = ddy(inputUv);
|
||||
float2x2 mat = float2x2(dx, dy);
|
||||
float4 vectorized = float4(dx, dy);
|
||||
float qq = dot(vectorized, vectorized);
|
||||
@@ -51,23 +68,34 @@ void main()
|
||||
float2 freq = sqrt(float2(qq + discriminant, qq - discriminant) / 2.0);
|
||||
|
||||
// Figuring out how many dots we want
|
||||
float spacing = freq.y * exp2(2.0);
|
||||
spacing = 1.0 / spacing;
|
||||
spacing *= brightness; // TODO: check reference to see how to calculate this!
|
||||
float spacingLog = max(log2(spacing), 0.0);
|
||||
float scaleExp = exp2(globalScale);
|
||||
float spacing = freq.y * scaleExp;
|
||||
|
||||
float brightnessSpacingMultiplier = pow(brightnessCurve * 2 + 0.001, -(1 - 0.5));
|
||||
// float brightnessSpacingMultiplier = 1;
|
||||
spacing *= brightnessSpacingMultiplier;
|
||||
|
||||
float spacingLog = log2(spacing);
|
||||
int patternScaleLevel = floor(spacingLog);
|
||||
float patternFractional = spacingLog - patternScaleLevel;
|
||||
vec2 uv = v_uv0 * exp2(patternScaleLevel);
|
||||
|
||||
float dotsTotal = 4;
|
||||
float subLayer = lerp(0.25 * dotsTotal, dotsTotal, patternFractional);
|
||||
subLayer = (subLayer - 0.5) / dotsTotal;
|
||||
vec2 uv = inputUv / exp2(patternScaleLevel);
|
||||
|
||||
vec4 circleSample = texture3D(s_ditherSampler, vec3(uv, subLayer));
|
||||
float circleVal = circleSample.x < 0.75 ? 0.1 : 0.9;
|
||||
// patternFractional *= patternFractional;
|
||||
// patternFractional = smoothstep(0, 1, patternFractional);
|
||||
float subLayer = lerp(0.25 * dotsTotal, dotsTotal, 1 - patternFractional);
|
||||
subLayer = (subLayer - 0.5) * invZRes;
|
||||
|
||||
// Coloring
|
||||
vec3 texColor = u_testColor.x > 0.1 ? u_testColor.xyz : texture2D(s_texColor, v_uv0).xyz;
|
||||
vec3 finalColor = texColor * vec3(circleVal, circleVal, circleVal);
|
||||
float pattern = texture3D(s_ditherSampler, vec3(uv, subLayer)).r;
|
||||
|
||||
float contrast = 12 * scaleExp * brightnessSpacingMultiplier * 0.1;
|
||||
contrast *= pow(freq.y / freq.x, 1.0);
|
||||
float baseVal = lerp(0.5, brightness, saturate(1.05 / (1 + contrast)));
|
||||
float threshold = 1 - brightnessCurve + 0.6;
|
||||
|
||||
vec3 thresholds = threshold.xxx / texColor;
|
||||
// vec3 finalColor = saturate((pattern - thresholds) * contrast + baseVal);
|
||||
vec3 finalColor = saturate((pattern - thresholds) * contrast + baseVal);
|
||||
gl_FragColor = vec4(finalColor, 1.0);
|
||||
// gl_FragColor = vec4(finalColor * 0.8 + subLayer * 0.2, 1.0);
|
||||
// gl_FragColor = vec4(finalColor * 0.8 + vec3(uv % 1, 0.0) * 0.2, 1.0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user