From a2636e834cc17e41621d98fa2427c895a61b3398 Mon Sep 17 00:00:00 2001 From: ecker Date: Sun, 28 Jun 2026 19:56:55 -0500 Subject: [PATCH] opengl related fixes that almost are done (some props aren't rendering because of alpha shitcannery) --- bin/data/config.json | 4 +-- bin/data/entities/playerModel.json | 2 +- .../scenes/sourceengine/mds_mcdonalds.json | 4 +-- .../scenes/sourceengine/sourceengine.json | 4 +-- engine/inc/uf/engine/graph/pod.inl | 2 +- engine/inc/uf/ext/opengl/commands.h | 2 +- engine/inc/uf/ext/opengl/enums.h | 36 +++++++++---------- engine/src/engine/ext/ext.cpp | 6 ++-- engine/src/engine/graph/graph.cpp | 11 +++++- engine/src/ext/opengl/commands.cpp | 31 +++++++++------- engine/src/ext/opengl/graphic.cpp | 12 ++++--- engine/src/ext/valve/common.cpp | 1 + 12 files changed, 68 insertions(+), 47 deletions(-) diff --git a/bin/data/config.json b/bin/data/config.json index 33693021..03fadef6 100644 --- a/bin/data/config.json +++ b/bin/data/config.json @@ -1,9 +1,9 @@ { "engine": { "scenes": { - "start": "StartMenu", + "start": "SourceEngine", "lights": { "enabled": true, - "lightmaps": true, + "lightmaps": false, "max": 32, "shadows": { "enabled": false, diff --git a/bin/data/entities/playerModel.json b/bin/data/entities/playerModel.json index 5467bb32..f156a219 100644 --- a/bin/data/entities/playerModel.json +++ b/bin/data/entities/playerModel.json @@ -1,7 +1,7 @@ { "type": "Object", "name": "Player: Model", - "ignore": false, + "ignore": true, "import": "/model.json", "assets": [ // "/player/pbear.glb" diff --git a/bin/data/scenes/sourceengine/mds_mcdonalds.json b/bin/data/scenes/sourceengine/mds_mcdonalds.json index 9532b7bd..4ddfaa21 100644 --- a/bin/data/scenes/sourceengine/mds_mcdonalds.json +++ b/bin/data/scenes/sourceengine/mds_mcdonalds.json @@ -1,8 +1,8 @@ { "import": "./base_sourceengine.json", "assets": [ - { "filename": "./maps/mcdonalds-mds.bsp" } - // { "filename": "./maps/mcdonalds-mds/graph.json" } + // { "filename": "./maps/mcdonalds-mds.bsp" } + { "filename": "./maps/mcdonalds-mds/graph.json" } // ,{ "filename": "ent://burger.json", "delay": 1 } // ,{ "filename": "ent://craeture.json", "delay": 2 } ] diff --git a/bin/data/scenes/sourceengine/sourceengine.json b/bin/data/scenes/sourceengine/sourceengine.json index 89c57145..f7a5e99b 100644 --- a/bin/data/scenes/sourceengine/sourceengine.json +++ b/bin/data/scenes/sourceengine/sourceengine.json @@ -1,8 +1,8 @@ { // "import": "./rp_downtown_v2.json" // "import": "./ss2_medsci1.json" -// "import": "./mds_mcdonalds.json" - "import": "./cs_office.json" + "import": "./mds_mcdonalds.json" +// "import": "./cs_office.json" // "import": "./de_dust2.json" // "import": "./gm_construct.json" } \ No newline at end of file diff --git a/engine/inc/uf/engine/graph/pod.inl b/engine/inc/uf/engine/graph/pod.inl index d509a32b..5b6417af 100644 --- a/engine/inc/uf/engine/graph/pod.inl +++ b/engine/inc/uf/engine/graph/pod.inl @@ -22,7 +22,7 @@ namespace pod { float factorMetallic = 0.0f; float factorRoughness = 1.0f; float factorOcclusion = 1.0f; - float factorAlphaCutoff = 1.0f; + float factorAlphaCutoff = 0.0f; int32_t indexAlbedo = -1; int32_t indexNormal = -1; diff --git a/engine/inc/uf/ext/opengl/commands.h b/engine/inc/uf/ext/opengl/commands.h index 25400038..6ff2645f 100644 --- a/engine/inc/uf/ext/opengl/commands.h +++ b/engine/inc/uf/ext/opengl/commands.h @@ -69,7 +69,7 @@ namespace ext { } textures; struct { - uint8_t modeAlpha{}; + int8_t modeAlpha{}; float alphaCutoff = 0.001f; } blend; diff --git a/engine/inc/uf/ext/opengl/enums.h b/engine/inc/uf/ext/opengl/enums.h index becc5ec6..4e98b684 100644 --- a/engine/inc/uf/ext/opengl/enums.h +++ b/engine/inc/uf/ext/opengl/enums.h @@ -97,30 +97,30 @@ namespace ext { } namespace PrimitiveTopology { typedef GLenum type_t; - static const type_t POINT_LIST = GLenumerator(VK_PRIMITIVE_TOPOLOGY_POINT_LIST); - static const type_t LINE_LIST = GLenumerator(VK_PRIMITIVE_TOPOLOGY_LINE_LIST); - static const type_t LINE_STRIP = GLenumerator(VK_PRIMITIVE_TOPOLOGY_LINE_STRIP); - static const type_t TRIANGLE_LIST = GLenumerator(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST); - static const type_t TRIANGLE_STRIP = GLenumerator(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP); - static const type_t TRIANGLE_FAN = GLenumerator(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN); - static const type_t LINE_LIST_WITH_ADJACENCY = GLenumerator(VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY); - static const type_t LINE_STRIP_WITH_ADJACENCY = GLenumerator(VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY); - static const type_t TRIANGLE_LIST_WITH_ADJACENCY = GLenumerator(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY); - static const type_t TRIANGLE_STRIP_WITH_ADJACENCY = GLenumerator(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY); - static const type_t PATCH_LIST = GLenumerator(VK_PRIMITIVE_TOPOLOGY_PATCH_LIST); + static const type_t POINT_LIST = 0; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_POINT_LIST); + static const type_t LINE_LIST = 1; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_LINE_LIST); + static const type_t LINE_STRIP = 2; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_LINE_STRIP); + static const type_t TRIANGLE_LIST = 3; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST); + static const type_t TRIANGLE_STRIP = 4; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP); + static const type_t TRIANGLE_FAN = 5; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN); + static const type_t LINE_LIST_WITH_ADJACENCY = 6; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY); + static const type_t LINE_STRIP_WITH_ADJACENCY = 7; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY); + static const type_t TRIANGLE_LIST_WITH_ADJACENCY = 8; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY); + static const type_t TRIANGLE_STRIP_WITH_ADJACENCY = 9; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY); + static const type_t PATCH_LIST = 10; // GLenumerator(VK_PRIMITIVE_TOPOLOGY_PATCH_LIST); } namespace PolygonMode { typedef GLenum type_t; - static const type_t FILL = GLenumerator(VK_POLYGON_MODE_FILL); - static const type_t LINE = GLenumerator(VK_POLYGON_MODE_LINE); - static const type_t POINT = GLenumerator(VK_POLYGON_MODE_POINT); + static const type_t FILL = 0; // GLenumerator(VK_POLYGON_MODE_FILL); + static const type_t LINE = 1; // GLenumerator(VK_POLYGON_MODE_LINE); + static const type_t POINT = 2; // GLenumerator(VK_POLYGON_MODE_POINT); } namespace AddressMode { typedef GLenum type_t; - static const type_t CLAMP_TO_EDGE = GLenumerator(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE); - static const type_t CLAMP_TO_BORDER = GLenumerator(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER); - static const type_t MIRRORED_REPEAT = GLenumerator(VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT); - static const type_t REPEAT = GLenumerator(VK_SAMPLER_ADDRESS_MODE_REPEAT); + static const type_t CLAMP_TO_EDGE = 0; // GLenumerator(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE); + static const type_t CLAMP_TO_BORDER = 1; // GLenumerator(VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER); + static const type_t MIRRORED_REPEAT = 2; // GLenumerator(VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT); + static const type_t REPEAT = 3; // GLenumerator(VK_SAMPLER_ADDRESS_MODE_REPEAT); } namespace Filter { typedef GLenum type_t; diff --git a/engine/src/engine/ext/ext.cpp b/engine/src/engine/ext/ext.cpp index a33b213e..be59e117 100644 --- a/engine/src/engine/ext/ext.cpp +++ b/engine/src/engine/ext/ext.cpp @@ -48,7 +48,7 @@ #include #include -#if UF_USE_OPENVR +#if UF_USE_OPENVR && UF_USE_VULKAN #include #endif @@ -664,7 +664,7 @@ void UF_API uf::initialize() { } #endif -#if UF_USE_OPENVR +#if UF_USE_OPENVR && UF_USE_VULKAN { auto& configVrJson = uf::config["engine"]["ext"]["vr"]; ext::openvr::enabled = configVrJson["enable"].as( ext::openvr::enabled ); @@ -674,7 +674,7 @@ void UF_API uf::initialize() { } // could probably live alongside gui/deferred in the scene - static auto* vrRenderMode = new ext::vulkan::VrRenderMode; + static auto* vrRenderMode = new uf::renderer::VrRenderMode; uf::renderer::addRenderMode(vrRenderMode, "VR"); } #endif diff --git a/engine/src/engine/graph/graph.cpp b/engine/src/engine/graph/graph.cpp index 9fb4606b..c3e52bb1 100644 --- a/engine/src/engine/graph/graph.cpp +++ b/engine/src/engine/graph/graph.cpp @@ -834,9 +834,17 @@ void uf::graph::process( pod::Graph& graph ) { UF_DEBUG_TIMER_MULTITRACE("Parsing lightmaps"); // cringe hack for VBSP loader if ( storage.textures.map.count("lightmap_atlas") > 0 ) { - graphMetadataJson["lights"]["lightmap"] = true; graphMetadataJson["baking"]["enabled"] = false; textureDescriptors["lightmap_atlas"].srgb = false; + + if ( !graphMetadataJson["lights"]["lightmap"].as() ) { + for ( auto& name : graph.primitives ) { + auto& primitives = storage.primitives[name]; + for ( auto& primitive : primitives ) { + primitive.instance.lightmapID = -1; + } + } + } } else { constexpr const char* UF_GRAPH_DEFAULT_LIGHTMAP = "./lightmap.%i.png"; uf::stl::unordered_map filenames; @@ -1518,6 +1526,7 @@ void uf::graph::process( pod::Graph& graph, int32_t index, uf::Object& parent ) storage.objects[objectKeyName] = pod::Instance::Object{ .model = model, .previous = model, + .color = {1, 1, 1, 1}, }; if ( node.skin >= 0 && node.skin < graph.skins.size() ) { diff --git a/engine/src/ext/opengl/commands.cpp b/engine/src/ext/opengl/commands.cpp index 66b5b432..2a8cb118 100644 --- a/engine/src/ext/opengl/commands.cpp +++ b/engine/src/ext/opengl/commands.cpp @@ -281,10 +281,11 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: pod::Matrix4f mat = (*drawInfo.matrices.projection) * (*drawInfo.matrices.view) * (*drawInfo.matrices.model); bool visible = inside( instance, mat ); - drawCommand.instances = visible ? 1 : 0; - if ( !visible ) ++::culled; + if ( !visible ) { + ++::culled; + return; + } } - if ( drawCommand.instances == 0 ) return; } GL_ERROR_CHECK(glMatrixMode(GL_MODELVIEW)); @@ -327,12 +328,9 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: GL_ERROR_CHECK(glDisable(GL_DEPTH_TEST)); } GL_ERROR_CHECK(glDepthMask(drawInfo.descriptor.depth.write ? GL_TRUE : GL_FALSE)); - - uf::stl::vector colors; // CPU-buffer based command dispatching if ( drawInfo.attributes.normal.pointer ) GL_ERROR_CHECK(glEnableClientState(GL_NORMAL_ARRAY)); - if ( drawInfo.attributes.color.pointer || drawInfo.color.enabled ) GL_ERROR_CHECK(glEnableClientState(GL_COLOR_ARRAY)); GL_ERROR_CHECK(glEnableClientState(GL_VERTEX_ARRAY)); GLenum vertexType = GL_FLOAT; @@ -452,16 +450,17 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: // prioritize uniform color for now if ( drawInfo.color.enabled ) { const auto& color = drawInfo.color.pointer ? *drawInfo.color.pointer : drawInfo.color.value; - colors = uf::stl::vector( drawInfo.descriptor.inputs.vertex.count, color ); - GL_ERROR_CHECK(glColorPointer(4, GL_FLOAT, sizeof(pod::Vector4f), colors.data())); - // GL_ERROR_CHECK(glColor4f( color[0], color[1], color[2], color[3] )); + GL_ERROR_CHECK(glColor4f( color[0], color[1], color[2], color[3] )); } else if ( drawInfo.attributes.color.pointer ) { GLenum colorType = GL_UNSIGNED_BYTE; switch ( drawInfo.attributes.color.descriptor.size / drawInfo.attributes.color.descriptor.components ) { case sizeof(uint8_t): colorType = GL_UNSIGNED_BYTE; break; case sizeof(float): colorType = GL_FLOAT; break; } + GL_ERROR_CHECK(glEnableClientState(GL_COLOR_ARRAY)); GL_ERROR_CHECK(glColorPointer(drawInfo.attributes.color.descriptor.components, colorType, drawInfo.attributes.color.stride, colorPtr)); + } else { + GL_ERROR_CHECK(glColor4f( 1, 1, 1, 1 )); } if ( drawInfo.textures.primary.image && drawInfo.attributes.uv.pointer ) { @@ -493,17 +492,25 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer:: GL_ERROR_CHECK(glVertexPointer(3, vertexType, vertexStride, vertexPtr)); } + GLenum mode = GL_TRIANGLES; + if ( drawInfo.descriptor.fill == uf::renderer::enums::PolygonMode::LINE ) { + mode = GL_LINES; + glLineWidth(drawInfo.descriptor.lineWidth); + } else { + glLineWidth(1.0f); + } + if ( drawInfo.descriptor.inputs.index.count ) { - GL_ERROR_CHECK(glDrawElements(GL_TRIANGLES, drawInfo.descriptor.inputs.index.count, indicesType, (static_cast(drawInfo.attributes.index.pointer) + drawInfo.attributes.index.stride * drawInfo.descriptor.inputs.index.first))); + GL_ERROR_CHECK(glDrawElements(mode, drawInfo.descriptor.inputs.index.count, indicesType, (static_cast(drawInfo.attributes.index.pointer) + drawInfo.attributes.index.stride * drawInfo.descriptor.inputs.index.first))); } else { #if 0 && UF_ENV_DREAMCAST // GLdc has a "regression" where glDrawArrays does not work // everything should be using indices anyways so this path shouldn't really ever be taken uf::stl::vector indices(drawInfo.descriptor.inputs.vertex.count); for ( auto i = 0; i < drawInfo.descriptor.inputs.vertex.count; ++i ) indices[i] = i; - GL_ERROR_CHECK(glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, indices.data())); + GL_ERROR_CHECK(glDrawElements(mode, indices.size(), GL_UNSIGNED_SHORT, indices.data())); #else - GL_ERROR_CHECK(glDrawArrays(GL_TRIANGLES, drawInfo.descriptor.inputs.vertex.first, drawInfo.descriptor.inputs.vertex.count)); + GL_ERROR_CHECK(glDrawArrays(mode, drawInfo.descriptor.inputs.vertex.first, drawInfo.descriptor.inputs.vertex.count)); #endif } diff --git a/engine/src/ext/opengl/graphic.cpp b/engine/src/ext/opengl/graphic.cpp index ad56facc..eb11ecbc 100644 --- a/engine/src/ext/opengl/graphic.cpp +++ b/engine/src/ext/opengl/graphic.cpp @@ -417,7 +417,7 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, const GraphicDe drawCommandInfoBase.color.pointer = &uniforms->color; drawCommandInfoBase.color.value = uniforms->color; - drawCommandInfoBase.color.enabled = true; // drawCommandInfoBase.color.value != pod::Vector4f{1.0f, 1.0f, 1.0f, 1.0f}; + drawCommandInfoBase.color.enabled = drawCommandInfoBase.color.value != pod::Vector4f{1.0f, 1.0f, 1.0f, 1.0f}; } struct { @@ -497,9 +497,13 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, const GraphicDe drawCommandInfo.blend.modeAlpha = material.modeAlpha; drawCommandInfo.blend.alphaCutoff = material.factorAlphaCutoff; - drawCommandInfo.color.value = object.color * material.colorBase; + drawCommandInfo.color.value = object.color * material.colorBase; // to-do: blend properly drawCommandInfo.color.enabled = drawCommandInfo.color.value != pod::Vector4f{1.0f, 1.0f, 1.0f, 1.0f}; + if ( drawCommandInfo.color.value.w == 0.0f ) { + continue; + } + if ( 0 <= textureID ) { auto texture2DID = textures[textureID].index; drawCommandInfo.textures.primary = this->material.textures.at(texture2DID).descriptor; @@ -510,8 +514,8 @@ void ext::opengl::Graphic::record( CommandBuffer& commandBuffer, const GraphicDe drawCommandInfo.textures.secondary = this->material.textures.at(texture2DID).descriptor; } switch ( drawCommandInfo.blend.modeAlpha ) { - case 0: drawCommandInfos.opaques.emplace_back(drawCommandInfo); break; - default: drawCommandInfos.translucents.emplace_back(drawCommandInfo); break; + case pod::Material::AlphaMode::BLEND: drawCommandInfos.translucents.emplace_back(drawCommandInfo); break; + default: drawCommandInfos.opaques.emplace_back(drawCommandInfo); break; } } } else { diff --git a/engine/src/ext/valve/common.cpp b/engine/src/ext/valve/common.cpp index 18ab1a98..9cced12e 100644 --- a/engine/src/ext/valve/common.cpp +++ b/engine/src/ext/valve/common.cpp @@ -34,6 +34,7 @@ size_t impl::addMaterial( pod::Graph& graph, const uf::stl::string& name, int32_ material.factorMetallic = 0.0f; material.factorRoughness = 1.0f; material.factorOcclusion = 1.0f; + material.factorAlphaCutoff = 0.0f; material.indexNormal = -1; material.indexEmissive = -1; material.indexMetallicRoughness = -1;