partially fixed the shader. Still not pixel perfect, not NN interpolation, edge detection bad
This commit is contained in:
+9
-22
@@ -37,22 +37,14 @@ const shaderMaterial = new THREE.ShaderMaterial({
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec2 uv = vUv;
|
vec2 uv = vUv;
|
||||||
uv.x *= aspectRatio;
|
|
||||||
|
|
||||||
float screenPxCount = max(resolution.x, resolution.y) / (pxDensity * 12.5);
|
vec2 screenPxCount = vec2(resolution.x / pxDensity, resolution.y / pxDensity);
|
||||||
vec2 p = floor(uv * screenPxCount);
|
screenPxCount = vec2(256.0, 164.0);
|
||||||
p /= screenPxCount;
|
vec2 p = floor(uv * screenPxCount) / screenPxCount;
|
||||||
|
|
||||||
vec4 color = texture2D(tDiffuse, p);
|
vec4 color = texture2D(tDiffuse, p);
|
||||||
|
|
||||||
float brightness = (color.r + color.g + color.b) / 3.0;
|
gl_FragColor = color;
|
||||||
|
|
||||||
float threshold = 0.5;
|
|
||||||
vec3 finalColor = mix(centerColor, edgeColor, step(threshold, brightness));
|
|
||||||
|
|
||||||
if (color.a < 0.3) { finalColor = vec3(0.0); }
|
|
||||||
|
|
||||||
gl_FragColor = vec4(finalColor, color.a);
|
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
uniforms: {
|
uniforms: {
|
||||||
@@ -220,8 +212,8 @@ function generateHillMat(segments, width, length) {
|
|||||||
|
|
||||||
const fragmentShader = `
|
const fragmentShader = `
|
||||||
varying vec2 vUv;
|
varying vec2 vUv;
|
||||||
//uniform vec3 edgeColor;
|
uniform vec3 edgeColor;
|
||||||
//uniform vec3 centerColor;
|
uniform vec3 centerColor;
|
||||||
uniform int segmentCount;
|
uniform int segmentCount;
|
||||||
uniform vec2 resolution;
|
uniform vec2 resolution;
|
||||||
|
|
||||||
@@ -249,12 +241,7 @@ function generateHillMat(segments, width, length) {
|
|||||||
isEdge = 1.0;
|
isEdge = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// mix(centerColor, edgeColor, isEdge);
|
vec3 color = mix(centerColor, edgeColor, isEdge);
|
||||||
vec3 color = mix(
|
|
||||||
vec3(0.0, 0.0, 0.0),
|
|
||||||
vec3(1.0, 1.0, 1.0),
|
|
||||||
isEdge
|
|
||||||
);
|
|
||||||
|
|
||||||
gl_FragColor = vec4(color, 1.0);
|
gl_FragColor = vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
@@ -264,8 +251,8 @@ function generateHillMat(segments, width, length) {
|
|||||||
vertexShader,
|
vertexShader,
|
||||||
fragmentShader,
|
fragmentShader,
|
||||||
uniforms: {
|
uniforms: {
|
||||||
//edgeColor: { value: new THREE.Color(0x00b4f0) },
|
edgeColor: { value: new THREE.Color(0x00b4f0) },
|
||||||
//centerColor: { value: new THREE.Color(0x323232) },
|
centerColor: { value: new THREE.Color(0x323232) },
|
||||||
segmentCount: { value: segments },
|
segmentCount: { value: segments },
|
||||||
resolution: { value: new THREE.Vector2(width / segments, length) }
|
resolution: { value: new THREE.Vector2(width / segments, length) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user