Skip to content

Commit

Permalink
Improve positions of the textures in 08-update. Scan through the LODs…
Browse files Browse the repository at this point in the history
… of the textures with shader.
  • Loading branch information
mcourteaux committed Jun 14, 2024
1 parent 9547e79 commit 9b40283
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion examples/08-update/fs_update.sc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ $input v_texcoord0
#include "../common/common.sh"

SAMPLERCUBE(s_texCube, 0);
uniform vec4 u_time;

void main()
{
gl_FragColor = textureCube(s_texCube, v_texcoord0);
float lod = (1.0 - cos(u_time.x)) * 4.0; // 0 to 8
gl_FragColor = textureCubeLod(s_texCube, v_texcoord0, lod);
}
5 changes: 4 additions & 1 deletion examples/08-update/fs_update_cmp.sc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ $input v_texcoord0

SAMPLER2D(s_texColor, 0);

uniform vec4 u_time;

void main()
{
gl_FragColor = texture2D(s_texColor, v_texcoord0.xy*0.5+0.5);
float lod = (1.0 - cos(u_time.x)) * 4.0; // 0 to 8
gl_FragColor = texture2DLod(s_texColor, v_texcoord0.xy*0.5+0.5, lod);
}
8 changes: 4 additions & 4 deletions examples/08-update/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ class ExampleUpdate : public entry::AppI
if (bgfx::isValid(m_textureCube[ii]))
{
float mtx[16];
bx::mtxSRT(mtx, 0.65f, 0.65f, 0.65f, time, time*0.37f, 0.0f, -2.5f +ii*1.8f, 0.0f, 0.0f);
bx::mtxSRT(mtx, 0.65f, 0.65f, 0.65f, time, time*0.37f, 0.0f, -2.5f +ii*1.8f, 0.3f, 0.0f);

// Set model matrix for rendering.
bgfx::setTransform(mtx);
Expand All @@ -788,7 +788,7 @@ class ExampleUpdate : public entry::AppI

const float aspectRatio = float(m_height)/float(m_width);
const float margin = 0.7f;
const float sizeX = 0.5f * numColumns * 2.3f + margin;
const float sizeX = 0.5f * (numColumns + 2) * 2.3f + margin;
const float sizeY = sizeX * aspectRatio;

const bgfx::Caps* caps = bgfx::getCaps();
Expand All @@ -798,7 +798,7 @@ class ExampleUpdate : public entry::AppI
bx::mtxMul(worldToScreen, proj, projToScreen);

float mtx[16];
bx::mtxTranslate(mtx, -sizeX + margin + 1.0f, 1.9f, 0.0f);
bx::mtxTranslate(mtx, -sizeX + margin + 1.0f, 0.0f, 0.0f);

// Set model matrix for rendering.
bgfx::setTransform(mtx);
Expand Down Expand Up @@ -851,7 +851,7 @@ class ExampleUpdate : public entry::AppI

for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii)
{
bx::mtxTranslate(mtx, xpos + (ii%numColumns) * 2.3f, sizeY - margin - 2.8f + (ii/numColumns) * 2.3f, 0.0f);
bx::mtxTranslate(mtx, xpos + (1+ii%numColumns) * 2.3f, sizeY - margin - 2.8f + (ii/numColumns) * 2.3f, 0.0f);

// Set model matrix for rendering.
bgfx::setTransform(mtx);
Expand Down

0 comments on commit 9b40283

Please sign in to comment.