void TextureLitMaterial::render(GameObject* pGameObject, Camera* pCamera) { if (!_diffuseTexture) return; _shader->use(); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, _diffuseTexture->getId()); glUniform1i (_diffMapLoc, 0); glUniform1f(_diffuseTilingLoc, _diffuseTiling); if (normalMap) { glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, _normalMapTexture->getId()); glUniform1i (_normalMapLoc, 1); glUniform1f(_normalTilingLoc, _normalTiling); } if (specularMap) { glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, _specularMapTexture->getId()); glUniform1i (_specMapLoc, 2); glUniform1f(_specularTilingLoc, _specularTiling); } if (Renderer::getShadowDepthMapFar()) { glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, Renderer::getShadowDepthMapFar()); glUniform1i (_depthMapLocFar, 3); } if (Renderer::getShadowDepthMapFar()) { glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, Renderer::getShadowDepthMapNear()); glUniform1i (_depthMapLocNear, 4); } if (Renderer::getShadowDepthMapMid()) { glActiveTexture(GL_TEXTURE5); glBindTexture(GL_TEXTURE_2D, Renderer::getShadowDepthMapMid()); glUniform1i (_depthMapLocMid, 5); } glUniform1f(_matSmoothLoc, _smoothness); glUniform1f(_matShineLoc, _shininess); glUniform1f(_matAmbLoc, _ambient); glUniform1f(_hasNormMapLoc, normalMap); glUniform1f(_hasSpecMapLoc, specularMap); //pass in light data int index = 0; DualLinkList<Light> list = Light::GetLightList(); DualLinkNode<Light>* cn = list.startNode; //GLfloat near_plane = 1.0f, far_plane = 25.0f; while(cn!=NULL && index < MGE_MAX_LIGHTS) { Light* light = (Light*)cn; if(!light->IsActive())//do not render with inactive lights { cn = cn->nextNode; continue; } string indexString ="LightArray[" + std::to_string(index) + "]"; GLuint loc; int lightType = light->getType(); if (lightType == MGE_LIGHT_DIRECTIONAL) { loc = _shader->getUniformLocation(indexString + ".type"); glUniform1i(loc,lightType); loc = _shader->getUniformLocation(indexString + ".color"); glUniform3fv(loc,1,glm::value_ptr(light->getColor())); loc = _shader->getUniformLocation(indexString + ".direction"); glUniform3fv(loc,1,glm::value_ptr(light->getDirection())); //loc = _shader->getUniformLocation(indexString + ".position"); //glUniform3fv(loc,1,glm::value_ptr(light->getLocalPosition())); glm::mat4 lightProjection, lightView; lightView = Light::GetDirectionalViewMatrix(); glm::mat4 lightSpaceMatrix; lightProjection = Renderer::GetFarShadowOrtho(); lightSpaceMatrix = lightProjection * lightView; glUniformMatrix4fv(_lightMatLocFar, 1, GL_FALSE, glm::value_ptr(lightSpaceMatrix)); lightProjection = Renderer::GetNearShadowOrtho(); lightSpaceMatrix = lightProjection * lightView; glUniformMatrix4fv(_lightMatLocNear, 1, GL_FALSE, glm::value_ptr(lightSpaceMatrix)); lightProjection = Renderer::GetMidShadowOrtho(); lightSpaceMatrix = lightProjection * lightView; glUniformMatrix4fv(_lightMatLocMid, 1, GL_FALSE, glm::value_ptr(lightSpaceMatrix)); ++index; } else if ((!pGameObject->ignoreNonDirLights) && lightType == MGE_LIGHT_POINT) { glm::vec3 lightPos = light->getWorldPosition(); float dist = glm::distance(lightPos, pGameObject->getWorldPosition()); if(dist > light->getFalloff() + pGameObject->GetRenderBound().radius) { cn = cn->nextNode; continue; } loc = _shader->getUniformLocation(indexString + ".type"); glUniform1i(loc,lightType); loc = _shader->getUniformLocation(indexString + ".color"); glUniform3fv(loc,1,glm::value_ptr(light->getColor())); loc = _shader->getUniformLocation(indexString + ".position"); glUniform3fv(loc,1,glm::value_ptr(lightPos)); loc = _shader->getUniformLocation(indexString + ".attenuation"); glUniform3fv(loc,1,glm::value_ptr(light->getAttenuation())); ++index; } //++index; cn = cn->nextNode; } glUniform1i(_shader->getUniformLocation("lightCount"),index); //set view pos glUniform3fv(_viewPosLoc, 1, glm::value_ptr(pCamera->getWorldPosition())); //color glUniform4fv(_colorLoc,1,glm::value_ptr(color)); //pass in all MVP matrices separately glUniformMatrix4fv ( _projMatLoc, 1, GL_FALSE, glm::value_ptr(pCamera->getProjection())); glUniformMatrix4fv ( _viewMatLoc, 1, GL_FALSE, glm::value_ptr(pCamera->getView())); glUniformMatrix4fv ( _modelMatLoc, 1, GL_FALSE, glm::value_ptr(pGameObject->getWorldTransform())); //now inform mesh of where to stream its data pGameObject->getMesh()->streamToOpenGL(0, 1, 2, 3); //glGetError(); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); }