Added shader-reflected Skybox
This commit is contained in:
parent
b129392d88
commit
91ccda04e4
@ -475,8 +475,9 @@ void Mesh::draw(SceneContext &ctx) {
|
||||
shader->mat.shininess = shininess;
|
||||
|
||||
// Setting the space matrixes uniques to the object
|
||||
ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * model.getMatrix();
|
||||
ctx.modelViewMatrix = ctx.viewMatrix * model.getMatrix();
|
||||
ctx.modelMatrix = model.getMatrix();
|
||||
ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix;
|
||||
ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix;
|
||||
ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix)));
|
||||
|
||||
//Sending the uniform data to the shader
|
||||
|
||||
@ -110,6 +110,9 @@ void MyGlWindow::shaderSetup()
|
||||
shaders["Toon"]->uniformFlags &= ~ShaderFlags::SHINE_FLAG;
|
||||
|
||||
shaders["Skybox"] = new Shader("skybox.vert", "skybox.frag");
|
||||
shaders["Skybox"]->uniformFlags = MVP_FLAG | KA_FLAG | MODEL_MATRIX_FLAG | SKYBOX_TEX_FLAG;
|
||||
shaders["Skybox"]->mat.enabled = true;
|
||||
shaders["Skybox"]->mat.ka = glm::vec3(0.4, 0.4, 0.4);
|
||||
|
||||
}
|
||||
|
||||
@ -137,6 +140,7 @@ void MyGlWindow::setup()
|
||||
shaderSetup();
|
||||
skybox.initialize("Models/Skybox/", shaders["Skybox"]);
|
||||
skybox.scale = 10;
|
||||
_scnctx.skybox_tex = skybox.getTexID();
|
||||
lightSetup();
|
||||
|
||||
//meshes.emplace("Ogre", new Mesh("ogre/ogre.obj", shaders["TexNmapLight"]));
|
||||
@ -192,6 +196,8 @@ void MyGlWindow::setup()
|
||||
//meshes["Teapot"]->addTranslation(glm::vec4(5, 0, 3, 1));
|
||||
//meshes["Teapot"]->cullMode = BACK;
|
||||
|
||||
meshes.emplace("Teapot", new Mesh("teapot.obj", shaders["Skybox"]));
|
||||
|
||||
}
|
||||
|
||||
void MyGlWindow::draw()
|
||||
@ -209,7 +215,7 @@ void MyGlWindow::draw()
|
||||
_scnctx.viewMatrix = view;
|
||||
_scnctx.projectionMatrix = projection;
|
||||
|
||||
//_scnctx.adjustSpots();
|
||||
shaders["Skybox"]->addUniform("WorldCamPos", eye);
|
||||
for (auto it = meshes.begin(); it != meshes.end(); it++)
|
||||
(*it).second->draw(_scnctx);
|
||||
skybox.draw(shaders["Skybox"], _scnctx);
|
||||
|
||||
@ -16,8 +16,11 @@ struct SceneContext
|
||||
|
||||
glm::mat4x4 mvpMatrix;
|
||||
glm::mat4x4 modelViewMatrix;
|
||||
glm::mat4x4 modelMatrix;
|
||||
glm::mat3x3 normalMatrix;
|
||||
|
||||
GLuint skybox_tex;
|
||||
|
||||
std::map<std::string, Texture> textures;
|
||||
|
||||
void adjustSpots()
|
||||
|
||||
@ -39,6 +39,8 @@ void Shader::setCamera(SceneContext ctx)
|
||||
glUniformMatrix3fv(_program.addUniform("NormalMatrix"), 1, GL_FALSE, glm::value_ptr(ctx.normalMatrix));
|
||||
if ((uniformFlags & ShaderFlags::MODELVIEW_FLAG) == ShaderFlags::MODELVIEW_FLAG)
|
||||
glUniformMatrix4fv(_program.addUniform("ModelViewMatrix"), 1, GL_FALSE, glm::value_ptr(ctx.modelViewMatrix));
|
||||
if ((uniformFlags & ShaderFlags::MODEL_MATRIX_FLAG) == ShaderFlags::MODEL_MATRIX_FLAG)
|
||||
glUniformMatrix4fv(_program.addUniform("ModelMatrix"), 1, GL_FALSE, glm::value_ptr(ctx.modelMatrix));
|
||||
}
|
||||
|
||||
void Shader::setLights(SceneContext ctx)
|
||||
@ -72,4 +74,10 @@ void Shader::setUniforms(SceneContext ctx)
|
||||
setCamera(ctx);
|
||||
setLights(ctx);
|
||||
setMaterial(ctx);
|
||||
|
||||
if ((uniformFlags & ShaderFlags::SKYBOX_TEX_FLAG) == ShaderFlags::SKYBOX_TEX_FLAG)
|
||||
{
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, ctx.skybox_tex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,8 @@ enum ShaderFlags
|
||||
NORMAL_MAT_FLAG = 32,
|
||||
MODELVIEW_FLAG = 64,
|
||||
LIGHTS_FLAG = 128,
|
||||
MODEL_MATRIX_FLAG = 256,
|
||||
SKYBOX_TEX_FLAG = 512
|
||||
};
|
||||
|
||||
class Shader
|
||||
|
||||
@ -98,6 +98,8 @@ void Skybox::initialize(std::string skybox_dir, Shader *sky)
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||
sky->enable();
|
||||
sky->addUniform("DrawSkyBox", (int)GL_FALSE);
|
||||
sky->addUniform("CubeMapTex", (int)0);
|
||||
sky->addUniform("ReflectFactor", (float)0.85);
|
||||
sky->disable();
|
||||
}
|
||||
|
||||
@ -108,6 +110,12 @@ Skybox::~Skybox()
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
}
|
||||
|
||||
|
||||
// //Things to add
|
||||
// //Per model :
|
||||
// // - ModelMatrix
|
||||
// // - MaterialColor
|
||||
|
||||
void Skybox::draw(Shader *sky_shader, SceneContext &ctx)
|
||||
{
|
||||
sky_shader->enable();
|
||||
@ -118,7 +126,6 @@ void Skybox::draw(Shader *sky_shader, SceneContext &ctx)
|
||||
sky_shader->addUniform("mvp", mvpMatrix);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
|
||||
sky_shader->addUniform("CubeMapTex", (int)0);
|
||||
glBindVertexArray(vao);
|
||||
sky_shader->addUniform("DrawSkyBox", (int)GL_TRUE);
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ out vec4 FragColors;
|
||||
|
||||
in vec3 reflectDir;
|
||||
|
||||
uniform vec3 MaterialColor;
|
||||
uniform vec3 Ka;
|
||||
uniform float ReflectFactor;
|
||||
uniform bool DrawSkyBox;
|
||||
uniform samplerCube CubeMapTex;
|
||||
@ -19,5 +19,5 @@ void main()
|
||||
if (DrawSkyBox == true)
|
||||
FragColors = texColor;
|
||||
else
|
||||
FragColors = vec4(mix(texColor.xyz,MaterialColor,ReflectFactor), 1);
|
||||
FragColors = vec4(mix(Ka, texColor.xyz, ReflectFactor), 1);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user