SHARE
TWEET

Untitled

a guest Jun 24th, 2014 181 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Screenshots: http://imageupper.com/g/?S020001008V14036287812408235
  2.              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.
  3.  
  4.         public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
  5.         {
  6.             base.Draw(gameTime, spriteBatch);
  7.  
  8.             GraphicsDevice.SetRenderTarget(renderTargetA);
  9.             GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
  10.  
  11.             Material material = new Material();
  12.             material.DiffuseColor = Color.Red;
  13.             material.AmbientColor = Color.Red;
  14.             material.AmbientIntensity = 0.2f;
  15.             material.SpecularColor = Color.White;
  16.             material.SpecularIntensity = 2.0f;
  17.             material.SpecularPower = 25.0f;
  18.            
  19.             #region Billboard
  20.             GraphicsDevice.DepthStencilState = DepthStencilState.None;
  21.  
  22.             Matrix billboardMatrix = Matrix.CreateBillboard(lightPositions[0], camera.Eye, camera.Up, camera.Focus - camera.Eye);
  23.  
  24.             this.camera.SetEffectParameters(billboard);
  25.             billboard.Parameters["World"].SetValue(world * billboardMatrix);
  26.             billboard.Parameters["Tex"].SetValue(lightTexture);
  27.             billboard.CurrentTechnique = billboard.Techniques["Technique1"];
  28.  
  29.             foreach (EffectPass pass in billboard.CurrentTechnique.Passes)
  30.             {
  31.                 pass.Apply();
  32.                 this.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, lightQuad.QuadVertices, 0, lightQuad.QuadVertices.Length, lightQuad.QuadIndices, 0, lightQuad.QuadIndices.Length / 3);
  33.             }
  34.  
  35.             GraphicsDevice.DepthStencilState = DepthStencilState.Default;
  36.             #endregion
  37.  
  38.             #region OcclusionMap
  39.             Effect tempEffect;
  40.             foreach (ModelData m in models)
  41.             {
  42.                 tempEffect = m.Model.Meshes[0].MeshParts[0].Effect;
  43.                 m.Model.Meshes[0].MeshParts[0].Effect = occlusion;
  44.  
  45.                 ModelMesh mesh = m.Model.Meshes[0];
  46.  
  47.                 occlusion.CurrentTechnique = occlusion.Techniques["Technique1"];
  48.                 this.camera.SetEffectParameters(occlusion);
  49.                 occlusion.Parameters["World"].SetValue(world * m.Transform);
  50.  
  51.                 mesh.Draw();
  52.  
  53.                 m.Model.Meshes[0].MeshParts[0].Effect = tempEffect;
  54.             }
  55.             #endregion
  56.            
  57.             #region PostProcessing
  58.             GraphicsDevice.SetRenderTarget(null);
  59.             GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
  60.  
  61.             Matrix projection = Matrix.CreateOrthographicOffCenter(0,
  62.             GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1);
  63.             Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
  64.             postProcessing.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection);
  65.  
  66.             postProcessing.CurrentTechnique = postProcessing.Techniques["Godrays"];
  67.             Vector3 lightPosition = Vector3.Transform(lightPositions[0], world * camera.ViewMatrix * camera.ProjectionMatrix);
  68.             postProcessing.Parameters["lightPosition"].SetValue(new Vector2(lightPosition.X, lightPosition.Y));
  69.             postProcessing.Parameters["Tex"].SetValue(renderTargetA);
  70.             postProcessing.Parameters["exposure"].SetValue(0.2f);
  71.             postProcessing.Parameters["decay"].SetValue(0.999f);
  72.             postProcessing.Parameters["weight"].SetValue(0.2f);
  73.             postProcessing.Parameters["density"].SetValue(0.9f);
  74.  
  75.             spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointWrap, DepthStencilState.Default, RasterizerState.CullNone, postProcessing);
  76.             spriteBatch.Draw(renderTargetA, new Rectangle(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y, spriteBatch.GraphicsDevice.Viewport.Width, spriteBatch.GraphicsDevice.Viewport.Height), Color.White);
  77.             spriteBatch.End();
  78.  
  79.             GraphicsDevice.BlendState = BlendState.Opaque;
  80.             GraphicsDevice.DepthStencilState = DepthStencilState.Default;
  81.             GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
  82.             #endregion
  83.            
  84.             #region BlinnPhong
  85.             GraphicsDevice.SetRenderTarget(renderTargetB);
  86.             GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
  87.  
  88.             foreach (ModelData m in models)
  89.             {
  90.                 ModelMesh mesh = m.Model.Meshes[0];
  91.                 Effect e = mesh.Effects[0];
  92.  
  93.                 e.CurrentTechnique = e.Techniques[m.Technique];
  94.                 material.SetEffectParameters(e);
  95.                 this.camera.SetEffectParameters(e);
  96.                 e.Parameters["World"].SetValue(world * m.Transform);
  97.                 e.Parameters["WorldInverseTransposed"].SetValue(Matrix.Transpose(Matrix.Invert(world * m.Transform)));
  98.                 e.Parameters["CameraEye"].SetValue(new Vector4(this.camera.Eye, 0));
  99.                 // TODO: LightSource Color + Intensity
  100.                 e.Parameters["LightSources"].SetValue(lightPositions);
  101.  
  102.                 mesh.Draw();
  103.             }
  104.             #endregion
  105.  
  106.             #region Drawing
  107.             GraphicsDevice.SetRenderTarget(null);
  108.             GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
  109.  
  110.             spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
  111.             spriteBatch.Draw(renderTargetB, new Rectangle(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y, spriteBatch.GraphicsDevice.Viewport.Width, spriteBatch.GraphicsDevice.Viewport.Height), Color.White);
  112.             spriteBatch.End();
  113.  
  114.             GraphicsDevice.BlendState = BlendState.Opaque;
  115.             GraphicsDevice.DepthStencilState = DepthStencilState.Default;
  116.             GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
  117.             #endregion
  118.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top