diff --git a/shaders/cube.frag b/shaders/cube.frag index 7122ce8..79b4681 100644 --- a/shaders/cube.frag +++ b/shaders/cube.frag @@ -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); } diff --git a/shaders/cube.frag.spv b/shaders/cube.frag.spv index 828f1e5..c004b90 100644 Binary files a/shaders/cube.frag.spv and b/shaders/cube.frag.spv differ diff --git a/shaders/cube.vert b/shaders/cube.vert index aca4e67..39930c3 100644 --- a/shaders/cube.vert +++ b/shaders/cube.vert @@ -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; } diff --git a/shaders/cube.vert.spv b/shaders/cube.vert.spv index 1711635..986dc4b 100644 Binary files a/shaders/cube.vert.spv and b/shaders/cube.vert.spv differ