Improve color handling approach
This commit is contained in:
parent
e53ca905af
commit
f29293c475
22 changed files with 259 additions and 181 deletions
|
|
@ -6,17 +6,23 @@ uniform float maxMinDistance;
|
|||
uniform float distanceNdcPixelSize;
|
||||
varying vec2 position;
|
||||
|
||||
uniform sampler2D palette;
|
||||
|
||||
vec4 readFromPalette(int index) {
|
||||
return texture2D(palette, vec2((float(index) + 0.5) / {paletteSize}, 0.5));
|
||||
}
|
||||
|
||||
|
||||
{macroDefinitions}
|
||||
|
||||
{declarations}
|
||||
|
||||
void main() {
|
||||
float minDistance = maxMinDistance;
|
||||
float color = 0.0;
|
||||
|
||||
float objectMinDistance, objectColor;
|
||||
float minDistance = maxMinDistance, objectMinDistance;
|
||||
vec4 color = {backgroundColor};
|
||||
vec4 objectColor;
|
||||
|
||||
{functionCalls}
|
||||
|
||||
gl_FragColor = vec4(minDistance * 8.0, color, 0.0, 1.0);
|
||||
gl_FragColor = vec4(color.rgb, minDistance * 8.0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,21 +6,28 @@ uniform float maxMinDistance;
|
|||
uniform float distanceNdcPixelSize;
|
||||
in vec2 position;
|
||||
|
||||
uniform sampler2D palette;
|
||||
|
||||
#define WEBGL2_IS_AVAILABLE
|
||||
|
||||
vec4 readFromPalette(int index) {
|
||||
return texture(palette, vec2((float(index) + 0.5) / {paletteSize}, 0.5));
|
||||
}
|
||||
|
||||
{macroDefinitions}
|
||||
|
||||
{declarations}
|
||||
|
||||
out vec2 fragmentColor;
|
||||
layout(location = 0) out vec4 fragmentColor;
|
||||
layout(location = 1) out float distanceValue;
|
||||
|
||||
void main() {
|
||||
float minDistance = maxMinDistance;
|
||||
float color = 0.0;
|
||||
|
||||
float objectMinDistance, objectColor;
|
||||
float minDistance = maxMinDistance, objectMinDistance;
|
||||
vec4 color = {backgroundColor};
|
||||
vec4 objectColor;
|
||||
|
||||
{functionCalls}
|
||||
|
||||
fragmentColor = vec2(minDistance, color);
|
||||
distanceValue = minDistance;
|
||||
fragmentColor = color;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,22 +10,20 @@ precision lowp float;
|
|||
uniform float shadingNdcPixelSize;
|
||||
uniform vec2 squareToAspectRatioTimes2;
|
||||
uniform vec3 ambientLight;
|
||||
uniform vec4 backgroundColor;
|
||||
|
||||
uniform sampler2D distanceTexture;
|
||||
uniform sampler2D palette;
|
||||
uniform sampler2D colorTexture;
|
||||
|
||||
varying vec2 position;
|
||||
varying vec2 uvCoordinates;
|
||||
|
||||
float getDistance(in vec2 target, out vec4 color) {
|
||||
vec4 values = texture2D(distanceTexture, target);
|
||||
color = texture2D(palette, vec2(values[1], 0.0));
|
||||
return values[0] / 8.0;
|
||||
vec4 values = texture2D(colorTexture, target);
|
||||
color = vec4(values.rgb, 1.0);
|
||||
return values[3] / 8.0;
|
||||
}
|
||||
|
||||
float getDistance(in vec2 target) {
|
||||
return texture2D(distanceTexture, target)[0] / 8.0;
|
||||
return texture2D(colorTexture, target)[3] / 8.0;
|
||||
}
|
||||
|
||||
float shadowTransparency(float startingDistance, float lightCenterDistance, vec2 direction) {
|
||||
|
|
@ -122,13 +120,13 @@ void main() {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
vec3 outsideColor = backgroundColor.rgb * lighting;
|
||||
vec3 outsideColor = {backgroundColor}.rgb * lighting;
|
||||
vec3 insideColor = colorAtPosition * lightingInside;
|
||||
|
||||
float edge = clamp(startingDistance / shadingNdcPixelSize, 0.0, 1.0);
|
||||
vec3 antialiasedColor = mix(insideColor, outsideColor, edge);
|
||||
gl_FragColor = vec4(
|
||||
antialiasedColor,
|
||||
mix(rgbaColorAtPosition.a, backgroundColor.a, step(0.0, startingDistance))
|
||||
rgbaColorAtPosition.a
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,23 +8,21 @@ precision lowp float;
|
|||
{macroDefinitions}
|
||||
|
||||
uniform float shadingNdcPixelSize;
|
||||
uniform float distanceNdcPixelSize;
|
||||
uniform vec2 squareToAspectRatioTimes2;
|
||||
uniform vec3 ambientLight;
|
||||
uniform vec4 backgroundColor;
|
||||
|
||||
uniform sampler2D distanceTexture;
|
||||
uniform sampler2D palette;
|
||||
uniform sampler2D colorTexture;
|
||||
|
||||
in vec2 position;
|
||||
in vec2 uvCoordinates;
|
||||
|
||||
float getDistance(in vec2 target, out vec4 color) {
|
||||
vec4 values = texture(distanceTexture, target);
|
||||
color = texture(palette, vec2(values[1], 0.0));
|
||||
return values[0];
|
||||
vec4 getColor(vec2 target) {
|
||||
return texture(colorTexture, target);
|
||||
}
|
||||
|
||||
float getDistance(in vec2 target) {
|
||||
float getDistance(vec2 target) {
|
||||
return texture(distanceTexture, target)[0];
|
||||
}
|
||||
|
||||
|
|
@ -83,13 +81,14 @@ float shadowTransparency(float startingDistance, float lightCenterDistance, vec2
|
|||
|
||||
out vec4 fragmentColor;
|
||||
void main() {
|
||||
vec4 rgbaColorAtPosition;
|
||||
float startingDistance = getDistance(uvCoordinates, rgbaColorAtPosition);
|
||||
|
||||
vec4 rgbaColorAtPosition = getColor(uvCoordinates);
|
||||
vec3 colorAtPosition = rgbaColorAtPosition.rgb;
|
||||
|
||||
float startingDistance = getDistance(uvCoordinates);
|
||||
|
||||
|
||||
vec3 lighting = ambientLight;
|
||||
vec3 lightingInside = lighting;
|
||||
vec3 lightingInside = ambientLight;
|
||||
|
||||
#ifdef CIRCLE_LIGHT_COUNT
|
||||
#if CIRCLE_LIGHT_COUNT > 0
|
||||
|
|
@ -142,13 +141,13 @@ void main() {
|
|||
#endif
|
||||
#endif
|
||||
|
||||
vec3 outsideColor = backgroundColor.rgb * lighting;
|
||||
vec3 outsideColor = {backgroundColor}.rgb * lighting;
|
||||
vec3 insideColor = colorAtPosition * lightingInside * INTENSITY_INSIDE_RATIO;
|
||||
|
||||
|
||||
float edge = clamp(startingDistance / shadingNdcPixelSize, 0.0, 1.0);
|
||||
vec3 antialiasedColor = mix(insideColor, outsideColor, edge);
|
||||
fragmentColor = vec4(
|
||||
antialiasedColor,
|
||||
mix(rgbaColorAtPosition.a, backgroundColor.a, step(0.0, startingDistance))
|
||||
rgbaColorAtPosition.a
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue