Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/scene_renderer/shaders/DebugMaterial.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define ENABLE_VTX_ATTR_TEXCOORD
#define ENABLE_VTX_ATTR_NORMAL
#define ENABLE_VTX_ATTR_TANGENT
#define ENABLE_VTX_ATTR_COLOR

#include "MaterialInterface.hlsli"

Expand All @@ -35,6 +36,9 @@ float4 psmain(StandardVertexOutput input) : SV_TARGET
else if(Draw.dbgVtxAttrIndex == DBG_VTX_ATTR_INDEX_TANGENT) {
color = mul(Instances[Draw.instanceIndex].modelMatrix, float4(input.Tangent.xyz, 0)).xyz;
}
else if(Draw.dbgVtxAttrIndex == DBG_VTX_ATTR_INDEX_COLOR) {
color = input.Color;
}

return float4(normalize(color), 1);
}
1 change: 1 addition & 0 deletions assets/scene_renderer/shaders/MaterialInterface.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct DrawParams {
#define DBG_VTX_ATTR_INDEX_TEXCOORD 1
#define DBG_VTX_ATTR_INDEX_NORMAL 2
#define DBG_VTX_ATTR_INDEX_TANGENT 3
#define DBG_VTX_ATTR_INDEX_COLOR 4

#if defined(__spirv__)
[[vk::push_constant]]
Expand Down
2 changes: 2 additions & 0 deletions assets/scene_renderer/shaders/MaterialVertex.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define ENABLE_VTX_ATTR_TEXCOORD
#define ENABLE_VTX_ATTR_NORMAL
#define ENABLE_VTX_ATTR_TANGENT
#define ENABLE_VTX_ATTR_COLOR
#include "MaterialInterface.hlsli"

StandardVertexOutput vsmain(StandardVertexInput input)
Expand All @@ -29,5 +30,6 @@ StandardVertexOutput vsmain(StandardVertexInput input)
output.TexCoord = input.TexCoord;
output.Normal = input.Normal;
output.Tangent = input.Tangent;
output.Color = input.Color;
return output;
}
2 changes: 2 additions & 0 deletions assets/scene_renderer/shaders/StandardMaterial.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define ENABLE_VTX_ATTR_TEXCOORD
#define ENABLE_VTX_ATTR_NORMAL
#define ENABLE_VTX_ATTR_TANGENT
#define ENABLE_VTX_ATTR_COLOR
#include "MaterialInterface.hlsli"

#include "ppx/PBR.hlsli"
Expand Down Expand Up @@ -46,6 +47,7 @@ float4 psmain(StandardVertexOutput input) : SV_TARGET

baseColor = baseColor * float4(RemoveGamma(color.rgb, 2.2), color.a);
}
baseColor.rgb *= input.Color;

// Metal/roughness
float metallic = material.metallicFactor;
Expand Down
2 changes: 2 additions & 0 deletions assets/scene_renderer/shaders/UnlitMaterial.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define ENABLE_VTX_ATTR_TEXCOORD
#define ENABLE_VTX_ATTR_NORMAL
#define ENABLE_VTX_ATTR_TANGENT
#define ENABLE_VTX_ATTR_COLOR
#include "MaterialInterface.hlsli"

// -------------------------------------------------------------------------------------------------
Expand All @@ -38,6 +39,7 @@ float4 psmain(StandardVertexOutput input) : SV_TARGET
float4 value = tex.Sample(sam, uv);
color = color * value;
}
color.rgb *= input.Color;

return color;
}
14 changes: 13 additions & 1 deletion src/ppx/scene/scene_gltf_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1658,12 +1658,24 @@ ppx::Result GltfLoader::LoadMeshData(
std::vector<glm::float3> colors;
if (loadParams.requiredVertexAttributes.bits.colors && !IsNull(gltflAccessors.pColors)) {
PPX_ASSERT_MSG((colorFormat == targetColorFormat), "GLTF: vertex colors format is not supported");
colors = UnpackFloat3s(*gltflAccessors.pColors);
if (gltflAccessors.pColors->type == cgltf_type_vec3) {
colors = UnpackFloat3s(*gltflAccessors.pColors);
}
else if (gltflAccessors.pColors->type == cgltf_type_vec4) {
auto colors4 = UnpackFloat4s(*gltflAccessors.pColors);
for (auto& c : colors4) {
colors.push_back(glm::float3(c.r, c.g, c.b));
}
}
else {
PPX_ASSERT_MSG(false, "GLTF: vertex colors format must be VEC3 or VEC4");
}
}

// Process vertex data
for (cgltf_size i = 0; i < gltflAccessors.pPositions->count; ++i) {
TriMeshVertexData vertexData = {};
vertexData.color = glm::float3(1, 1, 1);

vertexData.position = positions[i];
if (loadParams.requiredVertexAttributes.bits.normals && !normals.empty()) {
Expand Down