bool SkyBoxTransition::ShaderSetup() { GLResourceManager &loader = GLResourceManager::Instance(); if (!loader.LoadShaderFromMemory(TransitionVertexShader, TransitionFragmentShader, uiProgram)) return false; glUseProgram(uiProgram); glUniform1i(GetUniLoc(uiProgram, "sTexture"), 0); glUniform1i(GetUniLoc(uiProgram, "sTexture2"), 1); locMix = GetUniLoc(uiProgram, "Mix"); return true; }
/** * Binds the unbound uniforms to the shader. * * Assumes the shader is already applied. */ void OpenGLShader::BindUniforms(){ { // Apply the unbound uniforms. map<string, uniform>::iterator unbound = unboundUniforms.begin(); while (unbound != unboundUniforms.end()){ string name = unbound->first; uniform uni = unbound->second; map<string, uniform>::iterator bound = boundUniforms.find(name); if (bound != boundUniforms.end()){ // If the uniform has already been bound, then // delete the old data, copy the new and bind it. DeleteData(bound->second); bound->second.data = uni.data; BindUniform(bound->second); }else{ // Else get the location of the uniform, bind it // and copy it to the bound array. uni.loc = GetUniLoc(name.c_str()); BindUniform(uni); boundUniforms[name] = uni; } ++unbound; } unboundUniforms.clear(); } { // Apply 4x4 mats map<string, matrix>::iterator unbound = unboundMatUnis.begin(); while (unbound != unboundMatUnis.end()){ string name = unbound->first; matrix uni = unbound->second; map<string, matrix>::iterator bound = boundMatUnis.find(name); if (bound != boundMatUnis.end()){ bound->second.mat = uni.mat; BindUniform(bound->second); }else{ uni.loc = GetUniLoc(name.c_str()); BindUniform(uni); boundMatUnis[name] = uni; } ++unbound; } unboundMatUnis.clear(); } }
bool SkyBox::ShaderSetup() { GLResourceManager &loader = GLResourceManager::Instance(); if (!loader.LoadShaderFromMemory(SkyBoxVertexShader, SkyBoxFragmentShader, uiProgram)) return false; glUseProgram(uiProgram); glUniform1i(GetUniLoc(uiProgram, "sTexture"), 0); return true; }
void Shadows::RenderGeometry(GLuint program) { PreRenderGeometry(program); if (program == uiProgram[E_DIFFUSE]) { glUniform1i(GetUniLoc(program, "NumLights"), iNumLights); glUniform4fv(GetUniLoc(program, "Color"), 1, GrayColor); } PrintOpenGLError(); pRoomMesh->GetVBO()->Render(GL_TRIANGLES); if (program == uiProgram[E_DIFFUSE]) { glUniform4fv(GetUniLoc(program, "Color"), 1, WhiteColor); } RenderCurrentGroup(false); PostRenderGeometry(program); }
void Shadows::DrawCoordinateFrame() { glUseProgram(uiProgram[E_COLOR_OFFSET]); float offset[] = { -0.9f, -0.9f }; glUniform2fv(GetUniLoc(uiProgram[E_COLOR_OFFSET], "Offset"), 1, offset); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -fDefDistance); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); CoordinateFrame::Instance().Render(); }
void Shadows::DrawLightMarker(float *lightPos) { float white[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glUseProgram(uiProgram[E_UNIFORM]); glUniform4fv(GetUniLoc(uiProgram[E_UNIFORM], "Color"), 1, white); glPushMatrix(); glTranslatef(lightPos[0], lightPos[1], lightPos[2]); glScalef(10.0f, 10.0f, 10.0f); //glEnableClientState(GL_VERTEX_ARRAY); pTetraVBO->Render(GL_TRIANGLES); //glDisableClientState(GL_VERTEX_ARRAY); glPopMatrix(); }
void Shadows::ShowShadowVolume(unsigned int lightIndex) { glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glUseProgram(uiProgram[E_SHADOW_VOLUME]); glEnable(GL_BLEND); GLuint program = uiProgram[E_SHADOW_VOLUME]; glUniform1i(GetUniLoc(program, "LightIndex"), lightIndex); glUniform1f(GetUniLoc(program, "ShadowExtent"), fShadowExtent); glUniform1i(GetUniLoc(program, "InfiniteShadowVolume"), false); //glEnableClientState(GL_VERTEX_ARRAY); //glEnableClientState(GL_NORMAL_ARRAY); RenderCurrentGroup(true); glDisable(GL_BLEND); //glDisableClientState(GL_NORMAL_ARRAY); //glDisableClientState(GL_VERTEX_ARRAY); }
void OpenGLShader::SetUniform(string name, Matrix<4, 4, float> value, bool force){ if (force){ map<string, matrix>::iterator bound = boundMatUnis.find(name); if (bound != boundMatUnis.end()){ bound->second.mat = value; BindUniform(bound->second); }else{ matrix mat; mat.loc = GetUniLoc(name.c_str()); mat.mat = value; BindUniform(bound->second); unboundMatUnis[name] = mat; } }else{ matrix mat; mat.loc = -1; mat.mat = value; unboundMatUnis[name] = mat; } }
void Shadows::RenderPlane(GLuint program, const float *color) { float vertexAttrib[] = { -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, }; //glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, vertexAttrib); glUniform4fv(GetUniLoc(program, "Color"), 1, color); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); //glDisableClientState(GL_VERTEX_ARRAY); }
void Shadows::RenderShadowVolumes(unsigned int lightIndex) { // store current OpenGL state //glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | // GL_POLYGON_BIT | GL_STENCIL_BUFFER_BIT); GLuint program = uiProgram[E_SHADOW_VOLUME]; glUseProgram(program); glUniform1i(GetUniLoc(program, "LightIndex"), lightIndex); glUniform1f(GetUniLoc(program, "ShadowExtent"), fShadowExtent); glUniform1i(GetUniLoc(program, "InfiniteShadowVolume"), false); glClear(GL_STENCIL_BUFFER_BIT); if (eDisplayMode == E_SHADOW_VOLUMES) glEnable(GL_BLEND); else glColorMask(0, 0, 0, 0); // do not write to the color buffer glDepthMask(0); // do not write to the depth (Z) buffer glEnable(GL_STENCIL_TEST); // enable stencil testing //glEnableClientState(GL_VERTEX_ARRAY); //glEnableClientState(GL_NORMAL_ARRAY); // set the reference stencil value to 0 glStencilFunc(GL_ALWAYS, 0, ~0); if (bUseDoubleStencil) { glDisable(GL_CULL_FACE); // cull faces (back or front) glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP); glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP); // Render group of meshes RenderCurrentGroup(true); } else { glEnable(GL_CULL_FACE); // cull faces (back or front) // Pass 1 for Z-fail // increment the stencil value on Z fail glStencilOp(GL_KEEP, GL_INCR, GL_KEEP); // draw only the back faces of the shadow volume glCullFace(GL_FRONT); // Render group of meshes RenderCurrentGroup(true); //glStencilFunc(GL_ALWAYS, 0, ~0); // Pass 2 for Z-fail // decrement the stencil value on Z fail glStencilOp(GL_KEEP, GL_DECR, GL_KEEP); // draw only the front faces of the shadow volume glCullFace(GL_BACK); // Render group of meshes RenderCurrentGroup(true); } //glDisableClientState(GL_NORMAL_ARRAY); //glDisableClientState(GL_VERTEX_ARRAY); if (eDisplayMode == E_SHADOW_VOLUMES) glDisable(GL_BLEND); else glColorMask(1, 1, 1, 1); // do not write to the color buffer glDepthMask(1); // do not write to the depth (Z) buffer // restore OpenGL state //glPopAttrib(); }