Browse Source

Render+Asset: Fix derived Renderer2D, fix Skybox uniform

master
Riyyi 4 months ago
parent
commit
cc33b5d481
  1. 4
      assets/glsl/batch-cubemap.vert
  2. 3
      assets/glsl/lightsource.frag
  3. 23
      src/inferno/render/renderer.cpp
  4. 25
      src/inferno/render/renderer.h

4
assets/glsl/batch-cubemap.vert

@ -8,7 +8,7 @@ out vec4 v_color;
out vec3 v_textureCoordinates;
out flat uint v_textureIndex;
uniform mat4 u_projectionView2;
uniform mat4 u_projectionView;
void main()
{
@ -16,5 +16,5 @@ void main()
v_textureCoordinates = a_position;
v_textureIndex = a_textureIndex;
// Vclip = Camera projection * Camera view * Model transform * Vlocal
gl_Position = u_projectionView2 * vec4(a_position, 1.0f);
gl_Position = u_projectionView * vec4(a_position, 1.0f);
}

3
assets/glsl/lightsource.frag

@ -10,5 +10,8 @@ uniform samplerCube u_textures[32];
void main()
{
// Prevent u_textures variable from getting optimized away
if (texture(u_textures[0], vec3(0.0f)).x > 99999.0f) { discard; }
color = v_color;
}

23
src/inferno/render/renderer.cpp

@ -283,7 +283,7 @@ void Renderer2D::drawQuad(const TransformComponent& transform, glm::mat4 color,
void Renderer2D::loadShader()
{
m_shader = AssetManager::the().load<Shader>("assets/glsl/post-process");
m_shader = AssetManager::the().load<Shader>("assets/glsl/batch-2d");
}
// -----------------------------------------
@ -371,10 +371,10 @@ void RendererCubemap::beginScene(glm::mat4 cameraProjection, glm::mat4 cameraVie
// x x x 0
// x x x 0
// 0 0 0 1
// cameraView = glm::mat4(glm::mat3(cameraView));
cameraView = glm::mat4(glm::mat3(cameraView));
m_shader->bind();
m_shader->setFloat("u_projectionView2", cameraProjection * cameraView);
m_shader->setFloat("u_projectionView", cameraProjection * cameraView);
m_shader->unbind();
}
@ -594,6 +594,13 @@ void Renderer3D::startBatch()
// -----------------------------------------
RendererPostProcess::RendererPostProcess(s)
{
Renderer2D::initialize();
ruc::info("RendererPostProcess initialized");
}
RendererPostProcess::~RendererPostProcess()
{
}
@ -627,12 +634,20 @@ void RendererPostProcess::drawQuad(const TransformComponent& transform, std::sha
void RendererPostProcess::loadShader()
{
ruc::error("POSTPROCESSING!");
m_shader = AssetManager::the().load<Shader>("assets/glsl/post-process");
}
// -----------------------------------------
RendererLightCube::RendererLightCube(s)
{
RendererCubemap::initialize();
m_enableDepthBuffer = true;
ruc::info("RendererLightCube initialized");
}
RendererLightCube::~RendererLightCube()
{
}

25
src/inferno/render/renderer.h

@ -143,7 +143,7 @@ public:
void drawQuad(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture);
protected:
Renderer2D() { Renderer2D::initialize(); } // Needed for derived classes
Renderer2D() {} // Needed for derived classes
void initialize();
@ -173,7 +173,7 @@ public:
void drawCubemap(const TransformComponent& transform, glm::mat4 color, std::shared_ptr<Texture> texture);
protected:
RendererCubemap() { RendererCubemap::initialize(); } // Needed for derived classes
RendererCubemap() {} // Needed for derived classes
void initialize();
@ -232,15 +232,13 @@ class RendererPostProcess final
: public Renderer2D
, public ruc::Singleton<RendererPostProcess> {
public:
RendererPostProcess(ruc::Singleton<RendererPostProcess>::s)
: Renderer2D()
{
}
virtual ~RendererPostProcess();
using Singleton<RendererPostProcess>::s;
using Singleton<RendererPostProcess>::the;
using Singleton<RendererPostProcess>::destroy;
RendererPostProcess(s);
virtual ~RendererPostProcess();
void drawQuad(const TransformComponent& transform, std::shared_ptr<Texture> albedo, std::shared_ptr<Texture> position, std::shared_ptr<Texture> normal);
private:
@ -253,16 +251,13 @@ class RendererLightCube final
: public RendererCubemap
, public ruc::Singleton<RendererLightCube> {
public:
RendererLightCube(ruc::Singleton<RendererLightCube>::s)
: RendererCubemap()
{
m_enableDepthBuffer = true;
}
virtual ~RendererLightCube();
using Singleton<RendererLightCube>::s;
using Singleton<RendererLightCube>::the;
using Singleton<RendererLightCube>::destroy;
RendererLightCube(s);
virtual ~RendererLightCube();
void beginScene(glm::mat4, glm::mat4) override {}
private:

Loading…
Cancel
Save