public void RenderWaterReflection(WaterPlane water, BaseCamera camera, Vector3 sunDirection, Matrix4 projectionMatrix, Vector4 clipPlane) { if (m_bPostConstructor) { return; } GL.Enable(EnableCap.ClipDistance0); Matrix4 mirrorMatrix; mirrorMatrix = GetMirrorMatrix(water); m_shader.startProgram(); m_skyboxDayTexture.BindTexture(TextureUnit.Texture0); m_skyboxNightTexture.BindTexture(TextureUnit.Texture1); m_shader.SetTransformationMatrices(ref projectionMatrix, camera.GetViewMatrix(), ref mirrorMatrix); m_shader.SetDayCubeTexture(0); m_shader.SetNightCubeTexture(1); m_shader.SetDayCycleValue(sunDirection.Normalized().Y); m_shader.SetMist(m_mist); m_shader.SetClipPlane(ref clipPlane); m_buffer.RenderVAO(PrimitiveType.Triangles); m_shader.stopProgram(); GL.Disable(EnableCap.ClipDistance0); }
public void renderEntities(DirectionalLight sun, BaseCamera camera, Matrix4 projectionMatrix, float time, Landscape terrain = null, Vector4 clipPlane = new Vector4()) { if (this._bufferAssembled) { postConstructor(terrain); timeElapsed += time * windSpeed; timeElapsed = timeElapsed > 360 ? timeElapsed - 360 : timeElapsed; _shader.startProgram(); _texture[0].BindTexture(TextureUnit.Texture0); //Биндим текстуру if (_texture.Count > 1) { _texture[1].BindTexture(TextureUnit.Texture1); //Биндим текстуру if (_texture.Count == 3) { _texture[2].BindTexture(TextureUnit.Texture2); //Биндим текстуру } } _shader.setTextureSampler(0); _shader.setMaterial(_grassMaterial); _shader.setViewMatrix(camera.GetViewMatrix()); _shader.setProjectionMatrix(ref projectionMatrix); _shader.setSun(sun); _shader.setWind(_wind); _shader.setTime(timeElapsed); _shader.setClipPlane(ref clipPlane); _shader.setMist(_mist); //VAOManager.renderInstanced(_buffer, PrimitiveType.Triangles, _plants.Count); _shader.stopProgram(); } }
public void StencilPass(BaseCamera camera, ref Matrix4 projectionMatrix) { PostConstructor(); m_stencilPassShader.startProgram(); m_stencilPassShader.SetUniformVariables(ref projectionMatrix, camera.GetViewMatrix(), ref m_modelMatrix); m_buffer.RenderVAO(PrimitiveType.Triangles); m_stencilPassShader.stopProgram(); }
public Matrix ViewMatrix() { if (currentCamera == null) { return(Matrix.Identity); } return(currentCamera.GetViewMatrix()); }
public void RenderWaterRefraction(DirectionalLight Sun, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane = new Vector4()) { if (bPostConstructor) { return; } Matrix4 modelMatrix; modelMatrix = GetWorldMatrix(); /*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); } m_liteRefractionShader.startProgram(); //Бинд шейдера m_texture.BindTexture(TextureUnit.Texture0); // diffusemap texture bool bEnableNM = m_normalMap != null; bool bEnableSM = m_specularMap != null; if (bEnableNM) { m_normalMap.BindTexture(TextureUnit.Texture1); // normalmap } if (bEnableSM) { m_specularMap.BindTexture(TextureUnit.Texture2); //Bind specular map } m_liteReflectionShader.SetTexture(0); if (bEnableNM) { m_liteRefractionShader.SetNormalMap(1); } if (bEnableSM) { m_liteRefractionShader.SetSpecularMap(2); } m_liteRefractionShader.SetAlbedoTexture(0); m_liteRefractionShader.SetMaterial(m_material); m_liteRefractionShader.SetTransformationMatrices(ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); m_liteRefractionShader.SetDirectionalLight(Sun); m_liteRefractionShader.SetClipPlane(ref clipPlane); m_skin.Buffer.RenderVAO(PrimitiveType.Triangles); m_liteRefractionShader.stopProgram(); }
public void render(BaseCamera camera, ref Matrix4 projectionMatrix) { postConstructor(); Matrix4 modelMatrix = Matrix4.Identity; GetShader().startProgram(); m_texture.BindTexture(TextureUnit.Texture0); m_envMap.BindTexture(TextureUnit.Texture1); GetShader().setUniformValues(ref modelMatrix, camera.GetViewMatrix(), ref projectionMatrix, camera.GetEyeVector(), 0, 1); m_skin.Buffer.RenderVAO(PrimitiveType.Triangles); GetShader().stopProgram(); }
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(); }
public void Render(BaseCamera camera, Matrix4 projectionMatrix) { postConstructor(); foreach (PointLight lamp in _lamps) { Matrix4 modelMatrix = Matrix4.CreateTranslation(lamp.Position.Xyz); _shader.startProgram(); _texture.BindTexture(TextureUnit.Texture0); _shader.setUniformValues(modelMatrix, camera.GetViewMatrix(), projectionMatrix, 0); _buffer.RenderVAO(PrimitiveType.Points); _shader.stopProgram(); } }
public override void RenderEntity(PrimitiveType mode, DirectionalLight Sun, List <PointLight> lights, BaseCamera camera, ref Matrix4 projectionMatrix, Vector4 clipPlane = default(Vector4)) { var worldMatrix = GetWorldMatrix(); var viewMatrix = camera.GetViewMatrix(); var skinningMatrices = m_animationHolder.GetAnimatedOffsetedMatrices(GetSkin().GetRootBone()); GetShader().startProgram(); m_texture.BindTexture(TextureUnit.Texture0); GetShader().SetAlbedoTexture(0); GetShader().SetTransformationMatrices(ref worldMatrix, ref viewMatrix, ref projectionMatrix); GetShader().SetSkinningMatrices(skinningMatrices); GetSkin().Buffer.RenderVAO(PrimitiveType.Triangles); GetShader().stopProgram(); }
public void RenderDummy(BaseCamera camera, ref Matrix4 ProjectionMatrix) { Matrix4 worldMatrix = Matrix4.Identity; Matrix4 viewMatrix = camera.GetViewMatrix(); Matrix4 projectionMatrix = ProjectionMatrix; m_skeletonShader.startProgram(); m_skeletonShader.SetTransformationMatrices(ref worldMatrix, ref viewMatrix, ref projectionMatrix); m_skeletonShader.SetSkeletonMatrices(m_animationHolder.GetAnimatedNotOffsetedPoseMatricesList().ToArray()); GL.PointSize(10); m_skeletonVAO.RenderVAO(PrimitiveType.Points); m_skeletonShader.stopProgram(); m_animationHolder.UpdateAnimationLoopTime(0.005f); }
public Matrix4 CreateOrthographicProjection(BaseCamera viewerCamera, ref Matrix4 projectionMatrix) { Matrix4 result = Matrix4.Identity; Matrix4 ViewProjectionMatrix = Matrix4.Identity; ViewProjectionMatrix *= viewerCamera.GetViewMatrix(); ViewProjectionMatrix *= projectionMatrix; ConvexVolume cameraVolume = new ConvexVolume(ViewProjectionMatrix); Vector3 lbn, rtf; GetEdgePoints(viewerCamera, cameraVolume, out lbn, out rtf); result = Matrix4.CreateOrthographic(rtf.X - lbn.X, 100, 1, 400); return(result); }
public void Render(BaseCamera baseCamera, ref Matrix4 projectionMatrix) { Matrix4 viewMatrix = baseCamera.GetViewMatrix(); viewMatrix[3, 0] = 0; viewMatrix[3, 1] = -3; viewMatrix[3, 2] = 0; m_shader.startProgram(); m_shader.SetTransformationMatrices(ref viewMatrix, ref projectionMatrix); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); m_vao.RenderVAO(OpenTK.Graphics.OpenGL.PrimitiveType.LineStrip); GL.Disable(EnableCap.Blend); m_shader.stopProgram(); }
public void renderSkybox(BaseCamera camera, Vector3 sunDirection, Matrix4 projectionMatrix) { PostConstructor(); GL.Disable(EnableCap.ClipDistance0); Matrix4 modelMatrix = Matrix4.CreateRotationY(MathHelper.DegreesToRadians(m_moveFactor)); m_shader.startProgram(); m_skyboxDayTexture.BindTexture(TextureUnit.Texture0); m_skyboxNightTexture.BindTexture(TextureUnit.Texture1); m_shader.SetTransformationMatrices(ref projectionMatrix, camera.GetViewMatrix(), ref modelMatrix); m_shader.SetDayCubeTexture(0); m_shader.SetNightCubeTexture(1); m_shader.SetDayCycleValue(sunDirection.Normalized().Y); m_shader.SetMist(m_mist); m_buffer.RenderVAO(PrimitiveType.Triangles); m_shader.stopProgram(); }
public void Render(BaseCamera camera, ref Matrix4 projectionMatrix, bool bApplyLensFlareScale = false) { postConstructor(); Matrix4 modelMatrix = Matrix4.Identity; if (bApplyLensFlareScale) { modelMatrix *= Matrix4.CreateScale(LENS_FLARE_SIZE_TO_SUN_SIZE); } modelMatrix *= Matrix4.CreateTranslation(m_lightSource.Position); GL.Disable(EnableCap.ClipDistance0); m_shader.startProgram(); m_texture1.BindTexture(TextureUnit.Texture0); m_texture2.BindTexture(TextureUnit.Texture1); m_shader.setUniformValues(ref modelMatrix, camera.GetViewMatrix(), ref projectionMatrix, m_lightSource, 0, 1); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); m_buffer.RenderVAO(PrimitiveType.Triangles); GL.Disable(EnableCap.Blend); m_shader.stopProgram(); }
public void RenderWaterRefraction(DirectionalLight Sun, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane = default(Vector4)) { if (bPostConstructor) { return; } Matrix4 modelMatrix; modelMatrix = GetWorldMatrix(); /*If clip plane is set - enable clipping plane*/ if (GeometryMath.CMP(clipPlane.LengthSquared, 0.0f) > 0) { GL.Disable(EnableCap.ClipDistance0); } else { GL.Enable(EnableCap.ClipDistance0); } m_liteRefractionShader.startProgram(); m_texture.BindTexture(TextureUnit.Texture0); m_normalMap?.BindTexture(TextureUnit.Texture1); m_liteRefractionShader.SetAlbedoTexture(0); m_liteRefractionShader.SetNormalMap(1); m_liteRefractionShader.SetMaterial(m_material); m_liteRefractionShader.SetTransformationMatrices(ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); m_liteRefractionShader.SetDirectionalLight(Sun); m_liteRefractionShader.SetClipPlane(ref clipPlane); m_skin.Buffer.RenderVAO(PrimitiveType.Triangles); m_liteRefractionShader.stopProgram(); }
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 void RenderWaterReflection(WaterPlane water, DirectionalLight Sun, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane) { if (m_bPostConstructor) { return; } float translationPositionY = (2 * water.GetTranslation().Y); Matrix4 mirrorMatrix, modelMatrix = Matrix4.Identity; mirrorMatrix = Matrix4.CreateScale(1, -1, 1); mirrorMatrix *= Matrix4.CreateTranslation(0, translationPositionY, 0); GL.Enable(EnableCap.ClipDistance0); liteReflectionShader.startProgram(); _textureBlack.BindTexture(TextureUnit.Texture0); _textureR.BindTexture(TextureUnit.Texture1); _textureG.BindTexture(TextureUnit.Texture2); _textureB.BindTexture(TextureUnit.Texture3); _blendMap.BindTexture(TextureUnit.Texture4); liteReflectionShader.SetTextureR(1); liteReflectionShader.SetTextureG(2); liteReflectionShader.SetTextureB(3); liteReflectionShader.SetTextureBlack(0); liteReflectionShader.SetBlendMap(4); liteReflectionShader.SetMaterial(_terrainMaterial); liteReflectionShader.SetTransformationMatrices(ref mirrorMatrix, ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); liteReflectionShader.SetDirectionalLight(Sun); liteReflectionShader.SetClippingPlane(ref clipPlane); _buffer.RenderVAO(PrimitiveType.Triangles); liteReflectionShader.stopProgram(); GL.Disable(EnableCap.ClipDistance0); }
public void RenderWaterReflection(WaterPlane water, DirectionalLight Sun, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane = new Vector4()) { if (bPostConstructor) { return; } Matrix4 modelMatrix, mirrorMatrix; mirrorMatrix = GetMirrorMatrix(water); 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); } m_liteReflectionShader.startProgram(); m_texture.BindTexture(TextureUnit.Texture0); m_normalMap?.BindTexture(TextureUnit.Texture1); m_liteReflectionShader.SetTexture(0); m_liteReflectionShader.SetNormalMap(1); m_liteReflectionShader.SetMaterial(m_material); m_liteReflectionShader.SetTransformationMatrices(ref mirrorMatrix, ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); m_liteReflectionShader.SetDirectionalLight(Sun); m_liteReflectionShader.SetClipPlane(ref clipPlane); m_skin.Buffer.RenderVAO(PrimitiveType.Triangles); m_liteReflectionShader.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(); } }
public void Tick(float deltaTime) { this.viewMatrix = camera.GetViewMatrix(); this.currentRay = calculateMouseRay(); }
public MousePicker(Matrix4 projectionMatrix, BaseCamera camera) { this.camera = camera; this.pojectionMatrix = projectionMatrix; this.viewMatrix = camera.GetViewMatrix(); }