aboutsummaryrefslogtreecommitdiff
path: root/Assets/Shaders
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Shaders')
-rw-r--r--Assets/Shaders/EquirectToCubemap.glsl33
-rw-r--r--Assets/Shaders/Geodesic.glsl12
-rw-r--r--Assets/Shaders/Skybox.glsl31
-rw-r--r--Assets/Shaders/Sphere.glsl7
4 files changed, 81 insertions, 2 deletions
diff --git a/Assets/Shaders/EquirectToCubemap.glsl b/Assets/Shaders/EquirectToCubemap.glsl
new file mode 100644
index 0000000..2b99c9b
--- /dev/null
+++ b/Assets/Shaders/EquirectToCubemap.glsl
@@ -0,0 +1,33 @@
+#type vertex
+
+#version 330 core
+layout (location = 0) in vec3 aPos;
+out vec3 WorldPos;
+uniform mat4 projection;
+uniform mat4 view;
+void main()
+{
+ WorldPos = aPos;
+ gl_Position = projection * view * vec4(WorldPos, 1.0);
+}
+
+#type fragment
+
+#version 330 core
+out vec4 FragColor;
+in vec3 WorldPos;
+uniform sampler2D equirectangularMap;
+const vec2 invAtan = vec2(0.1591, 0.3183);
+vec2 SampleSphericalMap(vec3 v)
+{
+ vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
+ uv *= invAtan;
+ uv += 0.5;
+ return uv;
+}
+void main()
+{
+ vec2 uv = SampleSphericalMap(normalize(WorldPos));
+ vec3 color = texture(equirectangularMap, uv).rgb;
+ FragColor = vec4(color, 1.0);
+}
diff --git a/Assets/Shaders/Geodesic.glsl b/Assets/Shaders/Geodesic.glsl
index 1799601..29f7b1c 100644
--- a/Assets/Shaders/Geodesic.glsl
+++ b/Assets/Shaders/Geodesic.glsl
@@ -2,6 +2,7 @@
layout(local_size_x = 16, local_size_y = 16) in;
layout(binding = 0, rgba8) writeonly uniform image2D outImage;
+layout(binding = 5) uniform samplerCube u_HDRIEnvironment;
layout(std140, binding = 1) uniform Camera
{
vec3 camPos; float _pad0;
@@ -55,6 +56,11 @@ vec4 objectColor = vec4(0.0);
vec3 hitCenter = vec3(0.0);
float hitRadius = 0.0;
+vec3 SampleHDRI(vec3 direction)
+{
+ return texture(u_HDRIEnvironment, direction).rgb;
+}
+
float hash(float p)
{
p = fract(p * 0.1031);
@@ -472,7 +478,11 @@ void main()
color = vec4(shaded, objectColor.a);
color = mix(accumulatedColor, color, color.a);
} else
- color = accumulatedColor;
+ {
+ vec3 rayDirection = normalize(vec3(ray.x, ray.y, ray.z) - cam.camPos);
+ vec3 hdriColor = SampleHDRI(rayDirection);
+ color = vec4(mix(accumulatedColor.rgb, hdriColor, 1.0 - accumulatedColor.a), 1.0);
+ }
imageStore(outImage, pix, color);
} \ No newline at end of file
diff --git a/Assets/Shaders/Skybox.glsl b/Assets/Shaders/Skybox.glsl
new file mode 100644
index 0000000..654bed1
--- /dev/null
+++ b/Assets/Shaders/Skybox.glsl
@@ -0,0 +1,31 @@
+#type vertex
+
+#version 330 core
+
+layout (location = 0) in vec3 aPos;
+
+out vec3 TexCoords;
+
+uniform mat4 u_Projection;
+uniform mat4 u_View;
+
+void main()
+{
+ TexCoords = aPos;
+ vec4 pos = u_Projection * u_View * vec4(aPos, 1.0);
+ gl_Position = pos.xyww;
+}
+
+#type fragment
+
+#version 330 core
+
+out vec4 FragColor;
+in vec3 TexCoords;
+
+uniform samplerCube u_Skybox;
+
+void main()
+{
+ FragColor = texture(u_Skybox, TexCoords);
+}
diff --git a/Assets/Shaders/Sphere.glsl b/Assets/Shaders/Sphere.glsl
index 23e8f54..9f620f7 100644
--- a/Assets/Shaders/Sphere.glsl
+++ b/Assets/Shaders/Sphere.glsl
@@ -33,6 +33,7 @@ uniform vec3 u_CameraPos;
uniform int u_IsSelected;
uniform vec3 u_OutlineColor;
uniform float u_OutlineWidth;
+uniform samplerCube u_HDRIEnvironment;
out vec4 o_FragColor;
@@ -43,10 +44,14 @@ void main()
vec3 viewDir = normalize(u_CameraPos - v_WorldPos);
vec3 reflectDir = reflect(-lightDir, normal);
+ // HDRI lighting
+ vec3 hdriLight = texture(u_HDRIEnvironment, normal).rgb;
+ float hdriIntensity = 0.3; // Adjust this for HDRI lighting strength
+
float diff = max(dot(normal, lightDir), 0.0);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32.0);
- vec3 diffuse = u_Color * diff;
+ vec3 diffuse = u_Color * (diff + hdriIntensity * hdriLight);
vec3 specular = vec3(u_Specular) * spec;
vec3 emission = u_Color * u_Emission;