Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Commit 9f9f7bb

Browse files
committed
Demo stuff
1 parent b7113f4 commit 9f9f7bb

25 files changed

+191
-122
lines changed

demo/demo_frame_graphs.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace fg_manager
9292
wr::AddPostProcessingTask<wr::DeferredCompositionTaskData>(*fg);
9393

9494
// Do Depth of field task
95-
wr::AddDoFCoCTask<wr::DeferredMainTaskData>(*fg);
95+
/*wr::AddDoFCoCTask<wr::DeferredMainTaskData>(*fg);
9696
9797
wr::AddDoFDownScaleTask<wr::PostProcessingData, wr::DoFCoCData>(*fg,
9898
rs.m_window.value()->GetWidth(), rs.m_window.value()->GetHeight());
@@ -112,12 +112,12 @@ namespace fg_manager
112112
wr::AddDoFBokehPostFilterTask<wr::DoFBokehData>(*fg,
113113
rs.m_window.value()->GetWidth(), rs.m_window.value()->GetHeight());
114114
115-
wr::AddDoFCompositionTask<wr::PostProcessingData, wr::DoFBokehPostFilterData, wr::DoFCoCData>(*fg);
115+
wr::AddDoFCompositionTask<wr::PostProcessingData, wr::DoFBokehPostFilterData, wr::DoFCoCData>(*fg);*/
116116

117117
// Copy the scene render pixel data to the final render target
118-
wr::AddRenderTargetCopyTask<wr::DoFCompositionData>(*fg);
118+
wr::AddRenderTargetCopyTask<wr::PostProcessingData>(*fg);
119119
// Display ImGui
120-
fg->AddTask<wr::ImGuiTaskData>(wr::GetImGuiTask<wr::DoFCompositionData>(imgui_func));
120+
fg->AddTask<wr::ImGuiTaskData>(wr::GetImGuiTask<wr::PostProcessingData>(imgui_func));
121121

122122
fg->Setup(rs);
123123
}

demo/scene_viknell.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace viknell_scene
4545
wr::TextureHandle bamboo_roughness = texture_pool->LoadFromFile("resources/materials/bamboo/bamboo-wood-semigloss-roughness.png", false, true);
4646
wr::TextureHandle bamboo_metallic = texture_pool->LoadFromFile("resources/materials/bamboo/bamboo-wood-semigloss-metal.png", false, true);
4747

48-
equirectangular_environment_map = texture_pool->LoadFromFile("resources/materials/Circus_Backstage_3k.hdr", false, false);
48+
equirectangular_environment_map = texture_pool->LoadFromFile("resources/materials/SunTemple_Skybox.hdr", false, false);
4949

5050
// Create Materials
5151
mirror_material = material_pool->Create();
@@ -69,7 +69,7 @@ namespace viknell_scene
6969
bamboo_material_internal->SetMetallic(bamboo_metallic);
7070

7171
plane_model = model_pool->Load<wr::VertexColor>(material_pool.get(), texture_pool.get(), "resources/models/plane.fbx");
72-
test_model = model_pool->LoadWithMaterials<wr::VertexColor>(material_pool.get(), texture_pool.get(), "resources/models/sponza_jacco/sponza.obj");
72+
test_model = model_pool->LoadWithMaterials<wr::VertexColor>(material_pool.get(), texture_pool.get(), "resources/materials/SunTemple.fbx");
7373
sphere_model = model_pool->Load<wr::VertexColor>(material_pool.get(), texture_pool.get(), "resources/models/sphere.fbx");
7474
}
7575

@@ -98,9 +98,9 @@ namespace viknell_scene
9898
camera->SetPosition({0, 0, 2});
9999
camera->SetSpeed(10);
100100

101-
camera_spline_node = scene_graph->CreateChild<SplineNode>(nullptr, "Camera Spline");
102-
light_1_spline_node = scene_graph->CreateChild<SplineNode>(nullptr, "Light 1 Spline");
103-
light_2_spline_node = scene_graph->CreateChild<SplineNode>(nullptr, "Light 2 Spline");
101+
camera_spline_node = scene_graph->CreateChild<SplineNode>(nullptr, "Camera Spline", false);
102+
light_1_spline_node = scene_graph->CreateChild<SplineNode>(nullptr, "Light 1 Spline", true);
103+
light_2_spline_node = scene_graph->CreateChild<SplineNode>(nullptr, "Light 2 Spline", true);
104104

105105
scene_graph->m_skybox = resources::equirectangular_environment_map;
106106
auto skybox = scene_graph->CreateChild<wr::SkyboxNode>(nullptr, resources::equirectangular_environment_map);
@@ -137,16 +137,16 @@ namespace viknell_scene
137137

138138

139139
// Lights
140-
auto point_light_0 = scene_graph->CreateChild<wr::LightNode>(nullptr, wr::LightType::DIRECTIONAL, DirectX::XMVECTOR{1, 1, 1});
140+
auto point_light_0 = scene_graph->CreateChild<wr::LightNode>(nullptr, wr::LightType::POINT, DirectX::XMVECTOR{ 1000 / 255, 1000 / 255, 1000 / 255 });
141141
//point_light_0->SetRadius(3.0f);
142-
point_light_0->SetRotation({20.950, 0.98, 0});
143-
point_light_0->SetPosition({-0.002, 0.080, 1.404});
142+
point_light_0->SetPosition({ 0, 2.5, 0 });
143+
point_light_0->SetRadius(10000.f);
144144

145-
point_light_1 = scene_graph->CreateChild<wr::LightNode>(nullptr, wr::LightType::POINT, DirectX::XMVECTOR{1, 0, 0});
145+
point_light_1 = scene_graph->CreateChild<wr::LightNode>(nullptr, wr::LightType::POINT, DirectX::XMVECTOR{3000 / 255, 0, 0});
146146
point_light_1->SetRadius(5.0f);
147147
point_light_1->SetPosition({0.5, 0, -0.3});
148148

149-
point_light_2 = scene_graph->CreateChild<wr::LightNode>(nullptr, wr::LightType::POINT, DirectX::XMVECTOR{0, 0, 1});
149+
point_light_2 = scene_graph->CreateChild<wr::LightNode>(nullptr, wr::LightType::POINT, DirectX::XMVECTOR{0, 0, 3000 / 255});
150150
point_light_2->SetRadius(5.0f);
151151
point_light_2->SetPosition({-0.5, 0.5, -0.3});
152152

demo/spline_node.cpp

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
static bool initialized = false;
1010

11-
SplineNode::SplineNode(std::string name) : Node(typeid(SplineNode)), m_name(name), m_animate(false), m_speed(1), m_time(0), m_spline(nullptr), m_quat_spline(nullptr)
11+
SplineNode::SplineNode(std::string name, bool looping) : Node(typeid(SplineNode)), m_name(name), m_animate(false), m_speed(1), m_time(0), m_spline(nullptr), m_quat_spline(nullptr), m_looping(looping)
1212
{
1313
if (initialized) return;
1414
initialized = true;
@@ -110,6 +110,11 @@ SplineNode::SplineNode(std::string name) : Node(typeid(SplineNode)), m_name(name
110110
scene_graph->GetActiveCamera()->SetRotation(cp.m_rotation);
111111
}
112112

113+
if (ImGui::Button("Remove"))
114+
{
115+
spline_node->m_control_points.erase(spline_node->m_control_points.begin() + i);
116+
}
117+
113118
ImGui::TreePop();
114119
}
115120
}
@@ -130,36 +135,43 @@ void SplineNode::UpdateSplineNode(float delta, std::shared_ptr<wr::Node> node)
130135

131136
auto num_points = m_control_points.size();
132137

133-
m_time += delta * m_speed;
134-
m_time = std::fmod(m_time, m_spline->getMaxT());
135-
136-
auto lerp_delta = m_time / m_spline->getMaxT();
137-
#ifdef LOOPING
138-
auto segment_i = lerp_delta * ((float)num_points);
139-
auto alpha = (lerp_delta * ((float)num_points)) - floor(segment_i);
140-
#else
141-
auto segment_i = lerp_delta * ((float)num_points - 1.f);
142-
auto alpha = (lerp_delta * ((float)num_points - 1.f)) - floor(segment_i);
143-
#endif
144-
145-
float backback = std::fmod((std::fmod(floor(segment_i), num_points) + num_points), num_points);
146-
auto back_point = m_control_points[backback];
147-
auto prev_point = m_control_points[floor(segment_i)];
148-
auto next_point = m_control_points[fmod(ceil(segment_i), num_points)];
149-
auto end_point = m_control_points[fmod(ceil(segment_i+1), num_points)];
150-
151-
auto rot_a = DirectX::XMQuaternionRotationRollPitchYawFromVector(prev_point.m_rotation);
152-
auto rot_b = DirectX::XMQuaternionRotationRollPitchYawFromVector(next_point.m_rotation);
153-
auto interp = DirectX::XMQuaternionSlerp(rot_a, rot_b, alpha);
154-
155-
auto new_pos = m_spline->getPosition(m_time);
156-
auto new_rot = m_quat_spline->getPosition(m_time);
157-
158-
LOG("{} -- {}", floor(segment_i), fmod(ceil(segment_i), num_points));
138+
auto impl = [&](auto spline, auto quat_spline)
139+
{
140+
m_time += delta * m_speed;
141+
m_time = std::fmod(m_time, spline->getMaxT());
142+
143+
auto lerp_delta = m_time / spline->getMaxT();
144+
145+
auto mod = m_looping ? 0.f : 1.f;
146+
auto segment_i = lerp_delta * ((float)num_points - mod);
147+
auto alpha = (lerp_delta * ((float)num_points - mod)) - floor(segment_i);
148+
149+
float backback = std::fmod((std::fmod(floor(segment_i), num_points) + num_points), num_points);
150+
auto back_point = m_control_points[backback];
151+
auto prev_point = m_control_points[floor(segment_i)];
152+
auto next_point = m_control_points[fmod(ceil(segment_i), num_points)];
153+
auto end_point = m_control_points[fmod(ceil(segment_i + 1), num_points)];
154+
155+
auto rot_a = DirectX::XMQuaternionRotationRollPitchYawFromVector(prev_point.m_rotation);
156+
auto rot_b = DirectX::XMQuaternionRotationRollPitchYawFromVector(next_point.m_rotation);
157+
auto interp = DirectX::XMQuaternionSlerp(rot_a, rot_b, alpha);
158+
159+
auto new_pos = spline->getPosition(m_time);
160+
auto new_rot = quat_spline->getPosition(m_time);
161+
162+
node->SetPosition({ new_pos[0], new_pos[1], new_pos[2] });
163+
node->SetRotationQuat(interp);
164+
node->SetRotationQuat({ new_rot[0], new_rot[1], new_rot[2], new_rot[3] });
165+
};
159166

160-
node->SetPosition({ new_pos[0], new_pos[1], new_pos[2] });
161-
node->SetRotationQuat(interp);
162-
node->SetRotationQuat({ new_rot[0], new_rot[1], new_rot[2], new_rot[3] });
167+
if (m_looping)
168+
{
169+
impl(reinterpret_cast<LoopingNaturalSpline<Vector<3>>*>(m_spline), reinterpret_cast<LoopingNaturalSpline<Vector<4>>*>(m_quat_spline));
170+
}
171+
else
172+
{
173+
impl(reinterpret_cast<NaturalSpline<Vector<3>>*>(m_spline), reinterpret_cast<NaturalSpline<Vector<4>>*>(m_quat_spline));
174+
}
163175
}
164176

165177
void SplineNode::UpdateNaturalSpline()
@@ -176,7 +188,7 @@ void SplineNode::UpdateNaturalSpline()
176188
m_quat_spline = nullptr;
177189
}
178190

179-
if (m_control_points.size() < 3)
191+
if (m_control_points.size() < (m_looping ? 2 : 3))
180192
{
181193
return;
182194
}
@@ -189,11 +201,14 @@ void SplineNode::UpdateNaturalSpline()
189201
m_spline_positions.push_back(Vector<3>({ cp.m_position.m128_f32[0], cp.m_position.m128_f32[1], cp.m_position.m128_f32[2] }));
190202
}
191203

192-
#ifdef LOOPING
193-
m_spline = new LoopingNaturalSpline<Vector<3>>(m_spline_positions);
194-
#else
195-
m_spline = new NaturalSpline<Vector<3>>(m_spline_positions);
196-
#endif
204+
if (m_looping)
205+
{
206+
m_spline = new LoopingNaturalSpline<Vector<3>>(m_spline_positions);
207+
}
208+
else
209+
{
210+
m_spline = new NaturalSpline<Vector<3>>(m_spline_positions);
211+
}
197212
}
198213

199214
{
@@ -204,11 +219,15 @@ void SplineNode::UpdateNaturalSpline()
204219
auto quat = DirectX::XMQuaternionRotationRollPitchYawFromVector(cp.m_rotation);
205220
m_spline_rotations.push_back(Vector<4>({ quat.m128_f32[0], quat.m128_f32[1], quat.m128_f32[2], quat.m128_f32[3] }));
206221
}
207-
#ifdef LOOPING
208-
m_quat_spline = new LoopingNaturalSpline<Vector<4>>(m_spline_positions);
209-
#else
210-
m_quat_spline = new NaturalSpline<Vector<4>>(m_spline_rotations);
211-
#endif
222+
223+
if (m_looping)
224+
{
225+
m_quat_spline = new LoopingNaturalSpline<Vector<4>>(m_spline_rotations);
226+
}
227+
else
228+
{
229+
m_quat_spline = new NaturalSpline<Vector<4>>(m_spline_rotations);
230+
}
212231
}
213232
}
214233

demo/spline_node.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SplineNode : public wr::Node
1414
};
1515

1616
public:
17-
SplineNode(std::string name);
17+
SplineNode(std::string name, bool looping = false);
1818
~SplineNode();
1919

2020
void UpdateSplineNode(float delta, std::shared_ptr<wr::Node> node);
@@ -32,16 +32,14 @@ class SplineNode : public wr::Node
3232
DirectX::XMVECTOR m_initial_position;
3333
DirectX::XMVECTOR m_initial_rotation;
3434

35-
#ifdef LOOPING
36-
LoopingNaturalSpline<Vector<3>>* m_spline;
37-
LoopingNaturalSpline<Vector<4>>* m_quat_spline;
38-
#else
39-
NaturalSpline<Vector<3>>* m_spline;
40-
NaturalSpline<Vector<4>>* m_quat_spline;
41-
#endif
35+
void* m_spline;
36+
void* m_quat_spline;
37+
4238
std::vector<ControlPoint> m_control_points;
4339
float m_speed;
4440
float m_time;
4541

42+
bool m_looping;
43+
4644
std::string m_name;
4745
};

resources/shaders/basic.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ VS_OUTPUT main_vs(VS_INPUT input, uint instid : SV_InstanceId)
5858
output.uv = float2(input.uv.x, 1.0f - input.uv.y);
5959
output.tangent = normalize(mul(inst.model, float4(input.tangent, 0))).xyz;
6060
output.bitangent = normalize(mul(inst.model, float4(input.bitangent, 0))).xyz;
61-
output.normal = normalize(mul(inst.model, float4(input.normal, 0))).xyz;
61+
output.normal = normalize(mul(inst.model, float4(-input.normal, 0))).xyz;
6262
output.color = input.color;
6363

6464
return output;

resources/shaders/deferred_composition.hlsl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,19 @@ void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID)
8080
else
8181
{
8282
irradiance = irradiance_map.SampleLevel(linear_sampler, flipped_N, 0).xyz;
83+
irradiance /= 2;
8384
}
8485

86+
#ifdef HARD_IRR
87+
irradiance = IRR;
88+
#endif
89+
8590
// Get shadow factor (0: fully shadowed, 1: no shadow)
8691
float shadow_factor = lerp(
8792
// Do deferred shadow (fully lit for now)
8893
1.0,
8994
// Shadow buffer if its hybrid rendering
90-
buffer_refl_shadow[screen_coord].a,
95+
buffer_refl_shadow.SampleLevel(linear_sampler, uv, 0).w,
9196
// Lerp factor (0: no hybrid, 1: hybrid)
9297
is_hybrid);
9398

@@ -98,12 +103,13 @@ void main_cs(int3 dispatch_thread_id : SV_DispatchThreadID)
98103
// Sample from environment if it IS NOT hybrid rendering
99104
sampled_environment_map,
100105
// Reflection buffer if it IS hybrid rendering
101-
buffer_refl_shadow[screen_coord].xyz,
106+
buffer_refl_shadow.SampleLevel(linear_sampler, uv, 0).xyz,
102107
// Lerp factor (0: no hybrid, 1: hybrid)
103108
is_hybrid);
104109

105110
// Shade pixel
106111
retval = shade_pixel(pos, V, albedo, metallic, roughness, normal, irradiance, reflection, sampled_brdf, shadow_factor);
112+
//retval = reflection;
107113
}
108114
else
109115
{

resources/shaders/lighting.hlsl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ float3 shade_pixel(float3 pos, float3 V, float3 albedo, float metallic, float ro
7272
float3 specular = prefiltered_color * (kS * sampled_brdf.x + sampled_brdf.y);
7373
//float3 specular = reflection * kS;
7474

75-
float3 ambient = (kD * diffuse + specular) * 1.0f; //Replace 1.0f with AO, when we have it.
75+
float3 ambient = ((kD * diffuse) + specular) * 1.0f; //Replace 1.0f with AO, when we have it.
7676

77-
return ambient + (res * shadow_factor);
77+
return ambient + (res);
7878
}
7979

8080
float3 shade_light(float3 pos, float3 V, float3 albedo, float3 normal, float metallic, float roughness, Light light, inout uint rand_seed, uint depth)
@@ -147,8 +147,18 @@ float DoShadowAllLights(float3 wpos, uint depth, inout float rand_seed)
147147
// Get maxium ray length (depending on type)
148148
float t_max = lerp(light_dist, 100000, tid == light_type_directional);
149149

150+
float min_cos = cos(light.ang);
151+
float max_cos = lerp(min_cos, 1, 0.5f);
152+
float cos_angle = dot(light.dir, L);
153+
float spot_intensity = lerp(smoothstep(min_cos, max_cos, cos_angle), 1, tid != light_type_spot);
154+
155+
//Attenuation & spot intensity (only used with point or spot)
156+
float attenuation = lerp(1.0f - smoothstep(0, light.rad, light_dist), 1, tid == light_type_directional);
157+
158+
float3 radiance = attenuation;
159+
150160
// Add shadow factor to final result
151-
res += GetShadowFactor(wpos, L, t_max, depth + 1, rand_seed);
161+
res += GetShadowFactor(wpos, L, t_max, depth, rand_seed) * length(radiance);
152162
}
153163

154164
// return final res

resources/shaders/material_util.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ OutputMaterialData InterpretMaterialData(MaterialData data,
4949

5050
float4 albedo = lerp(material_albedo.Sample(s0, uv), float4(data.albedo_alpha.xyz, 1.0f), use_albedo_constant != 0 || has_albedo_texture == 0);
5151

52-
//#define COMPRESSED_PBR
52+
#define COMPRESSED_PBR
5353
#ifdef COMPRESSED_PBR
5454
float4 roughness = lerp(material_metallic.Sample(s0, uv).y, data.metallic_roughness.w, use_roughness_constant != 0 || has_roughness_texture == 0);
5555
float4 metallic = lerp(material_metallic.Sample(s0, uv).z, length(data.metallic_roughness.xyz), use_metallic_constant != 0 || has_metallic_texture == 0);
@@ -86,7 +86,7 @@ OutputMaterialData InterpretMaterialDataRT(MaterialData data,
8686
uint has_metallic_texture = data.flags & MATERIAL_HAS_METALLIC_TEXTURE;
8787
uint use_normal_texture = data.flags & MATERIAL_HAS_NORMAL_TEXTURE;
8888

89-
//#define COMPRESSED_PBR
89+
#define COMPRESSED_PBR
9090
#ifdef COMPRESSED_PBR
9191
const float3 albedo = lerp(material_albedo.SampleLevel(s0, uv, mip_level).xyz,
9292
data.albedo_alpha.xyz,

resources/shaders/post_processing.hlsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ void main(uint3 DTid : SV_DispatchThreadID)
2020
float2 uv = (float2(DTid.xy) / resolution);
2121

2222
float gamma = 2.2;
23-
float exposure = 1;
23+
float exposure = 2;
2424

2525
float3 color = input[DTid.xy].rgb;
26-
//color = SampleFXAA(input, s0, DTid.xy, resolution);
26+
color = SampleFXAA(input, s0, DTid.xy, resolution);
2727
//uv = ZoomUV(uv, 0.75);
2828
//float3 color = input.SampleLevel(s0, BarrelDistortUV(uv, 2), 0);
2929
//float3 color = ChromaticAberrationV2(input, s0, uv, 0.2, 0.96f).rgb;
3030

3131
if (hdr == 0)
3232
{
33-
color = linearToneMapping(color, exposure, gamma);
34-
//color = simpleReinhardToneMapping(color, exposure, gamma);
33+
//color = linearToneMapping(color, exposure, gamma);
34+
color = simpleReinhardToneMapping(color, exposure, gamma);
3535
//color = lumaBasedReinhardToneMapping(color, gamma);
3636
//color = whitePreservingLumaBasedReinhardToneMapping(color, gamma);
3737
//color = RomBinDaHouseToneMapping(color, gamma);

resources/shaders/rt_global.hlsl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
#define MAX_RECURSION 3
1+
#define MAX_RECURSION 2
22
//#define FOUR_X_A
33
//#define PATH_TRACING
44
//#define DEPTH_OF_FIELD
5-
#define EPSILON 0.01
6-
#define MAX_SHADOW_SAMPLES 4
5+
#define SOFT_SHADOWS
6+
#define EPSILON 0.05
7+
#define MAX_SHADOW_SAMPLES 8
78

89
#ifdef FALLBACK
910
#undef MAX_RECURSION
@@ -12,5 +13,10 @@
1213
#define NO_SHADOWS
1314
#endif
1415

16+
#define HARD_IRR
17+
#ifdef HARD_IRR
18+
#define IRR 0.15
19+
#endif
20+
1521
RaytracingAccelerationStructure Scene : register(t0, space0);
1622

0 commit comments

Comments
 (0)