Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Screenshots: http://imageupper.com/g/?S020001008V14036287812408235
- First screenshot is just with Blinn-Phong shading, the second screenshot is the occlusion map and the third screenshot is the result of applying the shader to the second image with the parameters you suggested.
- public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
- {
- base.Draw(gameTime, spriteBatch);
- GraphicsDevice.SetRenderTarget(renderTargetA);
- GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
- Material material = new Material();
- material.DiffuseColor = Color.Red;
- material.AmbientColor = Color.Red;
- material.AmbientIntensity = 0.2f;
- material.SpecularColor = Color.White;
- material.SpecularIntensity = 2.0f;
- material.SpecularPower = 25.0f;
- #region Billboard
- GraphicsDevice.DepthStencilState = DepthStencilState.None;
- Matrix billboardMatrix = Matrix.CreateBillboard(lightPositions[0], camera.Eye, camera.Up, camera.Focus - camera.Eye);
- this.camera.SetEffectParameters(billboard);
- billboard.Parameters["World"].SetValue(world * billboardMatrix);
- billboard.Parameters["Tex"].SetValue(lightTexture);
- billboard.CurrentTechnique = billboard.Techniques["Technique1"];
- foreach (EffectPass pass in billboard.CurrentTechnique.Passes)
- {
- pass.Apply();
- this.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, lightQuad.QuadVertices, 0, lightQuad.QuadVertices.Length, lightQuad.QuadIndices, 0, lightQuad.QuadIndices.Length / 3);
- }
- GraphicsDevice.DepthStencilState = DepthStencilState.Default;
- #endregion
- #region OcclusionMap
- Effect tempEffect;
- foreach (ModelData m in models)
- {
- tempEffect = m.Model.Meshes[0].MeshParts[0].Effect;
- m.Model.Meshes[0].MeshParts[0].Effect = occlusion;
- ModelMesh mesh = m.Model.Meshes[0];
- occlusion.CurrentTechnique = occlusion.Techniques["Technique1"];
- this.camera.SetEffectParameters(occlusion);
- occlusion.Parameters["World"].SetValue(world * m.Transform);
- mesh.Draw();
- m.Model.Meshes[0].MeshParts[0].Effect = tempEffect;
- }
- #endregion
- #region PostProcessing
- GraphicsDevice.SetRenderTarget(null);
- GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
- Matrix projection = Matrix.CreateOrthographicOffCenter(0,
- GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1);
- Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
- postProcessing.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection);
- postProcessing.CurrentTechnique = postProcessing.Techniques["Godrays"];
- Vector3 lightPosition = Vector3.Transform(lightPositions[0], world * camera.ViewMatrix * camera.ProjectionMatrix);
- postProcessing.Parameters["lightPosition"].SetValue(new Vector2(lightPosition.X, lightPosition.Y));
- postProcessing.Parameters["Tex"].SetValue(renderTargetA);
- postProcessing.Parameters["exposure"].SetValue(0.2f);
- postProcessing.Parameters["decay"].SetValue(0.999f);
- postProcessing.Parameters["weight"].SetValue(0.2f);
- postProcessing.Parameters["density"].SetValue(0.9f);
- spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointWrap, DepthStencilState.Default, RasterizerState.CullNone, postProcessing);
- spriteBatch.Draw(renderTargetA, new Rectangle(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y, spriteBatch.GraphicsDevice.Viewport.Width, spriteBatch.GraphicsDevice.Viewport.Height), Color.White);
- spriteBatch.End();
- GraphicsDevice.BlendState = BlendState.Opaque;
- GraphicsDevice.DepthStencilState = DepthStencilState.Default;
- GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
- #endregion
- #region BlinnPhong
- GraphicsDevice.SetRenderTarget(renderTargetB);
- GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
- foreach (ModelData m in models)
- {
- ModelMesh mesh = m.Model.Meshes[0];
- Effect e = mesh.Effects[0];
- e.CurrentTechnique = e.Techniques[m.Technique];
- material.SetEffectParameters(e);
- this.camera.SetEffectParameters(e);
- e.Parameters["World"].SetValue(world * m.Transform);
- e.Parameters["WorldInverseTransposed"].SetValue(Matrix.Transpose(Matrix.Invert(world * m.Transform)));
- e.Parameters["CameraEye"].SetValue(new Vector4(this.camera.Eye, 0));
- // TODO: LightSource Color + Intensity
- e.Parameters["LightSources"].SetValue(lightPositions);
- mesh.Draw();
- }
- #endregion
- #region Drawing
- GraphicsDevice.SetRenderTarget(null);
- GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
- spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
- spriteBatch.Draw(renderTargetB, new Rectangle(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y, spriteBatch.GraphicsDevice.Viewport.Width, spriteBatch.GraphicsDevice.Viewport.Height), Color.White);
- spriteBatch.End();
- GraphicsDevice.BlendState = BlendState.Opaque;
- GraphicsDevice.DepthStencilState = DepthStencilState.Default;
- GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement