Ice refractions and reflections added back in !
This commit is contained in:
parent
4be70e132d
commit
4cba6ad37e
@ -29,10 +29,10 @@ void main()
|
|||||||
vec4 reflections = vec4(texture(skybox,R).rgb, 1.0);
|
vec4 reflections = vec4(texture(skybox,R).rgb, 1.0);
|
||||||
|
|
||||||
// Refractive shading
|
// Refractive shading
|
||||||
float ratio = air_ri/diamond_ri;
|
float ratio = air_ri/Ice_ri;
|
||||||
vec3 I2 = normalize(Position-cameraPos);
|
vec3 I2 = normalize(Position-cameraPos);
|
||||||
vec3 R2 = refract(I2, normalize(Normal), ratio);
|
vec3 R2 = refract(I2, normalize(Normal), ratio);
|
||||||
vec4 refractions = vec4(texture(skybox, R2).rgb, 1.0);
|
vec4 refractions = vec4(texture(skybox, R2).rgb, 1.0);
|
||||||
|
|
||||||
FragColor = vec4(albeno.rgb + (refractions.rgb * 0.5) + (reflections.rgb * 0.8), 1.0);
|
FragColor = vec4(albeno.rgb + (refractions.rgb * 1.0) + (reflections.rgb * 0.0), 1.0);
|
||||||
}
|
}
|
@ -6,4 +6,5 @@ struct Material {
|
|||||||
glm::vec3 diffuse;
|
glm::vec3 diffuse;
|
||||||
glm::vec3 specular;
|
glm::vec3 specular;
|
||||||
float shininess;
|
float shininess;
|
||||||
|
|
||||||
};
|
};
|
@ -10,10 +10,18 @@
|
|||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
#include "../Primitives/Scene.h"
|
#include "../Primitives/Scene.h"
|
||||||
|
static enum class RenderPass {
|
||||||
|
NONE = 0,
|
||||||
|
SKYBOX,
|
||||||
|
DEFAULT,
|
||||||
|
};
|
||||||
|
const int num_passes = static_cast<int>(RenderPass::DEFAULT) ;
|
||||||
|
|
||||||
|
Texture* colourAttachment;
|
||||||
|
|
||||||
|
|
||||||
void Renderer::Setup()
|
void Renderer::Setup()
|
||||||
{
|
{
|
||||||
shader.Load("../Shaders/Framebuffers.vs", "../Shaders/Framebuffers.fs");
|
|
||||||
|
|
||||||
// Create ScreenVAO
|
// Create ScreenVAO
|
||||||
glGenVertexArrays(1, &ScreenVAO);
|
glGenVertexArrays(1, &ScreenVAO);
|
||||||
glBindVertexArray(ScreenVAO);
|
glBindVertexArray(ScreenVAO);
|
||||||
@ -36,7 +44,14 @@ void Renderer::Setup()
|
|||||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||||
glEnable(GL_MULTISAMPLE);
|
glEnable(GL_MULTISAMPLE);
|
||||||
|
|
||||||
|
// Load shaders
|
||||||
|
shaders[static_cast<int>(RenderPass::SKYBOX)] = Shader();
|
||||||
|
shaders[static_cast<int>(RenderPass::SKYBOX)].Load("../Shaders/skybox.vs", "../Shaders/Cubemap.fs");
|
||||||
|
shaders[static_cast<int>(RenderPass::DEFAULT)] = Shader();
|
||||||
|
shaders[static_cast<int>(RenderPass::DEFAULT)].Load("../Shaders/shader.vs", "../Shaders/shader.fs");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::resize(int width, int height ) {
|
void Renderer::resize(int width, int height ) {
|
||||||
framebuffer = FrameBuffer();
|
framebuffer = FrameBuffer();
|
||||||
|
|
||||||
@ -60,11 +75,29 @@ void Renderer::resize(int width, int height ) {
|
|||||||
|
|
||||||
renderbufferObject.Unbind();
|
renderbufferObject.Unbind();
|
||||||
|
|
||||||
}
|
OutlineEffect = FrameBuffer();
|
||||||
|
OutlineEffect.Bind();
|
||||||
|
|
||||||
|
colourAttachment = CreateTexture(width, height);
|
||||||
|
OutlineEffect.Attach(*colourAttachment);
|
||||||
|
|
||||||
|
auto renderBuffer = RenderBuffer();
|
||||||
|
renderBuffer.Bind();
|
||||||
|
renderBuffer.UseDepthAndStencil(width, height);
|
||||||
|
|
||||||
|
renderBuffer.Unbind();
|
||||||
|
|
||||||
|
glad_glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderBuffer.id);
|
||||||
|
|
||||||
|
OutlineEffect.Unbind();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::Render(Scene& scene)
|
void Renderer::Render(Scene& scene)
|
||||||
{
|
{
|
||||||
|
static RenderPass currentPass = RenderPass::SKYBOX;
|
||||||
|
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||||
|
|
||||||
@ -72,17 +105,15 @@ void Renderer::Render(Scene& scene)
|
|||||||
auto view = scene.MainCamera.GetViewMatrix();
|
auto view = scene.MainCamera.GetViewMatrix();
|
||||||
auto model = glm::mat4(1.0f);
|
auto model = glm::mat4(1.0f);
|
||||||
|
|
||||||
// 1. Skybox pass
|
std::cout << "SKYBOX PASS!" << std::endl;
|
||||||
Shader cubemap;
|
|
||||||
cubemap.Load("../Shaders/skybox.vs", "../Shaders/Cubemap.fs");
|
|
||||||
|
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
|
Shader shader = shaders.at(static_cast<int>(RenderPass::SKYBOX));
|
||||||
|
|
||||||
cubemap.use();
|
shader.use();
|
||||||
|
|
||||||
cubemap.setMat4("projection", projection);
|
shader.setMat4("projection", projection);
|
||||||
auto centeredView = glm::mat4(glm::mat3(scene.MainCamera.GetViewMatrix()));
|
auto centeredView = glm::mat4(glm::mat3(scene.MainCamera.GetViewMatrix()));
|
||||||
cubemap.setMat4("view", centeredView);
|
shader.setMat4("view", centeredView);
|
||||||
|
|
||||||
scene.skybox.Bind();
|
scene.skybox.Bind();
|
||||||
|
|
||||||
@ -93,42 +124,68 @@ void Renderer::Render(Scene& scene)
|
|||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
|
|
||||||
// 2. Scene pass
|
std::cout << "DEFAULT PASS!" << std::endl;
|
||||||
Shader blinnPhong;
|
shader = shaders.at(static_cast<int>(RenderPass::DEFAULT));
|
||||||
blinnPhong.Load("../Shaders/shader.vs", "../Shaders/shader.fs");
|
|
||||||
|
|
||||||
blinnPhong.use();
|
shader.use();
|
||||||
blinnPhong.setVec3("cameraPos", scene.MainCamera.Position);
|
shader.setVec3("cameraPos", scene.MainCamera.Position);
|
||||||
|
shader.setInt("skybox", 11);
|
||||||
|
|
||||||
blinnPhong.setInt("skybox", 11);
|
glActiveTexture(GL_TEXTURE11);
|
||||||
|
scene.skybox.Bind();
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
blinnPhong.setMat4("model", model);
|
|
||||||
blinnPhong.setMat4("view", view);
|
|
||||||
blinnPhong.setMat4("projection", projection);
|
|
||||||
|
|
||||||
|
shader.setMat4("model", model);
|
||||||
|
shader.setMat4("view", view);
|
||||||
|
shader.setMat4("projection", projection);
|
||||||
for (auto entity : scene.entities) {
|
for (auto entity : scene.entities) {
|
||||||
entity.Draw(blinnPhong);
|
entity.Draw(shader);
|
||||||
}
|
}
|
||||||
|
scene.skybox.Unbind();
|
||||||
// 3. outline pass
|
|
||||||
//Shader OutlineShader;
|
|
||||||
//OutlineShader.Load("../Shaders/shader.vs", "../Shaders/outlineshader.fs");
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
Shader OutlineShader;
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
OutlineShader.Load("../Shaders/shader.vs", "../Shaders/outlineshader.fs");
|
||||||
|
|
||||||
|
glStencilFunc(GL_NOTEQUAL, 1, 0xFF);
|
||||||
|
glStencilMask(0x00);
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
//OutlineEffect.Bind();
|
||||||
|
//glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
|
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
OutlineShader.use();
|
||||||
|
OutlineShader.setMat4("model", glm::scale(glm::mat4(1.0f), glm::vec3(1.05f, 1.05f, 1.05f)));
|
||||||
|
OutlineShader.setMat4("view", view);
|
||||||
|
OutlineShader.setMat4("projection", projection);
|
||||||
|
OutlineShader.setVec3("outlineColor", glm::vec3(0.28f, 0.10f, 0.26f));
|
||||||
|
|
||||||
|
for (auto entity : scene.entities) {
|
||||||
|
entity.Draw(OutlineShader);
|
||||||
|
}
|
||||||
|
|
||||||
|
glStencilFunc(GL_ALWAYS, 1, 0xFF);
|
||||||
|
glStencilMask(0xFF);
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 4. draw result to screen
|
// 4. draw result to screen
|
||||||
/*glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
/*
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
Shader shader;
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
shader.Load("../Shaders/Framebuffers.vs", "../Shaders/Framebuffers.fs");
|
||||||
|
|
||||||
|
|
||||||
shader.use();
|
shader.use();
|
||||||
shader.setInt("screenTexture",0);
|
shader.setInt("screenTexture",0);
|
||||||
glBindVertexArray(ScreenVAO);
|
glBindVertexArray(ScreenVAO);
|
||||||
@ -139,13 +196,12 @@ void Renderer::Render(Scene& scene)
|
|||||||
|
|
||||||
|
|
||||||
// Reset stencil
|
// Reset stencil
|
||||||
glStencilMask(0xFF);
|
|
||||||
glStencilFunc(GL_ALWAYS, 1, 0xFF);
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::Shutdown() {
|
void Renderer::Shutdown() {
|
||||||
|
|
||||||
|
|
||||||
framebuffer.Unbind();
|
framebuffer.Unbind();
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "FrameBuffer.h"
|
#include "FrameBuffer.h"
|
||||||
#include "RenderBuffer.h"
|
#include "RenderBuffer.h"
|
||||||
#include "../Primitives/Scene.h"
|
#include "../Primitives/Scene.h"
|
||||||
|
#include <map>
|
||||||
|
|
||||||
class Renderer
|
class Renderer
|
||||||
{
|
{
|
||||||
@ -20,12 +21,15 @@ class Renderer
|
|||||||
private:
|
private:
|
||||||
GLuint ScreenVAO, VBO;
|
GLuint ScreenVAO, VBO;
|
||||||
FrameBuffer framebuffer;
|
FrameBuffer framebuffer;
|
||||||
|
FrameBuffer OutlineEffect;
|
||||||
RenderBuffer renderbufferObject;
|
RenderBuffer renderbufferObject;
|
||||||
Texture* ColourBuffer;
|
Texture* ColourBuffer;
|
||||||
Shader shader;
|
|
||||||
|
|
||||||
glm::vec3 lightpos = glm::vec3(-0.2f, -1.0f, -0.3f);
|
glm::vec3 lightpos = glm::vec3(-0.2f, -1.0f, -0.3f);
|
||||||
|
|
||||||
|
std::map<int, Shader> shaders;
|
||||||
|
|
||||||
|
|
||||||
std::vector<float> ScreenVertices = {
|
std::vector<float> ScreenVertices = {
|
||||||
// vertex , uv
|
// vertex , uv
|
||||||
-1.0f, 1.0f, 0.0f, 1.0f,
|
-1.0f, 1.0f, 0.0f, 1.0f,
|
||||||
|
Loading…
Reference in New Issue
Block a user