Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snow Cover and mouse picking fix #67

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gl_engine/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "nucleus/timing/TimerManager.h"
#include "nucleus/timing/TimerInterface.h"
#include "nucleus/timing/CpuTimer.h"
#include "nucleus/utils/bit_coding.h"
#if (defined(__linux) && !defined(__ANDROID__)) || defined(_WIN32) || defined(_WIN64)
#include "GpuAsyncQueryTimer.h"
#endif
Expand Down Expand Up @@ -120,7 +121,7 @@ void Window::initialise_gpu()
TextureDefinition{ Framebuffer::ColourFormat::RGB8 }, // Albedo
TextureDefinition{ Framebuffer::ColourFormat::RGBA32F }, // Position WCS and distance (distance is optional, but i use it directly for a little speed improvement)
TextureDefinition{ Framebuffer::ColourFormat::RG16UI }, // Octahedron Normals
TextureDefinition{ Framebuffer::ColourFormat::R32UI } // Discretized Encoded Depth for readback IMPORTANT: IF YOU MOVE THIS YOU HAVE TO ADAPT THE GET DEPTH FUNCTION
TextureDefinition{ Framebuffer::ColourFormat::RGBA8 } // Discretized Encoded Depth for readback IMPORTANT: IF YOU MOVE THIS YOU HAVE TO ADAPT THE GET DEPTH FUNCTION
});

m_atmospherebuffer = std::make_unique<Framebuffer>(Framebuffer::DepthFormat::None, std::vector{ TextureDefinition{Framebuffer::ColourFormat::RGBA8} });
Expand Down Expand Up @@ -440,9 +441,8 @@ void Window::update_gpu_quads(const std::vector<nucleus::tile_scheduler::tile_ty

float Window::depth(const glm::dvec2& normalised_device_coordinates)
{
uint32_t fakeNormalizedDepth;
m_gbuffer->read_colour_attachment_pixel(3, normalised_device_coordinates, &fakeNormalizedDepth);
const auto depth = float(std::exp(double(fakeNormalizedDepth) / 4294967295.0 * 13.0));
const auto read_float = nucleus::utils::bit_coding::to_f16f16(m_gbuffer->read_colour_attachment_pixel(3, normalised_device_coordinates))[0];
const auto depth = std::exp(read_float * 13.f);
return depth;
}

Expand Down
14 changes: 6 additions & 8 deletions gl_engine/shaders/encoder.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
highp float fakeNormalizeWSDepth(highp float depth) {
return log(depth) / 13.0;
}
highp float fakeUnNormalizeWSDepth(highp float ndepth) {
return exp(13.0 * ndepth);
}
highp uint depthWSEncode1u32(highp float depth) {
return uint(fakeNormalizeWSDepth(depth) * 4294967295.0);
}
highp float depthWSDecode1u32(highp uint depth32) {
return fakeUnNormalizeWSDepth(float(depth32) / 4294967295.0);
lowp vec2 depthWSEncode2n8(highp float depth) {
highp float value = fakeNormalizeWSDepth(depth);
mediump uint scaled = uint(value * 65535.f + 0.5f);
mediump uint r = scaled >> 8u;
mediump uint b = scaled & 255u;
return vec2(float(r) / 255.f, float(b) / 255.f);
}

// ===== OCTAHEDRON MAPPING FOR NORMALS =====
Expand Down
32 changes: 16 additions & 16 deletions gl_engine/shaders/snow.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@
#define ORIGIN_SHIFT 20037508.3427892430765884
#define PI 3.1415926535897932384626433

mediump float mod289(mediump float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
mediump vec4 mod289(mediump vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
mediump vec4 perm(mediump vec4 x) { return mod289(((x * 34.0) + 1.0) * x); }
highp float mod289(highp float x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
highp vec4 mod289(highp vec4 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
highp vec4 perm(highp vec4 x) { return mod289(((x * 34.0) + 1.0) * x); }

mediump float noise(mediump vec3 p){
mediump vec3 a = floor(p);
mediump vec3 d = p - a;
highp float noise(highp vec3 p){
highp vec3 a = floor(p);
highp vec3 d = p - a;
d = d * d * (3.0 - 2.0 * d);
mediump vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0);
mediump vec4 k1 = perm(b.xyxy);
mediump vec4 k2 = perm(k1.xyxy + b.zzww);
mediump vec4 c = k2 + a.zzzz;
mediump vec4 k3 = perm(c);
mediump vec4 k4 = perm(c + 1.0);
mediump vec4 o1 = fract(k3 * (1.0 / 41.0));
mediump vec4 o2 = fract(k4 * (1.0 / 41.0));
mediump vec4 o3 = o2 * d.z + o1 * (1.0 - d.z);
mediump vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x);
highp vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0);
highp vec4 k1 = perm(b.xyxy);
highp vec4 k2 = perm(k1.xyxy + b.zzww);
highp vec4 c = k2 + a.zzzz;
highp vec4 k3 = perm(c);
highp vec4 k4 = perm(c + 1.0);
highp vec4 o1 = fract(k3 * (1.0 / 41.0));
highp vec4 o2 = fract(k4 * (1.0 / 41.0));
highp vec4 o3 = o2 * d.z + o1 * (1.0 - d.z);
highp vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x);
return o4.y * d.y + o4.x * (1.0 - d.y);
}

Expand Down
4 changes: 2 additions & 2 deletions gl_engine/shaders/tile.frag
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ uniform sampler2D texture_sampler;
layout (location = 0) out lowp vec3 texout_albedo;
layout (location = 1) out highp vec4 texout_position;
layout (location = 2) out highp uvec2 texout_normal;
layout (location = 3) out highp uint texout_depth;
layout (location = 3) out lowp vec4 texout_depth;

in highp vec2 uv;
in highp vec3 var_pos_cws;
Expand Down Expand Up @@ -69,7 +69,7 @@ void main() {
texout_normal = octNormalEncode2u16(normal);

// Write and encode distance for readback
texout_depth = depthWSEncode1u32(dist);
texout_depth = vec4(depthWSEncode2n8(dist), 0.0, 0.0);

// HANDLE OVERLAYS (and mix it with the albedo color) THAT CAN JUST BE DONE IN THIS STAGE
// (because of DATA thats not forwarded)
Expand Down