diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-03-10 01:33:39 +0000 |
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-03-10 01:33:39 +0000 |
| commit | 61d6b49d5a4c5f58a2922a19a360e078a0aeacba (patch) | |
| tree | c192508c15d880ccb84003f3494aa2e26d36324b | |
| parent | Specialise glTexture::savePosition (diff) | |
| download | ilt-61d6b49d5a4c5f58a2922a19a360e078a0aeacba.tar.bz2 ilt-61d6b49d5a4c5f58a2922a19a360e078a0aeacba.tar.xz ilt-61d6b49d5a4c5f58a2922a19a360e078a0aeacba.zip | |
Switch to floating point, camera relative position buffer
| -rw-r--r-- | gfx/gl/glTexture.cpp | 15 | ||||
| -rw-r--r-- | gfx/gl/sceneRenderer.cpp | 9 | ||||
| -rw-r--r-- | gfx/gl/sceneRenderer.h | 4 | ||||
| -rw-r--r-- | gfx/gl/shaders/billboard.frag | 2 | ||||
| -rw-r--r-- | gfx/gl/shaders/billboard.vert | 6 | ||||
| -rw-r--r-- | gfx/gl/shaders/commonPoint.glsl | 4 | ||||
| -rw-r--r-- | gfx/gl/shaders/directionalLight.frag | 5 | ||||
| -rw-r--r-- | gfx/gl/shaders/landmass.frag | 2 | ||||
| -rw-r--r-- | gfx/gl/shaders/materialOut.glsl | 2 | ||||
| -rw-r--r-- | gfx/gl/shaders/network.frag | 3 | ||||
| -rw-r--r-- | gfx/gl/shaders/pointLight.frag | 2 | ||||
| -rw-r--r-- | gfx/gl/shaders/pointLight.vert | 4 | ||||
| -rw-r--r-- | gfx/gl/shaders/spotLight.frag | 2 | ||||
| -rw-r--r-- | gfx/gl/shaders/spotLight.vert | 4 | ||||
| -rw-r--r-- | gfx/gl/shaders/water.frag | 6 | ||||
| -rw-r--r-- | gfx/gl/shaders/water.vert | 6 |
16 files changed, 35 insertions, 41 deletions
diff --git a/gfx/gl/glTexture.cpp b/gfx/gl/glTexture.cpp index 0bc3d62..51a27ed 100644 --- a/gfx/gl/glTexture.cpp +++ b/gfx/gl/glTexture.cpp @@ -159,18 +159,17 @@ Impl::glTextureDims<Dims>::savePosition(const char * path) const .size = {size.x, (area / static_cast<size_t>(size.x))}, }; glPixelStorei(GL_PACK_ALIGNMENT, 1); - std::vector<GlobalPosition3D> raw {area}; - glGetTextureImage( - name, 0, GL_BGR_INTEGER, GL_INT, static_cast<GLsizei>(sizeof(GlobalPosition3D) * area), raw.data()); - using Comp = GlobalPosition3D (*)(const GlobalPosition3D &, const GlobalPosition3D &); - auto notZero = std::views::filter([](const GlobalPosition3D & pos) { - return pos != GlobalPosition3D {}; + std::vector<RelativePosition3D> raw {area}; + glGetTextureImage(name, 0, GL_BGR, GL_FLOAT, static_cast<GLsizei>(sizeof(GlobalPosition3D) * area), raw.data()); + using Comp = RelativePosition3D (*)(const RelativePosition3D &, const RelativePosition3D &); + auto notZero = std::views::filter([](const RelativePosition3D & pos) { + return pos != RelativePosition3D {}; }); const auto minPos = *std::ranges::fold_left_first(raw | notZero, static_cast<Comp>(&glm::min)); const auto maxPos = *std::ranges::fold_left_first(raw | notZero, static_cast<Comp>(&glm::max)); const auto rangePos = difference(maxPos, minPos); - std::ranges::transform(raw, outTga->data, [minPos, rangePos](const GlobalPosition3D & pos) { - return GlobalPosition3D(255.F * (difference(pos, minPos) / rangePos)); + std::ranges::transform(raw, outTga->data, [minPos, rangePos](const auto & pos) { + return 255.F * ((pos - minPos) / rangePos); }); tga.msync(MS_ASYNC); } diff --git a/gfx/gl/sceneRenderer.cpp b/gfx/gl/sceneRenderer.cpp index 343321f..57802fa 100644 --- a/gfx/gl/sceneRenderer.cpp +++ b/gfx/gl/sceneRenderer.cpp @@ -31,7 +31,7 @@ SceneRenderer::SceneRenderer(ScreenAbsCoord s, GLuint o, glDebugScope) : }; glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); - configuregdata(gPosition, GL_RGB32I, GL_COLOR_ATTACHMENT0); + configuregdata(gPosition, GL_RGB32F, GL_COLOR_ATTACHMENT0); configuregdata(gNormal, GL_RGB8_SNORM, GL_COLOR_ATTACHMENT1); configuregdata(gAlbedoSpec, GL_RGB8, GL_COLOR_ATTACHMENT2); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { @@ -68,7 +68,7 @@ SceneRenderer::resize(ScreenAbsCoord newSize) glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, data, 0); }; glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); - configuregdata(gPosition, GL_RGB32I, GL_COLOR_ATTACHMENT0); + configuregdata(gPosition, GL_RGB32F, GL_COLOR_ATTACHMENT0); configuregdata(gNormal, GL_RGB8_SNORM, GL_COLOR_ATTACHMENT1); configuregdata(gAlbedoSpec, GL_RGB8, GL_COLOR_ATTACHMENT2); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, size.x, size.y); @@ -174,7 +174,7 @@ SceneRenderer::setDirectionalLight( shadowMapper.bind(2); glViewport(0, 0, size.x, size.y); dirLight.use(); - dirLight.setDirectionalLight(colour, direction.vector(), camera.getPosition(), lvp); + dirLight.setDirectionalLight(colour, direction.vector(), lvp); renderQuad(); } } @@ -194,14 +194,13 @@ const auto toTextureSpaceMat = glm::translate(glm::identity<glm::mat4>(), glm::v void SceneRenderer::DirectionalLightProgram::setDirectionalLight( - const RGB & c, const Direction3D & d, const GlobalPosition3D & p, const std::span<const glm::mat4x4> lvp) const + const RGB & c, const Direction3D & d, const std::span<const glm::mat4x4> lvp) const { const auto toTextureSpace = [](const glm::mat4 & m) { return toTextureSpaceMat * m; }; glUniform(colourLoc, c); glUniform(directionLoc, d); - glUniform(lightPointLoc, p); glUniform(lightViewProjectionCountLoc, static_cast<GLuint>(lvp.size())); glUniform(lightViewProjectionLoc, std::span<const glm::mat4> {lvp * toTextureSpace}); } diff --git a/gfx/gl/sceneRenderer.h b/gfx/gl/sceneRenderer.h index e9cafb4..3de6000 100644 --- a/gfx/gl/sceneRenderer.h +++ b/gfx/gl/sceneRenderer.h @@ -45,13 +45,11 @@ protected: DirectionalLightProgram(); using Program::use; - void setDirectionalLight( - const RGB &, const Direction3D &, const GlobalPosition3D &, const std::span<const glm::mat4x4>) const; + void setDirectionalLight(const RGB &, const Direction3D &, const std::span<const glm::mat4x4>) const; private: RequiredUniformLocation directionLoc {*this, "lightDirection"}; RequiredUniformLocation colourLoc {*this, "lightColour"}; - RequiredUniformLocation lightPointLoc {*this, "lightPoint"}; RequiredUniformLocation lightViewProjectionLoc {*this, "lightViewProjection"}; RequiredUniformLocation lightViewProjectionCountLoc {*this, "lightViewProjectionCount"}; }; diff --git a/gfx/gl/shaders/billboard.frag b/gfx/gl/shaders/billboard.frag index 1e2c4ae..7864c79 100644 --- a/gfx/gl/shaders/billboard.frag +++ b/gfx/gl/shaders/billboard.frag @@ -10,7 +10,7 @@ uniform float size; include(`materialOut.glsl') -flat in ivec3 ModelPos; +flat in vec3 ModelPos; flat in float Yaw; flat in float Depth; diff --git a/gfx/gl/shaders/billboard.vert b/gfx/gl/shaders/billboard.vert index 2d73084..faf8b19 100644 --- a/gfx/gl/shaders/billboard.vert +++ b/gfx/gl/shaders/billboard.vert @@ -8,16 +8,16 @@ uniform float size; layout(location = 0) in ivec3 modelPos; layout(location = 1) in float yaw; -flat out ivec3 ModelPos; +flat out vec3 ModelPos; flat out float Yaw; flat out float Depth; void main() { - ModelPos = modelPos; + ModelPos = modelPos - viewPoint; Yaw = yaw; - gl_Position = viewProjection * vec4(modelPos - viewPoint + centre, 1); + gl_Position = viewProjection * vec4(ModelPos + centre, 1); Depth = gl_Position.w; gl_PointSize = (viewPort.w * size * 2) / gl_Position.w; } diff --git a/gfx/gl/shaders/commonPoint.glsl b/gfx/gl/shaders/commonPoint.glsl index dc534d5..9a08321 100644 --- a/gfx/gl/shaders/commonPoint.glsl +++ b/gfx/gl/shaders/commonPoint.glsl @@ -3,11 +3,11 @@ include(`getMaterialDetail.glsl') void main() { - FragPos = (model * position) + modelPos; + FragPos = (model * position) + modelPos - viewPoint; TexCoords = texCoord; Normal = (model * normal); Colour = colour; Material = getMaterialDetail(material); - gl_Position = viewProjection * vec4(FragPos - viewPoint, 1); + gl_Position = viewProjection * vec4(FragPos, 1); } diff --git a/gfx/gl/shaders/directionalLight.frag b/gfx/gl/shaders/directionalLight.frag index e5ebfb0..5da1acd 100644 --- a/gfx/gl/shaders/directionalLight.frag +++ b/gfx/gl/shaders/directionalLight.frag @@ -6,13 +6,12 @@ out vec3 FragColor; in vec2 TexCoords; -layout(binding = 0) uniform isampler2D gPosition; +layout(binding = 0) uniform sampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; layout(binding = 2) uniform sampler2DArray shadowMap; uniform vec3 lightDirection; uniform vec3 lightColour; -uniform ivec3 lightPoint; uniform mat4 lightViewProjection[MAX_MAPS]; uniform uint lightViewProjectionCount; @@ -53,7 +52,7 @@ isShaded(vec4 Position) void main() { - const vec4 Position = vec4(texture(gPosition, TexCoords).xyz - lightPoint, 1); + const vec4 Position = vec4(texture(gPosition, TexCoords).xyz, 1); const vec3 Normal = texture(gNormal, TexCoords).rgb; const float shaded = isShaded(Position); FragColor = shaded * max(dot(-lightDirection, Normal) * lightColour, 0); diff --git a/gfx/gl/shaders/landmass.frag b/gfx/gl/shaders/landmass.frag index b5c7fa1..d641ecd 100644 --- a/gfx/gl/shaders/landmass.frag +++ b/gfx/gl/shaders/landmass.frag @@ -67,7 +67,7 @@ main() } } - gPosition = ivec4(position, 1); + gPosition = vec4(FragPos, 1); gNormal = vec4(Normal, 1); gAlbedoSpec = vec4(color, 1); } diff --git a/gfx/gl/shaders/materialOut.glsl b/gfx/gl/shaders/materialOut.glsl index 846825e..dc5f8e8 100644 --- a/gfx/gl/shaders/materialOut.glsl +++ b/gfx/gl/shaders/materialOut.glsl @@ -1,3 +1,3 @@ -layout(location = 0) out ivec4 gPosition; +layout(location = 0) out vec4 gPosition; layout(location = 1) out vec4 gNormal; layout(location = 2) out vec4 gAlbedoSpec; diff --git a/gfx/gl/shaders/network.frag b/gfx/gl/shaders/network.frag index 2f291ea..8c62e34 100644 --- a/gfx/gl/shaders/network.frag +++ b/gfx/gl/shaders/network.frag @@ -5,12 +5,11 @@ in vec3 rposition; in vec2 texCoord; layout(binding = 0) uniform sampler2D texture0; -uniform ivec3 viewPoint; void main() { - gPosition = ivec4(viewPoint + rposition, 1); + gPosition = vec4(rposition, 1); gNormal = vec4(0, 0, 1, 1); gAlbedoSpec = texture(texture0, texCoord); } diff --git a/gfx/gl/shaders/pointLight.frag b/gfx/gl/shaders/pointLight.frag index bb2c453..a141592 100644 --- a/gfx/gl/shaders/pointLight.frag +++ b/gfx/gl/shaders/pointLight.frag @@ -2,7 +2,7 @@ out vec3 FragColor; -layout(binding = 0) uniform isampler2D gPosition; +layout(binding = 0) uniform sampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; uniform ivec4 viewPort; flat in vec4 geo_centre; diff --git a/gfx/gl/shaders/pointLight.vert b/gfx/gl/shaders/pointLight.vert index 2fd5418..b8ddecb 100644 --- a/gfx/gl/shaders/pointLight.vert +++ b/gfx/gl/shaders/pointLight.vert @@ -16,9 +16,9 @@ flat out float kq; void main() { - position = modelPos + ivec3(mat3(model) * v_position); + position = (modelPos - viewPoint) + ivec3(mat3(model) * v_position); kq = v_kq; size = (8000 * sqrt(max(max(v_colour.r, v_colour.g), v_colour.b))) / sqrt(v_kq); colour = v_colour; - gl_Position = vec4(position - viewPoint, 0); + gl_Position = vec4(position, 0); } diff --git a/gfx/gl/shaders/spotLight.frag b/gfx/gl/shaders/spotLight.frag index 1305dbd..0241e88 100644 --- a/gfx/gl/shaders/spotLight.frag +++ b/gfx/gl/shaders/spotLight.frag @@ -2,7 +2,7 @@ out vec3 FragColor; -layout(binding = 0) uniform isampler2D gPosition; +layout(binding = 0) uniform sampler2D gPosition; layout(binding = 1) uniform sampler2D gNormal; uniform ivec4 viewPort; flat in vec4 geo_centre; diff --git a/gfx/gl/shaders/spotLight.vert b/gfx/gl/shaders/spotLight.vert index 36d2ee5..83f3859 100644 --- a/gfx/gl/shaders/spotLight.vert +++ b/gfx/gl/shaders/spotLight.vert @@ -20,11 +20,11 @@ flat out float kq; void main() { - position = modelPos + ivec3(mat3(model) * v_position); + position = (modelPos - viewPoint) + ivec3(mat3(model) * v_position); direction = normalize(mat3(model) * v_direction); colour = v_colour; kq = v_kq; size = (8000 * sqrt(max(max(colour.r, colour.g), colour.b))) / sqrt(kq); arc = vec2(cos(v_arc / 2), tan(v_arc / 2)); - gl_Position = vec4(position - viewPoint, 0); + gl_Position = vec4(position, 0); } diff --git a/gfx/gl/shaders/water.frag b/gfx/gl/shaders/water.frag index a09e754..86a8a87 100644 --- a/gfx/gl/shaders/water.frag +++ b/gfx/gl/shaders/water.frag @@ -1,6 +1,6 @@ #version 460 core -in vec3 FragPos; +in vec4 FragPos; in vec2 TexCoords; include(`materialOut.glsl') @@ -9,8 +9,8 @@ uniform sampler2D texture0; void main() { - gPosition = ivec4(FragPos, 1); + gPosition = vec4(FragPos.xyz, 1); gNormal = vec4(0, 0, 1, 1); gAlbedoSpec = texture(texture0, TexCoords); - gAlbedoSpec.a *= clamp(-FragPos.z * .0007, .1, 1.0); + gAlbedoSpec.a *= clamp(-FragPos.w * .0007, .1, 1.0); } diff --git a/gfx/gl/shaders/water.vert b/gfx/gl/shaders/water.vert index 60e4fb8..bb056b8 100644 --- a/gfx/gl/shaders/water.vert +++ b/gfx/gl/shaders/water.vert @@ -1,7 +1,7 @@ #version 460 core layout(location = 0) in ivec3 position; -out vec3 FragPos; +out vec4 FragPos; out vec2 TexCoords; uniform mat4 viewProjection; @@ -14,8 +14,8 @@ main() vec3 wpos = vec3(position.x + (cos(waves) * 1000.0), position.y + (cos(waves * 1.4) * 1000.0), cos(waves + (position.x / 1000000) + (position.y / 8000)) * 300.0); - FragPos = vec3(wpos.xy, position.z); + FragPos = vec4(wpos - viewPoint, position.z); TexCoords = (position.xy / 8192) - (viewPoint.xy / 8192); - gl_Position = viewProjection * vec4(wpos - viewPoint, 1.0); + gl_Position = viewProjection * vec4(FragPos.xyz, 1.0); } |
