summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-12-17 12:14:35 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-12-17 12:14:35 +0000
commitcbc94ed8572cd4ea4e22ad5437b54eea055235d9 (patch)
tree8fe8d0016124f7e4fa19a72a6fe6c9ea48b6ab2c
parentUse a separate framebuffer for illumination phase (diff)
downloadilt-cbc94ed8572cd4ea4e22ad5437b54eea055235d9.tar.bz2
ilt-cbc94ed8572cd4ea4e22ad5437b54eea055235d9.tar.xz
ilt-cbc94ed8572cd4ea4e22ad5437b54eea055235d9.zip
Use 32bit integer texture for position render data
-rw-r--r--gfx/gl/sceneRenderer.cpp2
-rw-r--r--gfx/gl/shaders/directionalLight.fs6
-rw-r--r--gfx/gl/shaders/landmass.fs2
-rw-r--r--gfx/gl/shaders/material.fs2
-rw-r--r--gfx/gl/shaders/materialOut.glsl2
-rw-r--r--gfx/gl/shaders/pointLight.fs2
-rw-r--r--gfx/gl/shaders/spotLight.fs2
-rw-r--r--gfx/gl/shaders/water.fs2
-rw-r--r--test/test-render.cpp2
9 files changed, 11 insertions, 11 deletions
diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp
index b88fb71..2854dea 100644
--- a/gfx/gl/sceneRenderer.cpp
+++ b/gfx/gl/sceneRenderer.cpp
@@ -38,7 +38,7 @@ SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o) :
};
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
- configuregdata(gPosition, {GL_RGB32F}, GL_RGB, GL_COLOR_ATTACHMENT0);
+ configuregdata(gPosition, {GL_RGB32I}, GL_RGB_INTEGER, GL_COLOR_ATTACHMENT0);
configuregdata(gNormal, {GL_RGB8_SNORM, GL_RGB16F}, GL_RGB, GL_COLOR_ATTACHMENT1);
configuregdata(gAlbedoSpec, {GL_RGB8}, GL_RGB, GL_COLOR_ATTACHMENT2);
constexpr std::array<unsigned int, 3> attachments {
diff --git a/gfx/gl/shaders/directionalLight.fs b/gfx/gl/shaders/directionalLight.fs
index ca10ef5..3756db7 100644
--- a/gfx/gl/shaders/directionalLight.fs
+++ b/gfx/gl/shaders/directionalLight.fs
@@ -7,7 +7,7 @@ out vec3 FragColor;
in vec2 TexCoords;
-layout(binding = 0) uniform sampler2D gPosition;
+layout(binding = 0) uniform isampler2D gPosition;
layout(binding = 1) uniform sampler2D gNormal;
layout(binding = 2) uniform sampler2D shadowMap;
@@ -27,7 +27,7 @@ insideShadowCube(vec3 v)
}
float
-isShaded(vec3 Position)
+isShaded(ivec3 Position)
{
for (uint m = 0u; m < lightViewProjectionCount; m++) {
vec3 PositionInLightSpace = (lightViewProjection[m] * vec4(Position, 1.0f)).xyz;
@@ -44,7 +44,7 @@ isShaded(vec3 Position)
void
main()
{
- const vec3 Position = texture(gPosition, TexCoords).xyz;
+ const ivec3 Position = texture(gPosition, TexCoords).xyz;
const vec3 Normal = texture(gNormal, TexCoords).rgb;
const float shaded = isShaded(Position);
FragColor = (1 - shaded) * max(dot(-lightDirection, Normal) * lightColour, 0);
diff --git a/gfx/gl/shaders/landmass.fs b/gfx/gl/shaders/landmass.fs
index 9865d11..fc43bf2 100644
--- a/gfx/gl/shaders/landmass.fs
+++ b/gfx/gl/shaders/landmass.fs
@@ -60,7 +60,7 @@ main()
}
}
- gPosition = vec4(FragPos, 1);
+ gPosition = ivec4(FragPos, 1);
gNormal = vec4(Normal, 1);
gAlbedoSpec = vec4(color, 1);
}
diff --git a/gfx/gl/shaders/material.fs b/gfx/gl/shaders/material.fs
index 20fa8ab..5b93707 100644
--- a/gfx/gl/shaders/material.fs
+++ b/gfx/gl/shaders/material.fs
@@ -42,7 +42,7 @@ main()
{
vec4 textureColour = getTextureColour(Material, TexCoords);
float opaque = step(0.5, mix(textureColour.a, 1, Colour.a));
- gPosition = vec4(FragPos, opaque);
+ gPosition = ivec4(FragPos, opaque);
gNormal = vec4(Normal, opaque);
gl_FragDepth = mix(1.0, gl_FragCoord.z, opaque);
gAlbedoSpec = mix(textureColour, vec4(Colour.rgb, 1), Colour.a);
diff --git a/gfx/gl/shaders/materialOut.glsl b/gfx/gl/shaders/materialOut.glsl
index dc5f8e8..846825e 100644
--- a/gfx/gl/shaders/materialOut.glsl
+++ b/gfx/gl/shaders/materialOut.glsl
@@ -1,3 +1,3 @@
-layout(location = 0) out vec4 gPosition;
+layout(location = 0) out ivec4 gPosition;
layout(location = 1) out vec4 gNormal;
layout(location = 2) out vec4 gAlbedoSpec;
diff --git a/gfx/gl/shaders/pointLight.fs b/gfx/gl/shaders/pointLight.fs
index 1a68df8..ba327b6 100644
--- a/gfx/gl/shaders/pointLight.fs
+++ b/gfx/gl/shaders/pointLight.fs
@@ -3,7 +3,7 @@
out vec3 FragColor;
-layout(binding = 0) uniform sampler2D gPosition;
+layout(binding = 0) uniform isampler2D gPosition;
layout(binding = 1) uniform sampler2D gNormal;
uniform ivec4 viewPort;
uniform vec3 colour;
diff --git a/gfx/gl/shaders/spotLight.fs b/gfx/gl/shaders/spotLight.fs
index 78b8f72..937f922 100644
--- a/gfx/gl/shaders/spotLight.fs
+++ b/gfx/gl/shaders/spotLight.fs
@@ -3,7 +3,7 @@
out vec3 FragColor;
-layout(binding = 0) uniform sampler2D gPosition;
+layout(binding = 0) uniform isampler2D gPosition;
layout(binding = 1) uniform sampler2D gNormal;
uniform ivec4 viewPort;
uniform vec3 colour;
diff --git a/gfx/gl/shaders/water.fs b/gfx/gl/shaders/water.fs
index 2ccc924..a0daa17 100644
--- a/gfx/gl/shaders/water.fs
+++ b/gfx/gl/shaders/water.fs
@@ -10,7 +10,7 @@ uniform vec3 waves;
void
main()
{
- gPosition = vec4(FragPos, 1);
+ gPosition = ivec4(FragPos, 1);
gNormal = vec4(Normal, 1);
gAlbedoSpec = texture(texture0, TexCoords);
gAlbedoSpec.a *= clamp(-FragPos.z * .0007, .1, 1.0);
diff --git a/test/test-render.cpp b/test/test-render.cpp
index e2797a4..66b4d46 100644
--- a/test/test-render.cpp
+++ b/test/test-render.cpp
@@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE(basic)
{
std::filesystem::create_directories(prefix);
Texture::save(gAlbedoSpec, (prefix / "albedo.tga").c_str());
- Texture::save(gPosition, (prefix / "position.tga").c_str());
+ Texture::savePosition(gPosition, (prefix / "position.tga").c_str());
Texture::saveNormal(gNormal, (prefix / "normal.tga").c_str());
Texture::save(gIllumination, (prefix / "illumination.tga").c_str());
}