summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/31-rsm/reflectiveshadowmap.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/31-rsm/reflectiveshadowmap.cpp')
-rw-r--r--3rdparty/bgfx/examples/31-rsm/reflectiveshadowmap.cpp60
1 files changed, 33 insertions, 27 deletions
diff --git a/3rdparty/bgfx/examples/31-rsm/reflectiveshadowmap.cpp b/3rdparty/bgfx/examples/31-rsm/reflectiveshadowmap.cpp
index 8a0ca30a2d7..65dfe345c2e 100644
--- a/3rdparty/bgfx/examples/31-rsm/reflectiveshadowmap.cpp
+++ b/3rdparty/bgfx/examples/31-rsm/reflectiveshadowmap.cpp
@@ -1,6 +1,6 @@
/*
* Copyright 2016 Joseph Cherlin. All rights reserved.
- * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
+ * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#include <common.h>
@@ -105,7 +105,7 @@ static const float s_meshScale[] =
0.05f
};
-// Vertex decl for our screen space quad (used in deferred rendering)
+// Vertex layout for our screen space quad (used in deferred rendering)
struct PosTexCoord0Vertex
{
float m_x;
@@ -116,24 +116,24 @@ struct PosTexCoord0Vertex
static void init()
{
- ms_decl
+ ms_layout
.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
.end();
}
- static bgfx::VertexDecl ms_decl;
+ static bgfx::VertexLayout ms_layout;
};
-bgfx::VertexDecl PosTexCoord0Vertex::ms_decl;
+bgfx::VertexLayout PosTexCoord0Vertex::ms_layout;
// Utility function to draw a screen space quad for deferred rendering
void screenSpaceQuad(float _textureWidth, float _textureHeight, float _texelHalf, bool _originBottomLeft, float _width = 1.0f, float _height = 1.0f)
{
- if (3 == bgfx::getAvailTransientVertexBuffer(3, PosTexCoord0Vertex::ms_decl) )
+ if (3 == bgfx::getAvailTransientVertexBuffer(3, PosTexCoord0Vertex::ms_layout) )
{
bgfx::TransientVertexBuffer vb;
- bgfx::allocTransientVertexBuffer(&vb, 3, PosTexCoord0Vertex::ms_decl);
+ bgfx::allocTransientVertexBuffer(&vb, 3, PosTexCoord0Vertex::ms_layout);
PosTexCoord0Vertex* vertex = (PosTexCoord0Vertex*)vb.data;
const float minx = -_width;
@@ -186,8 +186,8 @@ void screenSpaceQuad(float _textureWidth, float _textureHeight, float _texelHalf
class ExampleRSM : public entry::AppI
{
public:
- ExampleRSM(const char* _name, const char* _description)
- : entry::AppI(_name, _description)
+ ExampleRSM(const char* _name, const char* _description, const char* _url)
+ : entry::AppI(_name, _description, _url)
, m_reading(0)
, m_currFrame(UINT32_MAX)
, m_cameraSpin(false)
@@ -211,6 +211,9 @@ public:
bgfx::Init init;
init.type = args.m_type;
init.vendorId = args.m_pciId;
+ init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle);
+ init.platformData.ndt = entry::getNativeDisplayHandle();
+ init.platformData.type = entry::getNativeWindowHandleType(entry::kDefaultWindowHandle);
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;
@@ -258,12 +261,12 @@ public:
u_rsmAmount = bgfx::createUniform("u_rsmAmount", bgfx::UniformType::Vec4); // How much RSM to use vs directional light
// Create texture sampler uniforms (used when we bind textures)
- s_normal = bgfx::createUniform("s_normal", bgfx::UniformType::Int1); // Normal gbuffer
- s_depth = bgfx::createUniform("s_depth", bgfx::UniformType::Int1); // Normal gbuffer
- s_color = bgfx::createUniform("s_color", bgfx::UniformType::Int1); // Color (albedo) gbuffer
- s_light = bgfx::createUniform("s_light", bgfx::UniformType::Int1); // Light buffer
- s_shadowMap = bgfx::createUniform("s_shadowMap", bgfx::UniformType::Int1); // Shadow map
- s_rsm = bgfx::createUniform("s_rsm", bgfx::UniformType::Int1); // Reflective shadow map
+ s_normal = bgfx::createUniform("s_normal", bgfx::UniformType::Sampler); // Normal gbuffer
+ s_depth = bgfx::createUniform("s_depth", bgfx::UniformType::Sampler); // Normal gbuffer
+ s_color = bgfx::createUniform("s_color", bgfx::UniformType::Sampler); // Color (albedo) gbuffer
+ s_light = bgfx::createUniform("s_light", bgfx::UniformType::Sampler); // Light buffer
+ s_shadowMap = bgfx::createUniform("s_shadowMap", bgfx::UniformType::Sampler); // Shadow map
+ s_rsm = bgfx::createUniform("s_rsm", bgfx::UniformType::Sampler); // Reflective shadow map
// Create program from shaders.
m_gbufferProgram = loadProgram("vs_rsm_gbuffer", "fs_rsm_gbuffer"); // Gbuffer
@@ -311,10 +314,9 @@ public:
| BGFX_SAMPLER_V_CLAMP
;
- // Make gbuffer and related textures
m_gbufferTex[GBUFFER_RT_NORMAL] = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::BGRA8, tsFlags);
m_gbufferTex[GBUFFER_RT_COLOR] = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::BGRA8, tsFlags);
- m_gbufferTex[GBUFFER_RT_DEPTH] = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::D24, tsFlags);
+ m_gbufferTex[GBUFFER_RT_DEPTH] = bgfx::createTexture2D(bgfx::BackbufferRatio::Equal, false, 1, bgfx::TextureFormat::D32F, tsFlags);
m_gbuffer = bgfx::createFrameBuffer(BX_COUNTOF(m_gbufferTex), m_gbufferTex, true);
// Make light buffer
@@ -351,21 +353,20 @@ public:
, false
, 1
, bgfx::TextureFormat::D16
- , BGFX_TEXTURE_RT /* | BGFX_TEXTURE_COMPARE_LEQUAL*/
- ); // Note I'm not setting BGFX_TEXTURE_COMPARE_LEQUAL. Why?
+ , BGFX_TEXTURE_RT /* | BGFX_SAMPLER_COMPARE_LEQUAL*/
+ ); // Note I'm not setting BGFX_SAMPLER_COMPARE_LEQUAL. Why?
// Normally a PCF shadow map such as this requires a compare. However, this sample also
- // reads from this texture in the lighting pass, and only uses the PCF capabilites in the
- // combine pass, so the flag is disabled by default.
+ // reads from this texture in the lighting pass, and only uses the PCF capabilities in
+ // the combine pass, so the flag is disabled by default.
m_shadowBuffer = bgfx::createFrameBuffer(BX_COUNTOF(m_shadowBufferTex), m_shadowBufferTex, true);
- // Vertex decl
+ // Vertex layout
PosTexCoord0Vertex::init();
// Init camera
cameraCreate();
- float camPos[] = {0.0f, 1.5f, 0.0f};
- cameraSetPosition(camPos);
+ cameraSetPosition({0.0f, 1.5f, 0.0f});
cameraSetVerticalAngle(-0.3f);
// Init directional light
@@ -448,7 +449,7 @@ public:
const float deltaTime = float(frameTime/freq);
// Update camera
- cameraUpdate(deltaTime*0.15f, m_mouseState);
+ cameraUpdate(deltaTime*0.15f, m_mouseState, ImGui::MouseOverArea() );
// Set up matrices for gbuffer
float view[16];
@@ -476,7 +477,7 @@ public:
lightAt[1] = 0.0f;
lightAt[2] = 0.0f;
- bx::mtxLookAt(smView, bx::load(lightEye), bx::load(lightAt) );
+ bx::mtxLookAt(smView, bx::load<bx::Vec3>(lightEye), bx::load<bx::Vec3>(lightAt) );
const float area = 10.0f;
const bgfx::Caps* caps = bgfx::getCaps();
bx::mtxOrtho(smProj, -area, area, -area, area, -100.0f, 100.0f, 0.0f, caps->homogeneousDepth);
@@ -759,4 +760,9 @@ public:
} // namespace
-ENTRY_IMPLEMENT_MAIN(ExampleRSM, "31-rsm", "Global Illumination with Reflective Shadow Map.");
+ENTRY_IMPLEMENT_MAIN(
+ ExampleRSM
+ , "31-rsm"
+ , "Global Illumination with Reflective Shadow Map."
+ , "https://bkaradzic.github.io/bgfx/examples.html#rsm"
+ );