View difference between Paste ID: zLMjuKmp and SByR6H9H
SHOW: | | - or go back to the newest paste.
1-
Notes:	- 
1+
2
        {
3
            base.Draw(gameTime, spriteBatch);
4
5
            GraphicsDevice.SetRenderTarget(renderTargetA);
6
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
7-
	    //Set the rendertarget to draw the Blinn-Phong shaded scene to
7+
8-
            GraphicsDevice.SetRenderTarget(renderTarget);
8+
9
            material.DiffuseColor = Color.Red;
10
            material.AmbientColor = Color.Red;
11
            material.AmbientIntensity = 0.2f;
12
            material.SpecularColor = Color.White;
13
            material.SpecularIntensity = 2.0f;
14
            material.SpecularPower = 25.0f;
15
            
16
            #region Billboard
17
            GraphicsDevice.DepthStencilState = DepthStencilState.None;
18
19-
	    //Draw all the models
19+
            Matrix billboardMatrix = Matrix.CreateBillboard(lightPositions[0], camera.Eye, camera.Up, camera.Focus - camera.Eye);
20
21
            this.camera.SetEffectParameters(billboard);
22
            billboard.Parameters["World"].SetValue(world * billboardMatrix);
23
            billboard.Parameters["Tex"].SetValue(lightTexture);
24
            billboard.CurrentTechnique = billboard.Techniques["Technique1"];
25
26
            foreach (EffectPass pass in billboard.CurrentTechnique.Passes)
27
            {
28
                pass.Apply();
29
                this.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, lightQuad.QuadVertices, 0, lightQuad.QuadVertices.Length, lightQuad.QuadIndices, 0, lightQuad.QuadIndices.Length / 3);
30
            }
31
32
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
33
            #endregion
34
35
            #region OcclusionMap
36
            Effect tempEffect;
37-
	    //Restore the rendertarget to the backbuffer and clear it.
37+
38
            {
39-
            GraphicsDevice.Clear(Color.Black);
39+
                tempEffect = m.Model.Meshes[0].MeshParts[0].Effect;
40
                m.Model.Meshes[0].MeshParts[0].Effect = occlusion;
41-
	    //Pass the standard variable to the spriteBatch vertex shader.
41+
42-
	    //The vertex shader isn't used (for as far as I can tell at least) but because the standard
42+
43-
	    //vertex shader for spriteBatch is compiled in 2_0 and the God Ray shader in 3_0 I had to implement it
43+
44-
	    //manually in order to compile it in 3_0.
44+
                occlusion.CurrentTechnique = occlusion.Techniques["Technique1"];
45
                this.camera.SetEffectParameters(occlusion);
46
                occlusion.Parameters["World"].SetValue(world * m.Transform);
47
48
                mesh.Draw();
49
50-
	    //Setup all the required data for the shader
50+
                m.Model.Meshes[0].MeshParts[0].Effect = tempEffect;
51-
            postProcessing.CurrentTechnique = postProcessing.Techniques["Technique1"];
51+
52
            #endregion
53
            
54-
	    postProcessing.Parameters["Tex"].SetValue(renderTarget);
54+
            #region PostProcessing
55-
            postProcessing.Parameters["exposure"].SetValue(0.5f);
55+
56-
            postProcessing.Parameters["decay"].SetValue(0.5f);
56+
57-
            postProcessing.Parameters["weight"].SetValue(0.5f);
57+
58-
            postProcessing.Parameters["density"].SetValue(0.5f);
58+
59
            GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1);
60-
	    //Draw the renderTarget to the screen at the size of the viewport so it fits the screen
60+
61
            postProcessing.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection);
62-
            spriteBatch.Draw(renderTarget, new Rectangle(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y, spriteBatch.GraphicsDevice.Viewport.Width, spriteBatch.GraphicsDevice.Viewport.Height), Color.White);
62+
63
            postProcessing.CurrentTechnique = postProcessing.Techniques["Godrays"];
64
            Vector3 lightPosition = Vector3.Transform(lightPositions[0], world * camera.ViewMatrix * camera.ProjectionMatrix);
65-
	    //Restore some of the changes spriteBatch.Begin() made to the graphics device so the 3D render won't break
65+
66
            postProcessing.Parameters["Tex"].SetValue(renderTargetA);
67
            postProcessing.Parameters["exposure"].SetValue(0.2f);
68
            postProcessing.Parameters["decay"].SetValue(0.999f);
69
            postProcessing.Parameters["weight"].SetValue(0.2f);
70
            postProcessing.Parameters["density"].SetValue(0.9f);
71
72
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointWrap, DepthStencilState.Default, RasterizerState.CullNone, postProcessing);
73
            spriteBatch.Draw(renderTargetA, new Rectangle(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y, spriteBatch.GraphicsDevice.Viewport.Width, spriteBatch.GraphicsDevice.Viewport.Height), Color.White);
74
            spriteBatch.End();
75
76
            GraphicsDevice.BlendState = BlendState.Opaque;
77
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
78
            GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
79
            #endregion
80
            
81
            #region BlinnPhong
82
            GraphicsDevice.SetRenderTarget(renderTargetB);
83
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
84
85
            foreach (ModelData m in models)
86
            {
87
                ModelMesh mesh = m.Model.Meshes[0];
88
                Effect e = mesh.Effects[0];
89
90
                e.CurrentTechnique = e.Techniques[m.Technique];
91
                material.SetEffectParameters(e);
92
                this.camera.SetEffectParameters(e);
93
                e.Parameters["World"].SetValue(world * m.Transform);
94
                e.Parameters["WorldInverseTransposed"].SetValue(Matrix.Transpose(Matrix.Invert(world * m.Transform)));
95
                e.Parameters["CameraEye"].SetValue(new Vector4(this.camera.Eye, 0));
96
                // TODO: LightSource Color + Intensity
97
                e.Parameters["LightSources"].SetValue(lightPositions);
98
99
                mesh.Draw();
100
            }
101
            #endregion
102
103
            #region Drawing
104
            GraphicsDevice.SetRenderTarget(null);
105
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
106
107
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
108
            spriteBatch.Draw(renderTargetB, new Rectangle(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y, spriteBatch.GraphicsDevice.Viewport.Width, spriteBatch.GraphicsDevice.Viewport.Height), Color.White);
109
            spriteBatch.End();
110
111
            GraphicsDevice.BlendState = BlendState.Opaque;
112
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
113
            GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
114
            #endregion
115
        }