mirror of
https://github.com/johndoe6345789/SDL3CPlusPlus.git
synced 2026-04-24 13:44:58 +00:00
feat: Add rainbow color effect to fragment shader and update vertex shader to pass world position
This commit is contained in:
@@ -1,8 +1,48 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 fragColor;
|
||||
layout(location = 1) in vec3 fragWorldPos;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(fragColor, 1.0);
|
||||
vec3 RainbowBand(float t) {
|
||||
t = clamp(t, 0.0, 1.0);
|
||||
float scaled = t * 5.0;
|
||||
int index = int(floor(scaled));
|
||||
float blend = fract(scaled);
|
||||
|
||||
vec3 red = vec3(0.91, 0.19, 0.21);
|
||||
vec3 orange = vec3(0.99, 0.49, 0.09);
|
||||
vec3 yellow = vec3(0.99, 0.86, 0.22);
|
||||
vec3 green = vec3(0.16, 0.74, 0.39);
|
||||
vec3 blue = vec3(0.24, 0.48, 0.88);
|
||||
vec3 purple = vec3(0.56, 0.25, 0.75);
|
||||
|
||||
vec3 a = red;
|
||||
vec3 b = orange;
|
||||
if (index == 1) {
|
||||
a = orange;
|
||||
b = yellow;
|
||||
} else if (index == 2) {
|
||||
a = yellow;
|
||||
b = green;
|
||||
} else if (index == 3) {
|
||||
a = green;
|
||||
b = blue;
|
||||
} else if (index == 4) {
|
||||
a = blue;
|
||||
b = purple;
|
||||
} else if (index >= 5) {
|
||||
a = purple;
|
||||
b = purple;
|
||||
}
|
||||
|
||||
return mix(a, b, blend);
|
||||
}
|
||||
|
||||
void main() {
|
||||
float bandPos = (fragWorldPos.y + 1.0) * 0.5;
|
||||
float diagonal = (fragWorldPos.x + fragWorldPos.z) * 0.15;
|
||||
vec3 rainbow = RainbowBand(bandPos + diagonal);
|
||||
vec3 shaded = mix(rainbow, fragColor, 0.08);
|
||||
outColor = vec4(shaded, 1.0);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -4,6 +4,7 @@ layout(location = 0) in vec3 inPos;
|
||||
layout(location = 1) in vec3 inColor;
|
||||
|
||||
layout(location = 0) out vec3 fragColor;
|
||||
layout(location = 1) out vec3 fragWorldPos;
|
||||
|
||||
layout(push_constant) uniform PushConstants {
|
||||
mat4 model;
|
||||
@@ -12,5 +13,7 @@ layout(push_constant) uniform PushConstants {
|
||||
|
||||
void main() {
|
||||
fragColor = inColor;
|
||||
gl_Position = pushConstants.viewProj * pushConstants.model * vec4(inPos, 1.0);
|
||||
vec4 worldPos = pushConstants.model * vec4(inPos, 1.0);
|
||||
fragWorldPos = worldPos.xyz;
|
||||
gl_Position = pushConstants.viewProj * worldPos;
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user