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
Binary file added assets/meshes/checkerboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 118 additions & 0 deletions assets/meshes/textured_quad.dae
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
<asset>
<up_axis>Z_UP</up_axis>
</asset>

<library_images>
<image id="checkerboard-img" name="checkerboard">
<init_from>checkerboard.png</init_from>
</image>
</library_images>

<library_effects>
<effect id="checkerboard-effect">
<profile_COMMON>
<newparam sid="checkerboard-surface">
<surface type="2D">
<init_from>checkerboard-img</init_from>
</surface>
</newparam>
<newparam sid="checkerboard-sampler">
<sampler2D>
<source>checkerboard-surface</source>
</sampler2D>
</newparam>
<technique sid="common">
<phong>
<diffuse>
<texture texture="checkerboard-sampler" texcoord="UVMap"/>
</diffuse>
</phong>
</technique>
</profile_COMMON>
</effect>
</library_effects>

<library_materials>
<material id="checkerboard-mat" name="Checkerboard">
<instance_effect url="#checkerboard-effect"/>
</material>
</library_materials>

<library_geometries>
<geometry id="quad-mesh" name="Quad">
<mesh>
<!-- 4 vertices: unit quad in XY plane -->
<source id="quad-positions">
<float_array id="quad-positions-array" count="12">
-1 -1 0 1 -1 0 1 1 0 -1 1 0
</float_array>
<technique_common>
<accessor source="#quad-positions-array" count="4" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>

<source id="quad-normals">
<float_array id="quad-normals-array" count="3">0 0 1</float_array>
<technique_common>
<accessor source="#quad-normals-array" count="1" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>

<!-- UVs: (0,0) bottom-left to (1,1) top-right (OpenGL convention) -->
<source id="quad-uvs">
<float_array id="quad-uvs-array" count="8">
0 0 1 0 1 1 0 1
</float_array>
<technique_common>
<accessor source="#quad-uvs-array" count="4" stride="2">
<param name="S" type="float"/>
<param name="T" type="float"/>
</accessor>
</technique_common>
</source>

<vertices id="quad-vertices">
<input semantic="POSITION" source="#quad-positions"/>
</vertices>

<!-- Two triangles forming the quad -->
<triangles material="checkerboard-mat" count="2">
<input semantic="VERTEX" source="#quad-vertices" offset="0"/>
<input semantic="NORMAL" source="#quad-normals" offset="1"/>
<input semantic="TEXCOORD" source="#quad-uvs" offset="2" set="0"/>
<p>0 0 0 1 0 1 2 0 2 0 0 0 2 0 2 3 0 3</p>
</triangles>
</mesh>
</geometry>
</library_geometries>

<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="Quad" name="Quad" type="NODE">
<instance_geometry url="#quad-mesh">
<bind_material>
<technique_common>
<instance_material symbol="checkerboard-mat" target="#checkerboard-mat">
<bind_vertex_input semantic="UVMap" input_semantic="TEXCOORD" input_set="0"/>
</instance_material>
</technique_common>
</bind_material>
</instance_geometry>
</node>
</visual_scene>
</library_visual_scenes>

<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>
1 change: 1 addition & 0 deletions examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_candlewick_example(Triangle.cpp)
add_candlewick_example(ColoredCube.cpp)
add_candlewick_example(MeshNormalsRgb.cpp)
add_candlewick_example(LitMesh.cpp)
add_candlewick_example(TexturedMesh.cpp)
if(BUILD_PINOCCHIO_VISUALIZER)
add_candlewick_example(
Ur5WithSystems.cpp
Expand Down
17 changes: 17 additions & 0 deletions examples/cpp/LitMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "candlewick/core/Shader.h"
#include "candlewick/utils/MeshData.h"
#include "candlewick/utils/LoadMesh.h"
#include "candlewick/utils/LoadTexture.h"
#include "candlewick/core/CameraControls.h"
#include "candlewick/core/LightUniforms.h"
#include "candlewick/core/TransformUniforms.h"
Expand Down Expand Up @@ -141,6 +142,13 @@ int main() {
.intensity = 4.0,
};

// Load base color texture (fallback to white for untextured meshes)
Texture baseColorTex = meshDatas[0].baseColorTexturePath.empty()
? createWhiteTexture(device)
: loadTextureFromFile(
device, meshDatas[0].baseColorTexturePath.c_str());
SDL_GPUSampler *materialSampler = createMaterialSampler(device);

while (frameNo < 1000 && !quitRequested) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
Expand Down Expand Up @@ -229,6 +237,13 @@ int main() {
.pushFragmentUniform(0u, materialUbo)
.pushFragmentUniform(1u, lightUbo);

// Bind base color texture
rend::bindFragmentSamplers(render_pass, 2u,
{{
.texture = baseColorTex,
.sampler = materialSampler,
}});

rend::draw(render_pass, meshes[0]);

SDL_EndGPURenderPass(render_pass);
Expand All @@ -242,6 +257,8 @@ int main() {
for (auto &mesh : meshes) {
mesh.release();
}
baseColorTex.destroy();
SDL_ReleaseGPUSampler(device, materialSampler);
pipeline.release();
ctx.destroy();
SDL_Quit();
Expand Down
Loading
Loading