From 4c9a0ec2400dc05cbd63b30d20d1dd5e0a93f73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 16 Mar 2015 16:48:46 -0700 Subject: [PATCH] Added 3D texture test to 08-update example. --- examples/08-update/fs_update_3d.sc | 17 +++++ examples/08-update/update.cpp | 67 ++++++++++++++++-- .../runtime/shaders/dx11/fs_update_3d.bin | Bin 0 -> 489 bytes examples/runtime/shaders/dx9/fs_update_3d.bin | Bin 0 -> 410 bytes .../runtime/shaders/gles/fs_update_3d.bin | Bin 0 -> 374 bytes .../runtime/shaders/glsl/fs_update_3d.bin | Bin 0 -> 306 bytes 6 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 examples/08-update/fs_update_3d.sc create mode 100644 examples/runtime/shaders/dx11/fs_update_3d.bin create mode 100644 examples/runtime/shaders/dx9/fs_update_3d.bin create mode 100644 examples/runtime/shaders/gles/fs_update_3d.bin create mode 100644 examples/runtime/shaders/glsl/fs_update_3d.bin diff --git a/examples/08-update/fs_update_3d.sc b/examples/08-update/fs_update_3d.sc new file mode 100644 index 00000000..dad87e9c --- /dev/null +++ b/examples/08-update/fs_update_3d.sc @@ -0,0 +1,17 @@ +$input v_texcoord0 + +/* + * Copyright 2011-2015 Branimir Karadzic. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#include "../common/common.sh" + +SAMPLER3D(u_texColor, 0); +uniform float u_time; + +void main() +{ + vec3 uvw = vec3(v_texcoord0.xy*0.5+0.5, sin(u_time)*0.5+0.5); + gl_FragColor = vec4_splat(texture3D(u_texColor, uvw).x); +} diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index 0ed14fa3..45ecad89 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -149,6 +149,31 @@ int _main_(int /*_argc*/, char** /*_argv*/) loadTexture("texture_compression_ptc24.pvr"), }; + const bgfx::Memory* mem8 = bgfx::alloc(32*32*32); + const bgfx::Memory* mem16f = bgfx::alloc(32*32*32*2); + const bgfx::Memory* mem32f = bgfx::alloc(32*32*32*4); + for (uint8_t zz = 0; zz < 32; ++zz) + { + for (uint8_t yy = 0; yy < 32; ++yy) + { + for (uint8_t xx = 0; xx < 32; ++xx) + { + const uint32_t offset = ( (zz*32+yy)*32+xx); + const uint32_t val = xx ^ yy ^ zz; + mem8->data[offset] = val<<3; + *(uint16_t*)&mem16f->data[offset*2] = bx::halfFromFloat( (float)val/32.0f); + *(float*)&mem32f->data[offset*4] = (float)val/32.0f; + } + } + } + + bgfx::TextureHandle textures3d[] = + { + bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R8, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem8), + bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R16F, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem16f), + bgfx::createTexture3D(32, 32, 32, 0, bgfx::TextureFormat::R32F, BGFX_TEXTURE_U_CLAMP|BGFX_TEXTURE_V_CLAMP|BGFX_TEXTURE_W_CLAMP, mem32f), + }; + // Create static vertex buffer. bgfx::VertexBufferHandle vbh = bgfx::createVertexBuffer(bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) ), PosTexcoordVertex::ms_decl); @@ -156,12 +181,14 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::IndexBufferHandle ibh = bgfx::createIndexBuffer(bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) ) ); // Create texture sampler uniforms. - bgfx::UniformHandle u_texCube = bgfx::createUniform("u_texCube", bgfx::UniformType::Uniform1iv); - + bgfx::UniformHandle u_texCube = bgfx::createUniform("u_texCube", bgfx::UniformType::Uniform1iv); bgfx::UniformHandle u_texColor = bgfx::createUniform("u_texColor", bgfx::UniformType::Uniform1iv); - bgfx::ProgramHandle program = loadProgram("vs_update", "fs_update"); - bgfx::ProgramHandle programCmp = loadProgram("vs_update", "fs_update_cmp"); + bgfx::UniformHandle u_time = bgfx::createUniform("u_time", bgfx::UniformType::Uniform1f); + + bgfx::ProgramHandle program = loadProgram("vs_update", "fs_update"); + bgfx::ProgramHandle programCmp = loadProgram("vs_update", "fs_update_cmp"); + bgfx::ProgramHandle program3d = loadProgram("vs_update", "fs_update_3d"); const uint32_t textureSide = 2048; @@ -210,6 +237,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) const int64_t freq = bx::getHPFrequency(); const double toMs = 1000.0/double(freq); float time = (float)( (now - timeOffset)/double(bx::getHPFrequency() ) ); + bgfx::setUniform(u_time, &time); // Use debug font to print information about this example. bgfx::dbgTextClear(); @@ -345,10 +373,11 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Submit primitive for rendering to view 1. bgfx::submit(1); + const float xpos = -8.0f - BX_COUNTOF(textures)*0.1f*0.5f; for (uint32_t ii = 0; ii < BX_COUNTOF(textures); ++ii) { - bx::mtxTranslate(mtx, -8.0f - BX_COUNTOF(textures)*0.1f*0.5f + ii*2.1f, 4.0f, 0.0f); + bx::mtxTranslate(mtx, xpos + ii*2.1f, 4.0f, 0.0f); // Set model matrix for rendering. bgfx::setTransform(mtx); @@ -370,9 +399,33 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::submit(1); } + for (uint32_t ii = 0; ii < BX_COUNTOF(textures3d); ++ii) + { + bx::mtxTranslate(mtx, xpos + ii*2.1f, -4.0f, 0.0f); + + // Set model matrix for rendering. + bgfx::setTransform(mtx); + + // Set vertex and fragment shaders. + bgfx::setProgram(program3d); + + // Set vertex and index buffer. + bgfx::setVertexBuffer(vbh); + bgfx::setIndexBuffer(ibh, 0, 6); + + // Bind texture. + bgfx::setTexture(0, u_texColor, textures3d[ii]); + + // Set render states. + bgfx::setState(BGFX_STATE_DEFAULT); + + // Submit primitive for rendering to view 1. + bgfx::submit(1); + } + for (uint32_t ii = 0; ii < 3; ++ii) { - bx::mtxTranslate(mtx, -8.0f - BX_COUNTOF(textures)*0.1f*0.5f + 8*2.1f, -4.0f + ii*2.1f, 0.0f); + bx::mtxTranslate(mtx, xpos + 8*2.1f, -4.0f + ii*2.1f, 0.0f); // Set model matrix for rendering. bgfx::setTransform(mtx); @@ -416,8 +469,10 @@ int _main_(int /*_argc*/, char** /*_argv*/) bgfx::destroyTexture(textureCube); bgfx::destroyIndexBuffer(ibh); bgfx::destroyVertexBuffer(vbh); + bgfx::destroyProgram(program3d); bgfx::destroyProgram(programCmp); bgfx::destroyProgram(program); + bgfx::destroyUniform(u_time); bgfx::destroyUniform(u_texColor); bgfx::destroyUniform(u_texCube); diff --git a/examples/runtime/shaders/dx11/fs_update_3d.bin b/examples/runtime/shaders/dx11/fs_update_3d.bin new file mode 100644 index 0000000000000000000000000000000000000000..e73f85355effce657ff52cfa7330bb23e820f9d1 GIT binary patch literal 489 zcmYjNy-LGi6g^35twCrICkM&k;GiHK#6g!1Mh?ym0Ql-#zF4BvID2uGX9T2C6sX*~R5_6&tpJHzORj0?+y$oqqm& zRBEqZcW2wIgA8CXZV?Z}3lV3XUZ2qQ~tgk`xjngG-&_; literal 0 HcmV?d00001 diff --git a/examples/runtime/shaders/dx9/fs_update_3d.bin b/examples/runtime/shaders/dx9/fs_update_3d.bin new file mode 100644 index 0000000000000000000000000000000000000000..08c745a4e7fc99dda362bfb965478fcb5e3b4547 GIT binary patch literal 410 zcmYjN%SyvQ6g|_Vl8t1cOVJ<*x-gg)7Xhi-h*YSc#;l`gq=A+xeL#1P_yhfftnE*@ z^&7g)Pq;CjNfdgMlY8f!`MyKFbIJfZs@f=5IT>o&?B_5dol}TUyiUau})1tl~t3m(4AKK;W%!_N4QR( zMsh4)CeHrdfz#=RT_@~4J|`n5kb_~`XW+XH-}R3hZqxHT+yZq0JA41$ZE?cs(*8PI z+E<@DT&oT!&YA0&S_aF`xCdiH3FMgx@Dk hi!`W5Syf|D&*%SKyZmjo<`k@)dECL$XQ-m!_ZMHcN?`y1 literal 0 HcmV?d00001 diff --git a/examples/runtime/shaders/gles/fs_update_3d.bin b/examples/runtime/shaders/gles/fs_update_3d.bin new file mode 100644 index 0000000000000000000000000000000000000000..636d67fcb2106efddc7bf7fcc6cff61c8e73903a GIT binary patch literal 374 zcmZWl-EM*~6h@bL(T6bS5}YBZ+ZCHPTgZ0p1CT~5HfcGe0>X^%?rD*LS=03A^!qtq zlikk?&bJ>^k5y?YnlDsnyopD1Mg^(G#9e-At+{Dsp210GrvhrR-#~3Sdqi`HVpiqy zh(?3LO95xD3nk3v8wTA0(n%Z@^3uMOP0VVP2hd#R;0Nr=VC+-sg51+pOy&L@HZ6RD z?~i)0r3FOcdjPL)d&2)Y_*v$DXBqs*y4ES#Tko VSWc$W#PH1hr{#44Nbbg%cL$L-a~1#q literal 0 HcmV?d00001 diff --git a/examples/runtime/shaders/glsl/fs_update_3d.bin b/examples/runtime/shaders/glsl/fs_update_3d.bin new file mode 100644 index 0000000000000000000000000000000000000000..0dd12aaa48eb9a42fa8e73c6068f4f88e6fe40f2 GIT binary patch literal 306 zcmZWl%MOAt5Cn}L`VnT2poU^8cb zr)qK7O)OH!6>E