general improvements
This commit is contained in:
@@ -1,24 +1,26 @@
|
||||
$input v_color0
|
||||
$input v_normal
|
||||
$input v_uv0
|
||||
$input v_wpos
|
||||
|
||||
uniform vec4 u_time;
|
||||
uniform vec4 u_testColor;
|
||||
|
||||
#include "common.sh"
|
||||
|
||||
float circle(vec2 uv, float radius)
|
||||
{
|
||||
float distSq = uv.x * uv.x + uv.y * uv.y;
|
||||
// float result = distSq / (radius * radius);
|
||||
float result = sqrt(distSq) / radius / 2;
|
||||
// float result = sqrt(distSq) / radius;
|
||||
return result < 0.4;
|
||||
float result = sqrt(distSq) / radius;
|
||||
// return result < 0.5;
|
||||
return clamp(1.0 - result, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float calcBrightness(vec3 lightPos, vec3 vertPos)
|
||||
float calcBrightness(vec3 lightPos, vec3 vertPos, vec3 normal)
|
||||
{
|
||||
return clamp(1.0 - distance(lightPos, vertPos) * 0.01, 0.0, 1.0);
|
||||
vec3 lightDir = normalize(lightPos - vertPos);
|
||||
float diffuse = max(0.0, dot(lightDir, normal));
|
||||
return diffuse * clamp(1.0 - distance(lightPos, vertPos) * 0.01, 0.0, 1.0);
|
||||
}
|
||||
|
||||
float circles(vec2 uv, float level, float subLevel, float brightness)
|
||||
@@ -43,15 +45,21 @@ float circles(vec2 uv, float level, float subLevel, float brightness)
|
||||
return min(sum, 1.0);
|
||||
}
|
||||
|
||||
vec3 desaturate(vec3 color)
|
||||
{
|
||||
return vec3_splat(dot(color, vec3(0.33, 0.34, 0.33)));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
float testRadius = 50.0;
|
||||
float testRadius = 30.0;
|
||||
float testSpeed = 1.0;
|
||||
vec3 testOffset = vec3(0.0, 0.0, 50.0);
|
||||
float brightness = calcBrightness(testOffset + vec3(sin(u_time.x * testSpeed) * testRadius, 0.0, cos(u_time.x * testSpeed) * testRadius), v_wpos);
|
||||
brightness = 0.2 + brightness * 0.8;
|
||||
float3 lightPos = vec3(sin(u_time.x * testSpeed) * testRadius, 5.0, cos(u_time.x * testSpeed) * testRadius);
|
||||
float brightness = calcBrightness(lightPos, v_wpos, v_normal);
|
||||
// brightness = 0.1 + brightness * 0.9;
|
||||
|
||||
float baseScale = 10.0;
|
||||
float baseScale = 2.0;
|
||||
float2 dx = ddx(v_uv0 * baseScale);
|
||||
float2 dy = ddy(v_uv0 * baseScale);
|
||||
float2x2 mat = float2x2(dx, dy);
|
||||
@@ -63,13 +71,19 @@ void main()
|
||||
float2 freq = sqrt(float2(qq + discriminant, qq - discriminant) / 2.0);
|
||||
|
||||
float spacing = freq.y * exp2(2.0);
|
||||
spacing = 4.0 / spacing;
|
||||
spacing = 1.0 / spacing;
|
||||
spacing *= brightness; // TODO: check reference to see how to calculate this!
|
||||
float spacingLog = max(log2(spacing), 1.0);
|
||||
float spacingLog = max(log2(spacing), 0.0);
|
||||
int patternScaleLevel = floor(spacingLog);
|
||||
float patternFractional = spacingLog - patternScaleLevel;
|
||||
|
||||
vec2 uv = v_uv0 * exp2(patternScaleLevel);
|
||||
float dither = circles(uv, patternScaleLevel, patternFractional, brightness);
|
||||
gl_FragColor = lerp(dither, vec4(0.1, 0.1, 0.15, 1.0), vec4(0.9, 0.75, 0.3, 1.0));
|
||||
vec3 color = desaturate(u_testColor.xyz) * 0.01 + dither * u_testColor.xyz * 0.95;
|
||||
vec3 smoothColor = brightness * u_testColor.xyz;
|
||||
vec3 mixedColor = 0.1 * smoothColor + 0.9 * color;
|
||||
gl_FragColor = vec4(mixedColor, 1.0);
|
||||
// gl_FragColor = brightness;
|
||||
// gl_FragColor = dither;
|
||||
// gl_FragColor = u_testColor;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
vec4 v_color0 : COLOR0 = vec4(1.0, 1.0, 0.0, 1.0);
|
||||
vec3 v_normal : NORMAL = vec3(0.0, 0.0, 1.0);
|
||||
vec2 v_uv0 : TEXCOORD0 = vec2(0.0, 0.0);
|
||||
vec3 v_wpos : TEXCOORD1 = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
vec3 a_position : POSITION;
|
||||
vec3 a_normal : NORMAL;
|
||||
vec4 a_color0 : COLOR0;
|
||||
vec2 a_texcoord0 : TEXCOORD0;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
$input a_position, a_color0, a_texcoord0
|
||||
$output v_color0, v_uv0, v_wpos
|
||||
$input a_position, a_normal, a_color0, a_texcoord0
|
||||
$output v_color0, v_normal, v_uv0, v_wpos
|
||||
|
||||
#include "common.sh"
|
||||
|
||||
@@ -9,4 +9,6 @@ void main()
|
||||
v_color0 = a_color0;
|
||||
v_uv0 = a_texcoord0;
|
||||
v_wpos = mul(u_model[0], vec4(a_position, 1.0)).xyz;
|
||||
|
||||
v_normal = normalize(mul((mat3)u_model[0], a_normal));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user