private void RenderControl_Render_GLSL(object sender, GlControlEventArgs e) { Control control = (Control)sender; PerspectiveProjectionMatrix projectionMatrix = new PerspectiveProjectionMatrix(45.0f, (float)control.Width / (float)control.Height, 0.1f, 100.0f); ModelMatrix viewMatrix = new ModelMatrix(); ModelMatrix modelMatrix = new ModelMatrix(); modelMatrix.Translate(new Vertex3f(modelPosition.X, modelPosition.Y, modelPosition.Z)); modelMatrix.Scale(new Vertex3f(0.2f, 0.2f, 0.2f)); Gl.Viewport(0, 0, control.Width, control.Height); Gl.ClearColor(0.05f, 0.05f, 0.05f, 1.0f); Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); modelShader.Use(); modelMatrix.RotateX(modelAngle.X); modelMatrix.RotateY(modelAngle.Y); modelMatrix.RotateZ(modelAngle.Z); //viewMatrix.Translate(new Vertex3f(-2.0f * (float)Math.Sin(modelAngle.Y * PI_OVER_180), 0.0f, -2.0f*(float)Math.Cos(modelAngle.Y*PI_OVER_180))); Gl.UniformMatrix4(modelShader.uLocation_Projection, 1, false, projectionMatrix.ToArray()); Gl.UniformMatrix4(modelShader.uLocation_View, 1, false, viewMatrix.ToArray()); Gl.UniformMatrix4(modelShader.uLocation_Model, 1, false, modelMatrix.ToArray()); modelNanosuit.Draw(modelShader); }
private void DisplayShadowMaps(GraphicsContext ctx) { State.ViewportState viewportState = new State.ViewportState(ctx); OrthoProjectionMatrix orthoProjection = new OrthoProjectionMatrix(0.0f, viewportState.Width, 0.0f, viewportState.Height); ModelMatrix model = new ModelMatrix(); // No depth test State.DepthTestState.DefaultState.Apply(ctx, null); ctx.Bind(_ShadowMapDebugProgram); for (int i = 0; i < _LightManager.ShadowLights.Count; i++) { SceneObjectLight shadowLight = _LightManager.ShadowLights[i]; SceneObjectLightSpot shadowSpotLight = shadowLight as SceneObjectLightSpot; if (shadowSpotLight == null) { continue; } Texture2d shadowTex = shadowSpotLight._ShadowMap; shadowTex.SamplerParams.CompareMode = false; ModelMatrix quadModel = new ModelMatrix(model); quadModel.Scale(shadowTex.Width / 4, shadowTex.Height / 4); _ShadowMapDebugProgram.SetUniform(ctx, "glo_ModelViewProjection", orthoProjection * quadModel); _ShadowMapDebugProgram.SetUniform(ctx, "glo_NearFar", new Vertex2f(0.1f, 100.0f)); _ShadowMapDebugProgram.SetUniform(ctx, "glo_Texture", shadowTex); _ShadowMapQuad.Draw(ctx, _ShadowMapDebugProgram); shadowTex.SamplerParams.CompareMode = true; // Stride right model.Translate(shadowTex.Width, 0.0f); } }