Skip to content

Commit 30b1a20

Browse files
committed
Hackily implement oit
1 parent 178c9c7 commit 30b1a20

File tree

13 files changed

+375
-219
lines changed

13 files changed

+375
-219
lines changed

libopensimcreator/Graphics/OpenSimGraphicsHelpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ SceneRendererParams osc::CalcSceneRendererParams(
6060
rv.dimensions = viewportDims;
6161
}
6262
rv.device_pixel_ratio = viewportDevicePixelRatio;
63-
rv.antialiasing_level = antiAliasingLevel;
63+
rv.anti_aliasing_level = antiAliasingLevel;
6464
rv.light_direction = recommended_light_direction(renderParams.camera);
6565
renderParams.renderingOptions.applyTo(rv);
6666
rv.view_matrix = renderParams.camera.view_matrix();

libopensimcreator/UI/MeshImporter/MeshImporterSharedState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ namespace osc::mi
444444
SceneRendererParams p;
445445
p.dimensions = get3DSceneDims();
446446
p.device_pixel_ratio = app.settings().get_value<float>("graphics/render_scale", 1.0f) * app.main_window_device_pixel_ratio();
447-
p.antialiasing_level = app.anti_aliasing_level();
447+
p.anti_aliasing_level = app.anti_aliasing_level();
448448
p.draw_rims = true;
449449
p.draw_floor = false;
450450
p.near_clipping_plane = m_3DSceneCamera.znear;

libopensimcreator/UI/SplashTab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class osc::SplashTab::Impl final : public TabPrivate {
197197
SceneRendererParams params{m_LastSceneRendererParams};
198198
params.dimensions = workspaceUIRect.dimensions();
199199
params.device_pixel_ratio = App::settings().get_value<float>("graphics/render_scale", 1.0f) * App::get().main_window_device_pixel_ratio(),
200-
params.antialiasing_level = App::get().anti_aliasing_level();
200+
params.anti_aliasing_level = App::get().anti_aliasing_level();
201201
params.projection_matrix = m_Camera.projection_matrix(aspect_ratio_of(workspaceUIRect));
202202

203203
if (params != m_LastSceneRendererParams) {

liboscar-demos/MeshGenTestTab.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class osc::MeshGenTestTab::Impl final : public TabPrivate {
104104
const Vector2 viewport_dimensions = viewport_ui_rect.dimensions();
105105
render_params_.dimensions = elementwise_max(viewport_dimensions, {0.0f, 0.0f});
106106
render_params_.device_pixel_ratio = App::settings().get_value<float>("graphics/render_scale", 1.0f) * App::get().main_window_device_pixel_ratio(),
107-
render_params_.antialiasing_level = App::get().anti_aliasing_level();
107+
render_params_.anti_aliasing_level = App::get().anti_aliasing_level();
108108
render_params_.light_direction = recommended_light_direction(camera_);
109109
render_params_.projection_matrix = camera_.projection_matrix(aspect_ratio_of(render_params_.dimensions));
110110
render_params_.view_matrix = camera_.view_matrix();

liboscar-demos/learnopengl/AdvancedLighting/LOGLPointShadowsTab.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ using namespace osc;
2626

2727
namespace
2828
{
29-
constexpr Vector2i c_shadowmap_pixel_dimensions = {1024, 1024};
29+
constexpr Vector2i c_shadow_map_pixel_dimensions = {1024, 1024};
3030

3131
Transform make_rotated_transform()
3232
{
@@ -66,7 +66,7 @@ namespace
6666
RenderTexture create_depth_texture()
6767
{
6868
return RenderTexture{{
69-
.pixel_dimensions = c_shadowmap_pixel_dimensions,
69+
.pixel_dimensions = c_shadow_map_pixel_dimensions,
7070
.dimensionality = TextureDimensionality::Cube,
7171
.color_format = ColorRenderBufferFormat::R32_SFLOAT,
7272
}};
@@ -128,7 +128,7 @@ class osc::LOGLPointShadowsTab::Impl final : public TabPrivate {
128128
const Rect workspace_screen_space_rect = ui::get_main_window_workspace_screen_space_rect();
129129

130130
draw_shadow_pass_to_cubemap();
131-
draw_shadowmapped_scene_to_screen(workspace_screen_space_rect);
131+
draw_shadow_mapped_scene_to_screen(workspace_screen_space_rect);
132132
}
133133

134134
void draw_shadow_pass_to_cubemap()
@@ -138,7 +138,7 @@ class osc::LOGLPointShadowsTab::Impl final : public TabPrivate {
138138
const float zfar = 25.0f;
139139
const Matrix4x4 projection_matrix = perspective(
140140
90_deg,
141-
aspect_ratio_of(c_shadowmap_pixel_dimensions),
141+
aspect_ratio_of(c_shadow_map_pixel_dimensions),
142142
znear,
143143
zfar
144144
);
@@ -148,19 +148,19 @@ class osc::LOGLPointShadowsTab::Impl final : public TabPrivate {
148148
calc_cubemap_view_proj_matrices(projection_matrix, light_pos_);
149149

150150
// pass data to material
151-
shadowmapping_material_.set_array("uShadowMatrices", shadow_matrices);
152-
shadowmapping_material_.set("uLightPos", light_pos_);
153-
shadowmapping_material_.set("uFarPlane", zfar);
151+
shadow_mapping_material_.set_array("uShadowMatrices", shadow_matrices);
152+
shadow_mapping_material_.set("uLightPos", light_pos_);
153+
shadow_mapping_material_.set("uFarPlane", zfar);
154154

155-
// render (shadowmapping does not use the camera's view/projection matrices)
155+
// render (shadow mapping does not use the camera's view/projection matrices)
156156
Camera camera;
157157
for (const SceneCube& cube : scene_cubes_) {
158-
graphics::draw(cube_mesh_, cube.transform, shadowmapping_material_, camera);
158+
graphics::draw(cube_mesh_, cube.transform, shadow_mapping_material_, camera);
159159
}
160160
camera.render_to(depth_texture_);
161161
}
162162

163-
void draw_shadowmapped_scene_to_screen(const Rect& viewport_screen_space_rect)
163+
void draw_shadow_mapped_scene_to_screen(const Rect& viewport_screen_space_rect)
164164
{
165165
Material material = use_soft_shadows_ ? soft_scene_material_ : scene_material_;
166166

@@ -200,7 +200,7 @@ class osc::LOGLPointShadowsTab::Impl final : public TabPrivate {
200200

201201
ResourceLoader loader_ = App::resource_loader();
202202

203-
Material shadowmapping_material_{Shader{
203+
Material shadow_mapping_material_{Shader{
204204
loader_.slurp("oscar_demos/learnopengl/shaders/AdvancedLighting/point_shadows/MakeShadowMap.vert"),
205205
loader_.slurp("oscar_demos/learnopengl/shaders/AdvancedLighting/point_shadows/MakeShadowMap.geom"),
206206
loader_.slurp("oscar_demos/learnopengl/shaders/AdvancedLighting/point_shadows/MakeShadowMap.frag"),

liboscar-demos/learnopengl/Guest/LOGLCSMTab.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace rgs = std::ranges;
3737

3838
namespace
3939
{
40-
constexpr int c_shadowmap_edge_length = 256;
40+
constexpr int c_shadow_map_edge_length = 256;
4141

4242
// represents a single transformed mesh in the scene
4343
struct TransformedMesh {
@@ -94,11 +94,11 @@ namespace
9494
return rv;
9595
}
9696

97-
// returns blank depth buffers that the cascade (shadowmaps) are written to
97+
// returns blank depth buffers that the cascade (shadow maps) are written to
9898
std::vector<SharedDepthStencilRenderBuffer> generate_blank_cascade_buffers()
9999
{
100100
const DepthStencilRenderBufferParams params = {
101-
.pixel_dimensions = Vector2i{c_shadowmap_edge_length},
101+
.pixel_dimensions = Vector2i{c_shadow_map_edge_length},
102102
.format = DepthStencilRenderBufferFormat::D32_SFloat,
103103
};
104104
return {

liboscar/Graphics/GraphicsImplementation.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2023,7 +2023,7 @@ std::ostream& osc::operator<<(std::ostream& o, const RenderTextureParams& params
20232023
"RenderTextureParams(width = " << params.pixel_dimensions.x
20242024
<< ", height = " << params.pixel_dimensions.y
20252025
<< ", device_pixel_ratio = " << params.device_pixel_ratio
2026-
<< ", antialiasing_level = " << params.anti_aliasing_level
2026+
<< ", anti_aliasing_level = " << params.anti_aliasing_level
20272027
<< ", color_format = " << params.color_format
20282028
<< ", depth_stencil_format = " << params.depth_stencil_format
20292029
<< ")";
@@ -3428,6 +3428,9 @@ class osc::Material::Impl final {
34283428
DepthFunction depth_function() const { return depth_function_; }
34293429
void set_depth_function(DepthFunction depth_function) { depth_function_ = depth_function; }
34303430

3431+
bool writes_to_depth_buffer() const { return writes_to_depth_buffer_; }
3432+
void set_writes_to_depth_buffer(bool value) { writes_to_depth_buffer_ = value; }
3433+
34313434
bool is_wireframe() const { return is_wireframe_mode_; }
34323435
void set_wireframe(bool value) { is_wireframe_mode_ = value; }
34333436

@@ -3446,6 +3449,7 @@ class osc::Material::Impl final {
34463449
BlendingEquation blending_equation_ = BlendingEquation::Default;
34473450
bool is_transparent_ = false;
34483451
bool is_depth_tested_ = true;
3452+
bool writes_to_depth_buffer_ = true;
34493453
bool is_wireframe_mode_ = false;
34503454
};
34513455

@@ -3518,6 +3522,16 @@ void osc::Material::set_depth_function(DepthFunction depth_function)
35183522
impl_.upd()->set_depth_function(depth_function);
35193523
}
35203524

3525+
bool osc::Material::writes_to_depth_buffer() const
3526+
{
3527+
return impl_->writes_to_depth_buffer();
3528+
}
3529+
3530+
void osc::Material::set_writes_to_depth_buffer(bool value)
3531+
{
3532+
impl_.upd()->set_writes_to_depth_buffer(value);
3533+
}
3534+
35213535
bool osc::Material::is_wireframe() const
35223536
{
35233537
return impl_->is_wireframe();
@@ -7346,6 +7360,10 @@ void osc::GraphicsBackend::handle_batch_with_same_material(
73467360
glDepthFunc(to_opengl_depth_function_enum(material_impl.depth_function()));
73477361
}
73487362

7363+
if (not material_impl.writes_to_depth_buffer()) {
7364+
glDepthMask(GL_FALSE);
7365+
}
7366+
73497367
if (material_impl.cull_mode() != CullMode::Off) {
73507368
glEnable(GL_CULL_FACE);
73517369
glCullFace(to_opengl_cull_face_enum(material_impl.cull_mode()));
@@ -7403,6 +7421,10 @@ void osc::GraphicsBackend::handle_batch_with_same_material(
74037421
glDisable(GL_CULL_FACE);
74047422
}
74057423

7424+
if (not material_impl.writes_to_depth_buffer()) {
7425+
glDepthMask(GL_TRUE); // Khronos: "Initially, depth buffer writing is enabled"
7426+
}
7427+
74067428
if (material_impl.depth_function() != DepthFunction::Default) {
74077429
glDepthFunc(to_opengl_depth_function_enum(DepthFunction::Default));
74087430
}

liboscar/Graphics/Material.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ namespace osc
8080
DepthFunction depth_function() const;
8181
void set_depth_function(DepthFunction);
8282

83+
bool writes_to_depth_buffer() const;
84+
void set_writes_to_depth_buffer(bool);
85+
8386
bool is_wireframe() const;
8487
void set_wireframe(bool);
8588

liboscar/Graphics/Material.tests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,22 @@ TEST_F(MaterialTest, MaterialGetDepthFunctionIsInitiallyDefault)
730730
ASSERT_EQ(material.depth_function(), DepthFunction::Default);
731731
}
732732

733+
TEST_F(MaterialTest, MaterialWritesToDepthBufferIsInitiallyTrue)
734+
{
735+
const Material material = generate_material();
736+
ASSERT_TRUE(material.writes_to_depth_buffer());
737+
}
738+
739+
TEST_F(MaterialTest, MaterialSetWritesToDepthBufferChangesWritesToDepthBuffer)
740+
{
741+
Material material = generate_material();
742+
ASSERT_TRUE(material.writes_to_depth_buffer());
743+
material.set_writes_to_depth_buffer(false);
744+
ASSERT_FALSE(material.writes_to_depth_buffer());
745+
material.set_writes_to_depth_buffer(true);
746+
ASSERT_TRUE(material.writes_to_depth_buffer());
747+
}
748+
733749
TEST_F(MaterialTest, MaterialSetDepthFunctionBehavesAsExpected)
734750
{
735751
Material material = generate_material();

liboscar/Graphics/RenderTexture.tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ TEST(RenderTexture, upd_color_buffer_returns_independent_RenderBuffers_from_copi
174174
// this popped up while developing the `LearnOpenGL/CSM` tab implementation, where
175175
// it was using a pattern like:
176176
//
177-
// std::vector<RenderTexture> shadowmaps(num_cascades, RenderTexture{common_params});
177+
// std::vector<RenderTexture> shadow_maps(num_cascades, RenderTexture{common_params});
178178
//
179-
// that pattern wasn't creating independent shadowmaps because the underlying `RenderBuffer`s
179+
// that pattern wasn't creating independent shadow maps because the underlying `RenderBuffer`s
180180
// were being reference-copied, rather than value-copied
181181

182182
RenderTexture render_texture;
@@ -190,9 +190,9 @@ TEST(RenderTexture, upd_depth_buffer_returns_independent_RenderBuffers_from_copi
190190
// this popped up while developing the `LearnOpenGL/CSM` tab implementation, where
191191
// it was using a pattern like:
192192
//
193-
// std::vector<RenderTexture> shadowmaps(num_cascades, RenderTexture{common_params});
193+
// std::vector<RenderTexture> shadow_maps(num_cascades, RenderTexture{common_params});
194194
//
195-
// that pattern wasn't creating independent shadowmaps because the underlying `RenderBuffer`s
195+
// that pattern wasn't creating independent shadow maps because the underlying `RenderBuffer`s
196196
// were being reference-copied, rather than value-copied
197197

198198
RenderTexture rt;

0 commit comments

Comments
 (0)