Refactored uniform types.

This commit is contained in:
Branimir Karadžić
2015-05-28 15:27:00 -07:00
parent 4bd29facd0
commit ff01992cb7
717 changed files with 637 additions and 728 deletions

View File

@@ -15,9 +15,11 @@ $input v_color0, v_texcoord0
#include "../common/common.sh"
#include "iq_sdf.sh"
uniform float u_time;
uniform mat4 u_mtx;
uniform vec3 u_lightDir;
uniform vec4 u_lightDirTime;
#define u_lightDir u_lightDirTime.xyz
#define u_time u_lightDirTime.w
float sceneDist(vec3 _pos)
{

View File

@@ -124,7 +124,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
, 0
);
// Setup root path for binary shaders. Shader binaries are different
// Setup root path for binary shaders. Shader binaries are different
// for each renderer.
switch (bgfx::getRendererType() )
{
@@ -140,9 +140,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Create vertex stream declaration.
PosColorTexCoord0Vertex::init();
bgfx::UniformHandle u_time = bgfx::createUniform("u_time", bgfx::UniformType::Uniform1f);
bgfx::UniformHandle u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Uniform4x4fv);
bgfx::UniformHandle u_lightDir = bgfx::createUniform("u_lightDir", bgfx::UniformType::Uniform3fv);
bgfx::UniformHandle u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Mat4);
bgfx::UniformHandle u_lightDirTime = bgfx::createUniform("u_lightDirTime", bgfx::UniformType::Vec4);
// Create program from shaders.
bgfx::ProgramHandle raymarching = loadProgram("vs_raymarching", "fs_raymarching");
@@ -176,7 +175,7 @@ int _main_(int /*_argc*/, char** /*_argv*/)
float at[3] = { 0.0f, 0.0f, 0.0f };
float eye[3] = { 0.0f, 0.0f, -15.0f };
float view[16];
float proj[16];
bx::mtxLookAt(view, eye, at);
@@ -200,16 +199,17 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bx::mtxRotateXY(mtx
, time
, time*0.37f
);
);
float mtxInv[16];
bx::mtxInverse(mtxInv, mtx);
float lightDirModel[4] = { -0.4f, -0.5f, -1.0f, 0.0f };
float lightDirModelN[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
bx::vec3Norm(lightDirModelN, lightDirModel);
float lightDir[4];
bx::vec4MulMtx(lightDir, lightDirModelN, mtxInv);
bgfx::setUniform(u_lightDir, lightDir);
float lightDirTime[4];
bx::vec4MulMtx(lightDirTime, lightDirModelN, mtxInv);
lightDirTime[3] = time;
bgfx::setUniform(u_lightDirTime, lightDirTime);
float mvp[16];
bx::mtxMul(mvp, mtx, vp);
@@ -218,11 +218,9 @@ int _main_(int /*_argc*/, char** /*_argv*/)
bx::mtxInverse(invMvp, mvp);
bgfx::setUniform(u_mtx, invMvp);
bgfx::setUniform(u_time, &time);
renderScreenSpaceQuad(1, raymarching, 0.0f, 0.0f, 1280.0f, 720.0f);
// Advance to next frame. Rendering thread will be kicked to
// Advance to next frame. Rendering thread will be kicked to
// process submitted rendering primitives.
bgfx::frame();
}
@@ -230,9 +228,8 @@ int _main_(int /*_argc*/, char** /*_argv*/)
// Cleanup.
bgfx::destroyProgram(raymarching);
bgfx::destroyUniform(u_time);
bgfx::destroyUniform(u_mtx);
bgfx::destroyUniform(u_lightDir);
bgfx::destroyUniform(u_lightDirTime);
// Shutdown bgfx.
bgfx::shutdown();