public virtual void RenderEntity(PrimitiveType mode, DirectionalLight directionalLight, List <PointLight> lights, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane = new Vector4()) { postConstructor(); Matrix4 modelMatrix; modelMatrix = GetWorldMatrix(); /*If clip plane is set - enable clipping plane*/ if (clipPlane.X == 0 && clipPlane.Y == 0 && clipPlane.Z == 0 && clipPlane.W == 0) { GL.Disable(EnableCap.ClipDistance0); } else { GL.Enable(EnableCap.ClipDistance0); } GetShader().startProgram(); // pass uniform variables to shader if (directionalLight != null && directionalLight.GetHasShadow()) { DirectionalLightWithShadow lightWithShadow = directionalLight as DirectionalLightWithShadow; // Get shadow handler ITexture shadowMap = lightWithShadow.GetShadowMapTexture(); shadowMap.BindTexture(TextureUnit.Texture1); GetShader().SetDirectionalLightShadowMatrix(lightWithShadow.GetShadowMatrix(ref modelMatrix, ref ProjectionMatrix)); } m_texture.BindTexture(TextureUnit.Texture0); bool bEnableNormalMap = m_normalMap != null; if (bEnableNormalMap) { m_normalMap.BindTexture(TextureUnit.Texture2); } GetShader().SetDiffuseMap(0); GetShader().SetNormalMap(2, bEnableNormalMap); GetShader().SetMaterial(m_material); GetShader().SetTransformationMatrices(ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); GetShader().SetPointLights(GetRelevantPointLights(lights)); GetShader().SetDirectionalLight(directionalLight); GetShader().SetClippingPlane(ref clipPlane); GetShader().SetMist(m_mist); GetShader().SetDirectionalLightShadowMap(1); m_skin.Buffer.RenderVAO(mode); GetShader().stopProgram(); }
private void DepthPassDraw(ref Point actualScreenRezolution) { // Global light source DirectionalLight globalLight = GameWorld.GetWorldInstance().GetLevel().DirectionalLight; if (globalLight != null) { if (globalLight.GetHasShadow()) { (globalLight as DirectionalLightWithShadow).WriteDepth(GameWorld.GetWorldInstance().ShadowCastCollection, ref EngineStatics.ProjectionMatrix); } GL.Viewport(0, 0, actualScreenRezolution.X, actualScreenRezolution.Y); } }
public void renderTerrain(PrimitiveType mode, DirectionalLight directionalLight, List <PointLight> pointLights, BaseCamera camera, Matrix4 ProjectionMatrix, Vector4 clipPlane = new Vector4()) { PostConstructor(); Matrix4 ModelMatrix = Matrix4.Identity; /*If clip plane is setted - enable clipping plane*/ if (clipPlane.X == 0 && clipPlane.Y == 0 && clipPlane.Z == 0 && clipPlane.W == 0) { GL.Disable(EnableCap.ClipDistance0); } else { GL.Enable(EnableCap.ClipDistance0); } _shader.startProgram(); _textureBlack.BindTexture(TextureUnit.Texture0); _textureR.BindTexture(TextureUnit.Texture1); _textureG.BindTexture(TextureUnit.Texture2); _textureB.BindTexture(TextureUnit.Texture3); _blendMap.BindTexture(TextureUnit.Texture4); /*For normal mapping local variables*/ Int32 nmR = -1, nmG = -1, nmB = -1, nmBlack = -1; /*TO DO : * if texture exists - bind this texture, and assign temp variable samplers ID, * else - leave temp variable with value -1. */ if (_normalMapR != null) { nmR = 5; _normalMapR.BindTexture(TextureUnit.Texture5); } if (_normalMapG != null) { nmG = 6; _normalMapG.BindTexture(TextureUnit.Texture6); } if (_normalMapB != null) { nmB = 7; _normalMapB.BindTexture(TextureUnit.Texture7); } if (_normalMapBlack != null) { nmBlack = 8; _normalMapBlack.BindTexture(TextureUnit.Texture8); } if (directionalLight != null && directionalLight.GetHasShadow()) { DirectionalLightWithShadow lightWithShadow = directionalLight as DirectionalLightWithShadow; // Get shadow handler ITexture shadowMap = lightWithShadow.GetShadowMapTexture(); shadowMap.BindTexture(TextureUnit.Texture9); // shadowmap _shader.SetDirectionalLightShadowMatrix(lightWithShadow.GetShadowMatrix(ref ModelMatrix, ref ProjectionMatrix)); } _shader.SetTextureR(1, nmR, nmR > 0); _shader.SetTextureG(2, nmG, nmG > 0); _shader.SetTextureB(3, nmB, nmB > 0); _shader.SetTextureBlack(0, nmBlack, nmBlack > 0); _shader.SetBlendMap(4); _shader.SetMaterial(_terrainMaterial); _shader.SetTransformationMatrices(ref ModelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); _shader.SetDirectionalLight(directionalLight); _shader.SetPointLights(pointLights); _shader.SetMist(_mist); _shader.SetClippingPlane(ref clipPlane); _shader.SetDirectionalLightShadowMap(9); _buffer.RenderVAO(mode); _shader.stopProgram(); }
public override void renderObject(PrimitiveType mode, DirectionalLight directionalLight, List <PointLight> lights, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane = new Vector4()) { postConstructor(); Matrix4 modelMatrix; modelMatrix = GetWorldMatrix(); /*If clip plane is set - enable clipping plane*/ if (clipPlane.X == 0 && clipPlane.Y == 0 && clipPlane.Z == 0 && clipPlane.W == 0) { GL.Disable(EnableCap.ClipDistance0); } else { GL.Enable(EnableCap.ClipDistance0); } GetShader().startProgram(); m_texture.BindTexture(TextureUnit.Texture0); //Bind texture bool bEnableNormalMap = m_normalMap != null; bool bEnableSpecularMap = m_specularMap != null; if (bEnableNormalMap) { m_normalMap.BindTexture(TextureUnit.Texture1); //Bind normal map } if (m_specularMap != null) { m_specularMap.BindTexture(TextureUnit.Texture2); //Bind specular map } GetShader().SetDiffuseMap(0); if (bEnableNormalMap) { GetShader().SetNormalMap(1); } if (bEnableSpecularMap) { GetShader().SetSpecularMap(2); } GetShader().SetMaterial(m_material); GetShader().SetTransformationMatrices(ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); GetShader().SetPointLights(GetRelevantPointLights(lights)); GetShader().SetDirectionalLight(directionalLight); GetShader().SetClippingPlane(ref clipPlane); GetShader().SetMist(m_mist); if (directionalLight != null && directionalLight.GetHasShadow()) { DirectionalLightWithShadow lightWithShadow = directionalLight as DirectionalLightWithShadow; ITexture shadowMap = lightWithShadow.GetShadowMapTexture(); shadowMap.BindTexture(TextureUnit.Texture4); // shadowmap GetShader().SetDirectionalLightShadowMatrix(lightWithShadow.GetShadowMatrix(ref modelMatrix, ref ProjectionMatrix)); } GetShader().SetDirectionalLightShadowMap(4); m_skin.Buffer.RenderVAO(mode); GetShader().stopProgram(); /*Show normal for every vertex*/ if (mode == PrimitiveType.Lines) { m_specialShader.startProgram(); m_specialShader.setUniformValues(ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); m_skin.Buffer.RenderVAO(PrimitiveType.Triangles); m_specialShader.stopProgram(); } }