palette postprocess
This commit is contained in:
BIN
assets/gfx/blood-crow-1x.png
Normal file
BIN
assets/gfx/blood-crow-1x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 82 B |
BIN
assets/gfx/blood-crow-8x.png
Normal file
BIN
assets/gfx/blood-crow-8x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 111 B |
BIN
assets/gfx/buddy.png
Normal file
BIN
assets/gfx/buddy.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 512 B |
67
assets/shaders/fshader.glsl
Normal file
67
assets/shaders/fshader.glsl
Normal file
@ -0,0 +1,67 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec3 fragPosition;
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
in vec3 fragNormal;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
// Output fragment color
|
||||
out vec4 finalColor;
|
||||
|
||||
#define MAX_LIGHTS 12
|
||||
|
||||
struct Light {
|
||||
int enabled;
|
||||
float distanceNear;
|
||||
float distanceFar;
|
||||
float power;
|
||||
vec3 position;
|
||||
vec4 color;
|
||||
};
|
||||
|
||||
uniform Light lights[MAX_LIGHTS];
|
||||
uniform vec4 ambient;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
if (texelColor.a == 0.0) discard;
|
||||
if (fragColor.b < 1.0) {
|
||||
finalColor = vec4(1.0, 1.0, 1.0, 1.0);
|
||||
} else {
|
||||
vec3 lightDot = vec3(0.0);
|
||||
vec4 tint = colDiffuse * fragColor;
|
||||
vec3 normal = normalize(fragNormal);
|
||||
|
||||
for (int i = 0; i < MAX_LIGHTS; i++) {
|
||||
if (lights[i].enabled == 1) {
|
||||
vec3 light = vec3(0.0);
|
||||
|
||||
light = normalize(lights[i].position - fragPosition);
|
||||
|
||||
float dist = distance(lights[i].position, fragPosition);
|
||||
|
||||
float power = smoothstep(lights[i].distanceFar, lights[i].distanceNear, dist);
|
||||
// float far = smoothstep(30.0, 1.0, dist) / 3.0;
|
||||
// float power = near + far * far * far;
|
||||
power = power * power;
|
||||
float NdotL = max(dot(normal, light), 0.0);
|
||||
// lightDot += lights[i].color.rgb * light * NdotL;
|
||||
// lightDot += lights[i].color.rgb * power * NdotL;
|
||||
lightDot += lights[i].color.rgb * power * lights[i].power;
|
||||
|
||||
}
|
||||
}
|
||||
finalColor.rgb = (texelColor.rgb * lightDot);
|
||||
// finalColor.rgb = normal;
|
||||
// finalColor = (texelColor * vec4(lightDot, 1.0));
|
||||
// finalColor = pow(finalColor, vec4(1.0/2.2));
|
||||
// finalColor.rgb = fragPosition;
|
||||
}
|
||||
}
|
30
assets/shaders/postprocess.glsl
Normal file
30
assets/shaders/postprocess.glsl
Normal file
@ -0,0 +1,30 @@
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes (from vertex shader)
|
||||
in vec3 fragPosition;
|
||||
in vec2 fragTexCoord;
|
||||
in vec4 fragColor;
|
||||
in vec3 fragNormal;
|
||||
|
||||
// Input uniform values
|
||||
uniform sampler2D texture0;
|
||||
uniform sampler2D texture1;
|
||||
uniform vec4 colDiffuse;
|
||||
|
||||
#define POSTERIZE 5.0
|
||||
|
||||
out vec4 finalColor;
|
||||
|
||||
void main() {
|
||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||
float grey = 0.21 * texelColor.r + 0.71 * texelColor.g + 0.07 * texelColor.b ;
|
||||
vec2 paluv = vec2(grey, 0.5);
|
||||
vec4 paletteValue = texture(texture1, paluv);
|
||||
|
||||
finalColor.a = 1.0;
|
||||
// finalColor.rgb = floor(texelColor.rgb * POSTERIZE) / POSTERIZE;
|
||||
|
||||
finalColor.rgb = paletteValue.rgb;
|
||||
//
|
||||
// finalColor.rgb = vec3(mean) + paletteValue.rgb;
|
||||
}
|
35
assets/shaders/vshader.glsl
Normal file
35
assets/shaders/vshader.glsl
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
|
||||
#version 330
|
||||
|
||||
// Input vertex attributes
|
||||
in vec3 vertexPosition;
|
||||
in vec2 vertexTexCoord;
|
||||
in vec3 vertexNormal;
|
||||
in vec4 vertexColor;
|
||||
|
||||
// Input uniform values
|
||||
uniform mat4 mvp;
|
||||
uniform mat4 matModel;
|
||||
uniform mat4 matNormal;
|
||||
|
||||
// Output vertex attributes (to fragment shader)
|
||||
out vec3 fragPosition;
|
||||
out vec2 fragTexCoord;
|
||||
out vec4 fragColor;
|
||||
out vec3 fragNormal;
|
||||
|
||||
// NOTE: Add your custom variables here
|
||||
|
||||
void main()
|
||||
{
|
||||
// Send vertex attributes to fragment shader
|
||||
fragPosition = vec3(matModel*vec4(vertexPosition, 1.0));
|
||||
// fragPosition = vertexPosition;
|
||||
fragTexCoord = vertexTexCoord;
|
||||
fragColor = vertexColor;
|
||||
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
|
||||
|
||||
// Calculate final vertex position
|
||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||
}
|
Reference in New Issue
Block a user