Skip to content

Commit

Permalink
Merge pull request #52 from matt77hias/world-space-shading
Browse files Browse the repository at this point in the history
World space shading
  • Loading branch information
matt77hias authored Feb 22, 2018
2 parents 57fb337 + 63fdf9c commit cc82287
Show file tree
Hide file tree
Showing 171 changed files with 4,661 additions and 6,997 deletions.
6 changes: 1 addition & 5 deletions MAGE/FPS/src/samples/forrest/forrest_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ namespace mage {
//---------------------------------------------------------------------
auto camera = Create< PerspectiveCamera >();

// Camera: Lens
// camera->GetLens().SetLensRadius(0.01f);
// camera->GetLens().SetFocalLength(3.0f);
// camera->GetLens().SetMaximumCoCRadius(2.0f);
// Camera: Viewport
// camera->GetViewport().SetNormalizedWidth(0.5f);
// Camera: Fog
Expand Down Expand Up @@ -142,7 +138,7 @@ namespace mage {
camera_node->Add(spot_light);

auto directional_light = Create< DirectionalLight >();
directional_light->SetRadiance(4.0f);
directional_light->SetIrradiance(4.0f);

auto directional_light_node = Create< Node >("Directional Light");
directional_light_node->Add(directional_light);
Expand Down
22 changes: 6 additions & 16 deletions MAGE/MAGE.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,14 @@
<ClInclude Include="MAGE\src\rendering\pass\back_buffer_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\bounding_volume_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\configuration.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\constant_component_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\constant_shading_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\deferred_shading_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\deferred_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\depth_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\dof_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\gbuffer_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\lbuffer_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\shading_normal_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\sky_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\sprite_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\variable_component_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\variable_shading_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\forward_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\voxelization_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pass\wireframe_pass.hpp" />
<ClInclude Include="MAGE\src\rendering\pipeline.hpp" />
<ClInclude Include="MAGE\src\rendering\renderer.hpp" />
<ClInclude Include="MAGE\src\rendering\rendering_output_manager.hpp" />
Expand Down Expand Up @@ -206,20 +200,14 @@
<ClCompile Include="MAGE\src\rendering\pass\aa_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\back_buffer_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\bounding_volume_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\constant_component_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\constant_shading_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\deferred_shading_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\deferred_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\depth_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\dof_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\gbuffer_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\lbuffer_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\shading_normal_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\sky_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\sprite_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\variable_component_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\variable_shading_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\forward_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\voxelization_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pass\wireframe_pass.cpp" />
<ClCompile Include="MAGE\src\rendering\pipeline.cpp" />
<ClCompile Include="MAGE\src\rendering\renderer.cpp" />
<ClCompile Include="MAGE\src\rendering\rendering_factory.cpp" />
Expand Down Expand Up @@ -248,6 +236,7 @@
<ClCompile Include="MAGE\src\ui\main_window.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="MAGE\src\camera\camera.tpp" />
<None Include="MAGE\src\loaders\mdl\mdl_loader.tpp" />
<None Include="MAGE\src\loaders\mdl\mdl_reader.tpp" />
<None Include="MAGE\src\loaders\mdl\mdl_writer.tpp" />
Expand All @@ -260,6 +249,7 @@
<None Include="MAGE\src\mesh\mesh.tpp" />
<None Include="MAGE\src\mesh\primitive_batch_mesh.tpp" />
<None Include="MAGE\src\mesh\static_mesh.tpp" />
<None Include="MAGE\src\model\model.tpp" />
<None Include="MAGE\src\model\model_descriptor.tpp" />
<None Include="MAGE\src\model\model_output.tpp" />
<None Include="MAGE\src\rendering\buffer\constant_buffer.tpp" />
Expand Down
66 changes: 18 additions & 48 deletions MAGE/MAGE.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -441,30 +441,15 @@
<ClInclude Include="MAGE\src\rendering\buffer\camera_buffer.hpp">
<Filter>Header Files\rendering\buffer</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\gbuffer_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\lbuffer_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\shading_normal_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\sky_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\sprite_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\variable_component_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\variable_shading_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\wireframe_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\aa_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
Expand All @@ -477,15 +462,6 @@
<ClInclude Include="MAGE\src\rendering\pass\configuration.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\constant_component_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\constant_shading_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\deferred_shading_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\depth_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
Expand Down Expand Up @@ -594,6 +570,12 @@
<ClInclude Include="MAGE\src\rendering\pass\voxelization_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\deferred_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
<ClInclude Include="MAGE\src\rendering\pass\forward_pass.hpp">
<Filter>Header Files\rendering\pass</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MAGE\src\core\engine.cpp">
Expand Down Expand Up @@ -752,30 +734,15 @@
<ClCompile Include="MAGE\src\rendering\pass\dof_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\gbuffer_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\lbuffer_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\shading_normal_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\sky_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\sprite_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\variable_component_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\variable_shading_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\wireframe_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\aa_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
Expand All @@ -785,15 +752,6 @@
<ClCompile Include="MAGE\src\rendering\pass\bounding_volume_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\constant_component_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\constant_shading_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\deferred_shading_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\depth_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
Expand Down Expand Up @@ -857,6 +815,12 @@
<ClCompile Include="MAGE\src\rendering\pass\voxelization_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\deferred_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
<ClCompile Include="MAGE\src\rendering\pass\forward_pass.cpp">
<Filter>Source Files\rendering\pass</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="MAGE\src\scripting\variable_script.tpp">
Expand Down Expand Up @@ -934,5 +898,11 @@
<None Include="MAGE\src\mesh\primitive_batch_mesh.tpp">
<Filter>Header Files\mesh</Filter>
</None>
<None Include="MAGE\src\model\model.tpp">
<Filter>Header Files\model</Filter>
</None>
<None Include="MAGE\src\camera\camera.tpp">
<Filter>Header Files\camera</Filter>
</None>
</ItemGroup>
</Project>
59 changes: 57 additions & 2 deletions MAGE/MAGE/src/camera/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,79 @@ namespace mage {

Camera::Camera() noexcept
: Component(),
m_buffer(),
m_near_z(MAGE_DEFAULT_NEAR_Z),
m_far_z(MAGE_DEFAULT_FAR_Z),
m_lens(),
m_viewport(),
m_settings() {}

Camera::Camera(const Camera &camera) noexcept = default;
Camera::Camera(const Camera &camera)
: Component(camera),
m_buffer(),
m_near_z(camera.m_near_z),
m_far_z(camera.m_far_z),
m_lens(camera.m_lens),
m_viewport(camera.m_viewport),
m_settings(camera.m_settings) {}

Camera::Camera(Camera &&camera) noexcept = default;

Camera::~Camera() = default;

Camera &Camera::operator=(const Camera &camera) noexcept = default;
Camera &Camera::operator=(const Camera &camera) {
Component::operator=(camera);

m_buffer = ConstantBuffer< CameraBuffer >();
m_near_z = camera.m_near_z;
m_far_z = camera.m_far_z;
m_lens = camera.m_lens;
m_viewport = camera.m_viewport;
m_settings = camera.m_settings;

return *this;
}

Camera &Camera::operator=(Camera &&camera) noexcept = default;

[[nodiscard]] const Viewport Camera::GetSSViewport() const noexcept {
const auto desc = DisplayConfiguration::Get()->GetAADescriptor();
return Viewport(m_viewport, desc);
}

void Camera::UpdateBuffer(ID3D11DeviceContext *device_context) const {
const auto &transform = GetOwner()->GetTransform();
const auto world_to_camera = transform.GetWorldToObjectMatrix();
const auto camera_to_world = transform.GetObjectToWorldMatrix();
const auto camera_to_projection = GetCameraToProjectionMatrix();
const auto projection_to_camera = GetProjectionToCameraMatrix();

CameraBuffer buffer;
buffer.m_world_to_camera = XMMatrixTranspose(world_to_camera);
buffer.m_camera_to_projection = XMMatrixTranspose(camera_to_projection);
buffer.m_projection_to_camera = XMMatrixTranspose(projection_to_camera);
buffer.m_camera_to_world = XMMatrixTranspose(camera_to_world);

buffer.m_viewport_top_left_x = static_cast< U32 >(m_viewport.GetTopLeftX());
buffer.m_viewport_top_left_y = static_cast< U32 >(m_viewport.GetTopLeftY());
buffer.m_viewport_width = static_cast< U32 >(m_viewport.GetWidth());
buffer.m_viewport_height = static_cast< U32 >(m_viewport.GetHeight());
buffer.m_viewport_inv_width_minus1 = 1.0f / (m_viewport.GetWidth() - 1.0f);
buffer.m_viewport_inv_height_minus1 = 1.0f / (m_viewport.GetHeight() - 1.0f);

const auto ss_viewport = GetSSViewport();
buffer.m_ss_viewport_top_left_x = static_cast< U32 >(ss_viewport.GetTopLeftX());
buffer.m_ss_viewport_top_left_y = static_cast< U32 >(ss_viewport.GetTopLeftY());
buffer.m_ss_viewport_width = static_cast< U32 >(ss_viewport.GetWidth());
buffer.m_ss_viewport_height = static_cast< U32 >(ss_viewport.GetHeight());
buffer.m_ss_viewport_inv_width_minus1 = 1.0f / (ss_viewport.GetWidth() - 1.0f);
buffer.m_ss_viewport_inv_height_minus1 = 1.0f / (ss_viewport.GetHeight() - 1.0f);

buffer.m_lens_radius = m_lens.GetLensRadius();
buffer.m_focal_length = m_lens.GetFocalLength();
buffer.m_max_coc_radius = m_lens.GetMaximumCoCRadius();

// Update the camera buffer.
m_buffer.UpdateData(device_context, buffer);
}
}
Loading

0 comments on commit cc82287

Please sign in to comment.