Skip to content

Commit f35471f

Browse files
committed
Added samppling strategies for raytracing shadows. Upgraded light object
1 parent 345aa19 commit f35471f

File tree

26 files changed

+206
-98
lines changed

26 files changed

+206
-98
lines changed

examples/raytracing/application.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void Application::setup() {
7272
light->set_area_of_effect(20.0f);
7373
light->set_shadow_fov(115.0f);
7474
light->set_shadow_type(ShadowType::RAYTRACED_SHADOW);
75+
light->set_area(0.5f);
7576
light->add_child(lightDummy);
7677
light->set_name("Light");
7778

include/engine/core/scene/light.h

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Light : public Object3D
2121
protected:
2222
Vec3 m_color;
2323
float m_intensity;
24+
float m_area = 0.0; // If ZERO is treated as a VPL (Virtual Point Light)
2425

2526
// Shadow
2627
struct Shadow {
@@ -35,12 +36,14 @@ class Light : public Object3D
3536
bool angleDependableBias = false;
3637
float kernelRadius = 1.0;
3738
int softness = 3;
39+
int raySamples = 4;
3840
};
3941

4042
Shadow m_shadow;
4143
const LightType m_lighType;
4244

4345
public:
46+
4447
Light(std::string name, LightType type, Vec3 color = Vec3(1.0f, 1.0f, 1.0f), float intensity = 1.0f)
4548
: Object3D(name, LIGHT)
4649
, m_color(color)
@@ -121,6 +124,12 @@ class Light : public Object3D
121124
virtual inline void set_shadow_softness(int k) {
122125
m_shadow.softness = k;
123126
}
127+
virtual inline int get_shadow_ray_samples() const {
128+
return m_shadow.raySamples;
129+
}
130+
virtual inline void set_shadow_ray_samples(int rays) {
131+
m_shadow.raySamples = rays;
132+
}
124133

125134
virtual inline bool get_angle_dependant_bias() const {
126135
return m_shadow.angleDependableBias;
@@ -139,6 +148,12 @@ class Light : public Object3D
139148
virtual LightType get_light_type() const {
140149
return m_lighType;
141150
}
151+
virtual inline float get_area() const {
152+
return m_area;
153+
}
154+
virtual inline void set_area(float a) {
155+
m_area = a;
156+
}
142157

143158
virtual Graphics::LightUniforms get_uniforms(Mat4 cameraView) const = 0;
144159
};
@@ -148,15 +163,13 @@ class Light : public Object3D
148163
class PointLight : public Light
149164
{
150165
float m_effectArea;
151-
float m_decaying;
152166

153167
static int m_instanceCount;
154168

155169
public:
156170
PointLight(Vec3 color = Vec3(1.0f, 1.0f, 1.0f), float intensity = 1.0f)
157171
: Light("Point Light #" + std::to_string(PointLight::m_instanceCount), LightType::POINT, color, intensity)
158-
, m_effectArea(12.0f)
159-
, m_decaying(1.0f) {
172+
, m_effectArea(12.0f) {
160173
PointLight::m_instanceCount++;
161174
}
162175

@@ -167,13 +180,6 @@ class PointLight : public Light
167180
m_effectArea = a;
168181
}
169182

170-
inline float get_decaying() const {
171-
return m_decaying;
172-
}
173-
inline void set_decaying(float d) {
174-
m_decaying = d;
175-
}
176-
177183
virtual Graphics::LightUniforms get_uniforms(Mat4 cameraView) const;
178184
};
179185

include/engine/core/textures/texture.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ VULKAN_ENGINE_NAMESPACE_BEGIN
1717
namespace Core {
1818

1919
struct TextureSettings {
20-
ColorFormatType format{SRGBA_8};
21-
TextureFilterType filter{LINEAR};
22-
TextureAdressModeType adressMode{REPEAT};
23-
24-
bool useMipmaps{true};
25-
bool anisotropicFilter{true};
26-
27-
int minMipLevel{0};
28-
int maxMipLevel{-1};
20+
ColorFormatType format = SRGBA_8;
21+
TextureFilterType filter = LINEAR;
22+
TextureAdressModeType adressMode = REPEAT;
23+
bool useMipmaps = true;
24+
bool anisotropicFilter = true;
25+
int minMipLevel = 0;
26+
int maxMipLevel = -1;
2927
};
3028

3129
/*

include/engine/core/textures/textureLDR.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class TextureLDR : public ITexture
2727

2828
public:
2929
static Texture *FALLBACK_TEX;
30+
static Texture *BLUE_NOISE_TEXT;
3031

3132
TextureLDR() : ITexture()
3233
{

include/engine/graphics/uniforms.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ struct CameraUniforms {
2626
};
2727

2828
struct LightUniforms {
29-
29+
3030
Vec4 position = {0.0f, 0.0f, 0.0f, 0.0f}; // w for type
3131
Vec4 color = {0.0f, 0.0f, 0.0f, 0.0f};
3232
Vec4 dataSlot1 = {0.0f, 0.0f, 0.0f, 0.0f};
3333
Mat4 viewProj;
3434
Vec4 dataSlot2 = {0.0f, 0.0f, 0.0f, 0.0f};
35-
3635
};
3736

3837
struct SceneUniforms {
@@ -46,6 +45,7 @@ struct SceneUniforms {
4645
int useIBL;
4746
float envRotation;
4847
float envColorMultiplier;
48+
float time;
4949
};
5050

5151
struct ObjectUniforms {

include/engine/systems/renderers/renderer.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include <engine/common.h>
2222

23+
#include <engine/tools/loaders.h>
24+
2325
#include <engine/core/materials/material.h>
2426
#include <engine/core/renderpasses/irradiance_compute_pass.h>
2527
#include <engine/core/renderpasses/panorama_conversion_pass.h>
@@ -120,9 +122,9 @@ class BaseRenderer
120122
Graphics::Utils::DeletionQueue m_deletionQueue;
121123

122124
// Query
123-
uint32_t m_currentFrame{0};
124-
bool m_initialized{false};
125-
bool m_updateFramebuffers{false};
125+
uint32_t m_currentFrame = 0;
126+
bool m_initialized = false;
127+
bool m_updateFramebuffers = false;
126128

127129
#pragma endregion
128130
public:

resources/shaders/forward/physically_based.glsl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ void main() {
7676
#version 460
7777
#extension GL_EXT_ray_tracing : enable
7878
#extension GL_EXT_ray_query : enable
79+
7980
#include camera.glsl
8081
#include light.glsl
8182
#include scene.glsl
@@ -87,7 +88,7 @@ void main() {
8788
#include IBL.glsl
8889
#include reindhart.glsl
8990
#include BRDFs/schlick_smith_BRDF.glsl
90-
#include raytraced_shadows.glsl
91+
#include raytracing.glsl
9192

9293
//Input
9394
layout(location = 0) in vec3 v_pos;
@@ -102,11 +103,11 @@ layout(location = 6) in mat3 v_TBN;
102103
layout(location = 0) out vec4 outColor;
103104

104105

105-
layout(set = 0, binding = 2) uniform sampler2DArray shadowMap;
106-
layout(set = 0, binding = 4) uniform samplerCube irradianceMap;
107-
layout (set = 0, binding = 5) uniform accelerationStructureEXT TLAS;
108-
109-
106+
//Uniforms
107+
layout(set = 0, binding = 2) uniform sampler2DArray shadowMap;
108+
layout(set = 0, binding = 4) uniform samplerCube irradianceMap;
109+
layout(set = 0, binding = 5) uniform accelerationStructureEXT TLAS;
110+
layout(set = 0, binding = 6) uniform sampler2D blueNoiseMap;
110111
layout(set = 1, binding = 1) uniform MaterialUniforms {
111112
vec3 albedo;
112113
float opacity;
@@ -129,8 +130,6 @@ layout(set = 1, binding = 1) uniform MaterialUniforms {
129130
int maskType;
130131
float opacityWeight;
131132
} material;
132-
133-
134133
layout(set = 2, binding = 0) uniform sampler2D albedoTex;
135134
layout(set = 2, binding = 1) uniform sampler2D normalTex;
136135
layout(set = 2, binding = 2) uniform sampler2D maskRoughTex;
@@ -202,7 +201,7 @@ void main() {
202201
if(scene.lights[i].shadowType == 1) //VSM
203202
lighting *= computeVarianceShadow(shadowMap, scene.lights[i], i, v_modelPos);
204203
if(scene.lights[i].shadowType == 2) //Raytraced
205-
lighting *= computeRaytracedShadow(TLAS, v_modelPos, normalize(scene.lights[i].shadowData.xyz - v_modelPos), 1000);
204+
lighting *= computeRaytracedShadow(TLAS, blueNoiseMap ,v_modelPos, scene.lights[i].shadowData.xyz - v_modelPos, int(scene.lights[i].shadowData.w) , scene.lights[i].area , 0);
206205
}
207206

208207
color += lighting;

resources/shaders/scripts/BRDFs/marschner_BSDF.glsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#define R_NORMALIZING_FACTOR 1.5
88
#define TT_NORMALIZING_FACTOR 1.0
99
#define TRT_NORMALIZING_FACTOR 0.01
10-
#define PI 3.1415926535897932384626433832795
10+
#ifndef PI
11+
#define PI 3.1415926535897932384626433832795
12+
#endif
1113
#define ONE_OVER_PI (1.0 / PI)
1214
#define ONE_OVER_PI_HALF (2.0 / PI)
1315
#define DEG2RAD(x) ((x) / 180.0 * PI)

resources/shaders/scripts/BRDFs/marschner_LUT_BSDF.glsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// LUT BASED
33
/////////////////////////////////////////////
44

5-
#define PI 3.1415926535897932384626433832795
5+
#ifndef PI
6+
#define PI 3.1415926535897932384626433832795
7+
#endif
68
#define ONE_OVER_PI (1.0 / PI)
79
#define ONE_OVER_PI_HALF (2.0 / PI)
810
#define DEG2RAD(x) ((x) / 180.0 * PI)

resources/shaders/scripts/BRDFs/schlick_smith_BRDF.glsl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
const float PI = 3.14159265359;
2-
const float EPSILON = 0.1;
1+
#ifndef PI
2+
#define PI 3.1415926535897932384626433832795
3+
#endif
4+
#ifndef EPSILON
5+
#define EPSILON 0.001
6+
#endif
37

48
struct SchlickSmithBRDF{
59
vec3 albedo;

0 commit comments

Comments
 (0)