├── .gitignore
├── 2D Pixel Shader
├── 2DEffect-test.sln
└── 2DEffect-test
│ ├── 2DEffect-test.csproj
│ ├── Content
│ ├── Content.mgcb
│ ├── Effect1.fx
│ ├── Effect2.fx
│ ├── Effect2b.fx
│ ├── lightmask.png
│ ├── surge-rainbow.png
│ └── surge.png
│ ├── Game1.cs
│ ├── Icon.ico
│ ├── Lights.cs
│ ├── LightsExtended.cs
│ ├── Program.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── app.config
├── RBWithakersShaders
├── Ambient.cs
├── Content
│ ├── Content.mgcb
│ ├── Effects
│ │ ├── Ambient.fx
│ │ ├── Diffuse.fx
│ │ ├── NormalMap.fx
│ │ ├── Reflection.fx
│ │ ├── Specular.fx
│ │ ├── Textured.fx
│ │ ├── Toon.fx
│ │ ├── ToonColored.fx
│ │ └── Transparency.fx
│ ├── Models
│ │ ├── Helicopter.fbx
│ │ ├── HelicopterTexture.png
│ │ ├── Helicopter_a.fbx
│ │ └── UntexturedSphere.FBX
│ ├── Skyboxes
│ │ ├── Skybox.fx
│ │ ├── Sunset.dds
│ │ └── cube.FBX
│ └── Textures
│ │ ├── HelicopterNormalMap.png
│ │ └── HelicopterTexture.png
├── Diffuse.cs
├── Icon.ico
├── NormalMap.cs
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── RBWithakersShaders.csproj
├── RBWithakersShaders.sln
├── Reflection.cs
├── Skybox.cs
├── Skybox.fx
├── SkyboxShader.cs
├── Specular.cs
├── Textured.cs
├── Toon.cs
├── Transparency.cs
└── cube.FBX
├── README.md
├── RiemersHLSLTuTorial.sln
├── RiemersHLSLTutorial
├── Content
│ ├── Content.mgcb
│ ├── Effect4.fx
│ ├── car.x
│ ├── chasis.jpg
│ ├── chasis_a.jpg
│ ├── lamppost.x
│ ├── ruedas.jpg
│ ├── streettexture.jpg
│ └── ventanas.jpg
├── Icon.ico
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── RiemersHLSLTutorial.csproj
└── game1.cs
├── pictures
├── BumpMap.jpg
├── Reflection-issue.jpg
├── Toon.jpg
├── ambient.jpg
├── diffuse.jpg
├── skybox.jpg
├── specular1.jpg
├── textured1.jpg
├── textured2.jpg
└── transparency-1.jpg
├── specular1.jpg
├── textured1.jpg
└── textured2.jpg
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
2 | [Bb]in/
3 | [Oo]bj/
4 |
5 | # mstest test results
6 | TestResults
7 |
8 | ## Ignore Visual Studio temporary files, build results, and
9 | ## files generated by popular Visual Studio add-ons.
10 |
11 | # User-specific files
12 | *.suo
13 | *.user
14 | *.sln.docstates
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Rr]elease/
19 | x64/
20 | *_i.c
21 | *_p.c
22 | *.ilk
23 | *.meta
24 | *.obj
25 | *.pch
26 | *.pdb
27 | *.pgc
28 | *.pgd
29 | *.rsp
30 | *.sbr
31 | *.tlb
32 | *.tli
33 | *.tlh
34 | *.tmp
35 | *.log
36 | *.vspscc
37 | *.vssscc
38 | .builds
39 |
40 | # Visual C++ cache files
41 | ipch/
42 | *.aps
43 | *.ncb
44 | *.opensdf
45 | *.sdf
46 |
47 | # Visual Studio profiler
48 | *.psess
49 | *.vsp
50 | *.vspx
51 |
52 | # Guidance Automation Toolkit
53 | *.gpState
54 |
55 | # ReSharper is a .NET coding add-in
56 | _ReSharper*
57 |
58 | # NCrunch
59 | *.ncrunch*
60 | .*crunch*.local.xml
61 |
62 | # Installshield output folder
63 | [Ee]xpress
64 |
65 | # DocProject is a documentation generator add-in
66 | DocProject/buildhelp/
67 | DocProject/Help/*.HxT
68 | DocProject/Help/*.HxC
69 | DocProject/Help/*.hhc
70 | DocProject/Help/*.hhk
71 | DocProject/Help/*.hhp
72 | DocProject/Help/Html2
73 | DocProject/Help/html
74 |
75 | # Click-Once directory
76 | publish
77 |
78 | # Publish Web Output
79 | *.Publish.xml
80 |
81 | # NuGet Packages Directory
82 | packages
83 |
84 | # Windows Azure Build Output
85 | csx
86 | *.build.csdef
87 |
88 | # Windows Store app package directory
89 | AppPackages/
90 |
91 | # Others
92 | [Bb]in
93 | [Oo]bj
94 | sql
95 | TestResults
96 | [Tt]est[Rr]esult*
97 | *.Cache
98 | ClientBin
99 | [Ss]tyle[Cc]op.*
100 | ~$*
101 | *.dbmdl
102 | Generated_Code #added for RIA/Silverlight projects
103 |
104 | # Backup & report files from converting an old project file to a newer
105 | # Visual Studio version. Backup files are not needed, because we have git ;-)
106 | _UpgradeReport_Files/
107 | Backup*/
108 | UpgradeLog*.XML
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.40629.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2DEffect-test", "2DEffect-test\2DEffect-test.csproj", "{5B7C22CE-C713-4A6C-AEAD-088306624C4E}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x86 = Debug|x86
11 | Release|x86 = Release|x86
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {5B7C22CE-C713-4A6C-AEAD-088306624C4E}.Debug|x86.ActiveCfg = Debug|x86
15 | {5B7C22CE-C713-4A6C-AEAD-088306624C4E}.Debug|x86.Build.0 = Debug|x86
16 | {5B7C22CE-C713-4A6C-AEAD-088306624C4E}.Release|x86.ActiveCfg = Release|x86
17 | {5B7C22CE-C713-4A6C-AEAD-088306624C4E}.Release|x86.Build.0 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/2DEffect-test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {5B7C22CE-C713-4A6C-AEAD-088306624C4E}
9 | WinExe
10 | Properties
11 | _2DEffect_test
12 | 2DEffect-test
13 | 512
14 | Windows
15 |
16 |
17 | v4.5
18 |
19 |
20 |
21 | x86
22 | true
23 | full
24 | false
25 | bin\Windows\Debug\
26 | DEBUG;TRACE;WINDOWS
27 | prompt
28 | 4
29 | false
30 | false
31 |
32 |
33 | x86
34 | pdbonly
35 | true
36 | bin\Windows\Release\
37 | TRACE;WINDOWS
38 | prompt
39 | 4
40 | false
41 |
42 |
43 | Icon.ico
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | False
55 | H:\MonoGame-dev\Windows\AnyCPU\Debug\MonoGame.Framework.dll
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
77 |
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Content/Content.mgcb:
--------------------------------------------------------------------------------
1 |
2 | #----------------------------- Global Properties ----------------------------#
3 |
4 | /outputDir:bin
5 | /intermediateDir:obj
6 | /platform:Windows
7 | /config:
8 | /profile:Reach
9 | /compress:False
10 |
11 | #-------------------------------- References --------------------------------#
12 |
13 |
14 | #---------------------------------- Content ---------------------------------#
15 |
16 | #begin surge.png
17 | /importer:TextureImporter
18 | /processor:TextureProcessor
19 | /processorParam:ColorKeyColor=255,0,255,255
20 | /processorParam:ColorKeyEnabled=True
21 | /processorParam:GenerateMipmaps=False
22 | /processorParam:PremultiplyAlpha=True
23 | /processorParam:ResizeToPowerOfTwo=False
24 | /processorParam:MakeSquare=False
25 | /processorParam:TextureFormat=Color
26 | /build:surge.png
27 |
28 | #begin Effect1.fx
29 | /importer:EffectImporter
30 | /processor:EffectProcessor
31 | /processorParam:DebugMode=Auto
32 | /build:Effect1.fx
33 |
34 | #begin surge-rainbow.png
35 | /importer:TextureImporter
36 | /processor:TextureProcessor
37 | /processorParam:ColorKeyColor=255,0,255,255
38 | /processorParam:ColorKeyEnabled=True
39 | /processorParam:GenerateMipmaps=False
40 | /processorParam:PremultiplyAlpha=True
41 | /processorParam:ResizeToPowerOfTwo=False
42 | /processorParam:MakeSquare=False
43 | /processorParam:TextureFormat=Color
44 | /build:surge-rainbow.png
45 |
46 | #begin lightmask.png
47 | /importer:TextureImporter
48 | /processor:TextureProcessor
49 | /processorParam:ColorKeyColor=255,0,255,255
50 | /processorParam:ColorKeyEnabled=True
51 | /processorParam:GenerateMipmaps=False
52 | /processorParam:PremultiplyAlpha=True
53 | /processorParam:ResizeToPowerOfTwo=False
54 | /processorParam:MakeSquare=False
55 | /processorParam:TextureFormat=Color
56 | /build:lightmask.png
57 |
58 | #begin Effect2.fx
59 | /importer:EffectImporter
60 | /processor:EffectProcessor
61 | /processorParam:DebugMode=Auto
62 | /build:Effect2.fx
63 |
64 | #begin Effect2b.fx
65 | /importer:EffectImporter
66 | /processor:EffectProcessor
67 | /processorParam:DebugMode=Auto
68 | /build:Effect2b.fx
69 |
70 |
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Content/Effect1.fx:
--------------------------------------------------------------------------------
1 | sampler TextureSampler : register(s0);
2 | sampler RainbowSampler : register(s1);
3 | Texture2D myTex2D;
4 | Texture2D rainbow;
5 | float param1;
6 |
7 | //float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float2 texCoord : TEXCOORD0) : SV_TARGET0
8 | float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float2 texCoord : TEXCOORD0) : SV_TARGET0
9 | {
10 | //float4 tex;
11 | //tex = myTex2D.Sample(TextureSampler, texCoord.xy) * .6f;
12 | //tex += myTex2D.Sample(TextureSampler, texCoord.xy + (0.005)) * .2f;
13 | //return tex;
14 |
15 | //base
16 | //return myTex2D.Sample(TextureSampler, texCoord.xy);
17 |
18 | //grayscale
19 | //float4 color = myTex2D.Sample(TextureSampler, texCoord.xy);
20 | //color.gb = color.r;
21 | //return color;
22 |
23 | //blackout
24 | //float4 color = myTex2D.Sample(TextureSampler, texCoord.xy);
25 | //color.rgb = 0;
26 | //color.rgb = color.gbr;
27 |
28 |
29 | //high contrast
30 | //float high = .6;
31 | //float low = .4;
32 |
33 | //if (color.r > high) color.r = 1;
34 | //else if (color.r < low) color.r = 0;
35 |
36 | //if (color.g > high) color.g = 1;
37 | //else if (color.g < low) color.g = 0;
38 |
39 | //if (color.b > high) color.b = 1;
40 | //else if (color.b < low) color.b = 0;
41 |
42 | //if (color.a)
43 | //color.rgb = 1 - color.rgb;
44 |
45 | //rainbow
46 | // if (!any(color)) return color;
47 |
48 | // float step = 1.0/7;
49 |
50 | // if (texCoord.x < (step * 1)) color = float4(1, 0, 0, 1);
51 | // else if (texCoord.x < (step * 2)) color = float4(1, .5, 0, 1);
52 | // else if (texCoord.x < (step * 3)) color = float4(1, 1, 0, 1);
53 | // else if (texCoord.x < (step * 4)) color = float4(0, 1, 0, 1);
54 | // else if (texCoord.x < (step * 5)) color = float4(0, 0, 1, 1);
55 | // else if (texCoord.x < (step * 6)) color = float4(.3, 0, .8, 1);
56 | // else color = float4(1, .8, 1, 1);
57 |
58 | //180 rotate
59 | //float4 color = myTex2D.Sample(TextureSampler, 1 - texCoord);
60 |
61 | //horiz mirror
62 | //float4 color = myTex2D.Sample(TextureSampler, float2(1 - texCoord.x, texCoord.y));
63 |
64 | // gradient
65 | // float4 color = myTex2D.Sample(TextureSampler, texCoord.xy);
66 | // if (color.a)
67 | // color.rgb = texCoord.y;
68 |
69 | //param 1
70 | // float4 color = myTex2D.Sample(TextureSampler, texCoord.xy);
71 | // if (texCoord.y > param1)
72 | // color = float4(0,0,0,0);
73 |
74 | float4 color = myTex2D.Sample(TextureSampler, texCoord.xy);
75 | float4 rainbow_color = rainbow.Sample(RainbowSampler, texCoord.xy);
76 |
77 | if (color.a)
78 | return rainbow_color;
79 |
80 | return color;
81 | }
82 |
83 |
84 | technique Technique1
85 | {
86 | pass Pass1
87 | {
88 | PixelShader = compile ps_4_0_level_9_3 PixelShaderFunction();
89 | }
90 | }
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Content/Effect2.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define PS_SHADERMODEL ps_3_0
4 | #else
5 | #define PS_SHADERMODEL ps_4_0_level_9_1
6 | #endif
7 |
8 | sampler textureSampler : register(s0);
9 | sampler lightSampler : register(s1);
10 | Texture2D sTexture;
11 | Texture2D lightMask;
12 |
13 |
14 | float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float2 texCoord : TEXCOORD0) : SV_TARGET0
15 | {
16 | float4 color = sTexture.Sample(textureSampler, texCoord.xy);
17 | float4 lightColor = lightMask.Sample(lightSampler, texCoord.xy);
18 |
19 | return color * lightColor;
20 | }
21 |
22 |
23 | technique Lighting
24 | {
25 | pass P0
26 | {
27 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
28 | }
29 | };
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Content/Effect2b.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define PS_SHADERMODEL ps_3_0
4 | #else
5 | #define PS_SHADERMODEL ps_4_0_level_9_1
6 | #endif
7 |
8 | sampler textureSampler : register(s0);
9 | sampler lightSampler : register(s1);
10 | Texture2D sTexture;
11 | Texture2D lightMask;
12 | float lightIntensity = 1;
13 | float lightRadius;
14 | //float lightFalloff = 2;
15 | //float lightAttenuation = 5000;
16 |
17 | float4 PixelShaderFunction(float4 pos : SV_POSITION, float4 color1 : COLOR0, float2 texCoord : TEXCOORD0) : SV_TARGET0
18 | {
19 | float4 color = sTexture.Sample(textureSampler, texCoord.xy);
20 | float4 lightColor = lightMask.Sample(lightSampler, texCoord.xy);
21 |
22 | //float d = distance(LightPosition, input.WorldPosition);
23 | //float att = 1 - pow(clamp(d / lightAttenuation, 0, 1),lightFalloff);
24 | return color * lightColor * lightIntensity;
25 | }
26 |
27 |
28 | technique Lighting
29 | {
30 | pass P0
31 | {
32 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
33 | }
34 | };
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Content/lightmask.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/2D Pixel Shader/2DEffect-test/Content/lightmask.png
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Content/surge-rainbow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/2D Pixel Shader/2DEffect-test/Content/surge-rainbow.png
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Content/surge.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/2D Pixel Shader/2DEffect-test/Content/surge.png
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Game1.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 | namespace _2DEffect_test
8 | {
9 | public class Game1 : Game
10 | {
11 | GraphicsDeviceManager graphics;
12 | SpriteBatch spriteBatch;
13 |
14 | Texture2D texture, rainbow;
15 | Effect effect;
16 |
17 | public Game1()
18 | {
19 | graphics = new GraphicsDeviceManager(this);
20 | Content.RootDirectory = "Content";
21 | }
22 |
23 | protected override void Initialize()
24 | {
25 |
26 | base.Initialize();
27 | }
28 |
29 | protected override void LoadContent()
30 | {
31 | spriteBatch = new SpriteBatch(GraphicsDevice);
32 |
33 | texture = Content.Load("surge");
34 | rainbow = Content.Load("surge-rainbow");
35 | effect = Content.Load("Effect1");
36 | }
37 |
38 | protected override void UnloadContent()
39 | {
40 | }
41 |
42 | protected override void Update(GameTime gameTime)
43 | {
44 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
45 | Exit();
46 |
47 | base.Update(gameTime);
48 | }
49 |
50 | protected override void Draw(GameTime gameTime)
51 | {
52 | GraphicsDevice.Clear(Color.CornflowerBlue);
53 |
54 | spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
55 | //effect.Parameters["param1"].SetValue(.3f);
56 | effect.Parameters["rainbow"].SetValue(rainbow);
57 | effect.CurrentTechnique.Passes[0].Apply();
58 | spriteBatch.Draw(texture, new Vector2(0, 0), Color.White);
59 | spriteBatch.End();
60 |
61 | base.Draw(gameTime);
62 | }
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/2D Pixel Shader/2DEffect-test/Icon.ico
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Lights.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 | namespace _2DEffect_test
8 | {
9 | public class Lights : Microsoft.Xna.Framework.Game
10 | {
11 | GraphicsDeviceManager graphics;
12 | SpriteBatch spriteBatch;
13 |
14 | Texture2D lightMask;
15 | Texture2D surge;
16 |
17 | RenderTarget2D lightsTarget;
18 | RenderTarget2D mainTarget;
19 |
20 | Effect lightingEffect;
21 |
22 | public Lights()
23 | {
24 | graphics = new GraphicsDeviceManager(this);
25 | Content.RootDirectory = "Content";
26 | }
27 |
28 | protected override void LoadContent()
29 | {
30 | spriteBatch = new SpriteBatch(GraphicsDevice);
31 |
32 | lightMask = Content.Load("lightmask");
33 | surge = Content.Load("surge");
34 |
35 | lightingEffect = Content.Load("Effect2");
36 |
37 | var pp = GraphicsDevice.PresentationParameters;
38 | lightsTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);
39 | mainTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);
40 | }
41 |
42 | protected override void Update(GameTime gameTime)
43 | {
44 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
45 | Exit();
46 |
47 | base.Update(gameTime);
48 | }
49 |
50 | protected override void Draw(GameTime gameTime)
51 | {
52 |
53 | // Create a Light Mask to pass to the pixel shader
54 | GraphicsDevice.SetRenderTarget(lightsTarget);
55 | GraphicsDevice.Clear(Color.Black);
56 | spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
57 | spriteBatch.Draw(lightMask, new Vector2(0, 0), Color.White);
58 | spriteBatch.Draw(lightMask, new Vector2(100, 0), Color.White);
59 | spriteBatch.Draw(lightMask, new Vector2(200, 200), Color.White);
60 | spriteBatch.Draw(lightMask, new Vector2(300, 300), Color.White);
61 | spriteBatch.Draw(lightMask, new Vector2(500, 200), Color.White);
62 | spriteBatch.End();
63 |
64 | // Draw the main scene to the Render Target
65 | GraphicsDevice.SetRenderTarget(mainTarget);
66 | GraphicsDevice.Clear(Color.CornflowerBlue);
67 | spriteBatch.Begin();
68 | spriteBatch.Draw(surge, new Vector2(100, 0), Color.White);
69 | spriteBatch.Draw(surge, new Vector2(250, 250), Color.White);
70 | spriteBatch.Draw(surge, new Vector2(550, 225), Color.White);
71 | spriteBatch.End();
72 |
73 | // Draw the main scene with a pixel
74 | GraphicsDevice.SetRenderTarget(null);
75 | GraphicsDevice.Clear(Color.CornflowerBlue);
76 | spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
77 | lightingEffect.Parameters["lightMask"].SetValue(lightsTarget);
78 | lightingEffect.CurrentTechnique.Passes[0].Apply();
79 | spriteBatch.Draw(mainTarget, Vector2.Zero, Color.White);
80 | spriteBatch.End();
81 |
82 | base.Draw(gameTime);
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/LightsExtended.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 | namespace _2DEffect_test
8 | {
9 | public class LightsExtended : Microsoft.Xna.Framework.Game
10 | {
11 | GraphicsDeviceManager graphics;
12 | SpriteBatch spriteBatch;
13 |
14 | Texture2D lightMask;
15 | Texture2D surge;
16 |
17 | RenderTarget2D lightsTarget;
18 | RenderTarget2D mainTarget;
19 |
20 | Effect lightingEffect;
21 |
22 | Vector2 lightPosition;
23 | float lightSpeed = 5;
24 |
25 |
26 | public LightsExtended()
27 | {
28 | graphics = new GraphicsDeviceManager(this);
29 | Content.RootDirectory = "Content";
30 | }
31 |
32 |
33 | protected override void Initialize()
34 | {
35 | lightPosition = new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2);
36 |
37 | base.Initialize();
38 | }
39 |
40 | protected override void LoadContent()
41 | {
42 | spriteBatch = new SpriteBatch(GraphicsDevice);
43 |
44 | lightMask = Content.Load("lightmask");
45 | surge = Content.Load("surge");
46 |
47 | lightingEffect = Content.Load("Effect2b");
48 |
49 | var pp = GraphicsDevice.PresentationParameters;
50 | lightsTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);
51 | mainTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight);
52 | }
53 |
54 | protected override void Update(GameTime gameTime)
55 | {
56 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
57 | Exit();
58 |
59 | if (Keyboard.GetState().IsKeyDown(Keys.Up))
60 | {
61 | lightPosition.Y -= lightSpeed;
62 | }
63 | if (Keyboard.GetState().IsKeyDown(Keys.Down))
64 | {
65 | lightPosition.Y += lightSpeed;
66 | }
67 | if (Keyboard.GetState().IsKeyDown(Keys.Left))
68 | {
69 | lightPosition.X -= lightSpeed;
70 | }
71 | if (Keyboard.GetState().IsKeyDown(Keys.Right))
72 | {
73 | lightPosition.X += lightSpeed;
74 | }
75 |
76 | base.Update(gameTime);
77 | }
78 |
79 | protected override void Draw(GameTime gameTime)
80 | {
81 |
82 | // Create a Light Mask to pass to the pixel shader
83 | GraphicsDevice.SetRenderTarget(lightsTarget);
84 | GraphicsDevice.Clear(Color.Black);
85 | spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);
86 | spriteBatch.Draw(lightMask, lightPosition, Color.White);
87 | spriteBatch.End();
88 |
89 | // Draw the main scene to the Render Target
90 | GraphicsDevice.SetRenderTarget(mainTarget);
91 | GraphicsDevice.Clear(Color.White); // change color to change light tint/color
92 | spriteBatch.Begin();
93 | spriteBatch.Draw(surge, new Vector2(100, 0), Color.White);
94 | spriteBatch.Draw(surge, new Vector2(250, 250), Color.White);
95 | spriteBatch.Draw(surge, new Vector2(550, 225), Color.White);
96 | spriteBatch.End();
97 |
98 | // Draw the main scene with a pixel
99 | GraphicsDevice.SetRenderTarget(null);
100 | GraphicsDevice.Clear(Color.White);
101 | spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
102 | lightingEffect.Parameters["lightMask"].SetValue(lightsTarget);
103 | lightingEffect.CurrentTechnique.Passes[0].Apply();
104 | spriteBatch.Draw(mainTarget, Vector2.Zero, Color.White);
105 | spriteBatch.End();
106 |
107 | base.Draw(gameTime);
108 | }
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace _2DEffect_test
4 | {
5 | #if WINDOWS || LINUX
6 | public static class Program
7 | {
8 | [STAThread]
9 | static void Main()
10 | {
11 | using (var game = new Lights()) // LightsExtended())
12 | game.Run();
13 | }
14 | }
15 | #endif
16 | }
17 |
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("2DEffect-test")]
9 | [assembly: AssemblyProduct("2DEffect-test")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("a50ef9f3-0605-498f-bdfd-c1e546de151a")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("3.4.0.456")]
36 | [assembly: AssemblyFileVersion("3.4.0.456")]
37 |
--------------------------------------------------------------------------------
/2D Pixel Shader/2DEffect-test/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/RBWithakersShaders/Ambient.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 |
8 | namespace RBWithakersShaders
9 | {
10 | public class Ambient : Microsoft.Xna.Framework.Game
11 | {
12 | GraphicsDeviceManager graphics;
13 | SpriteBatch spriteBatch;
14 | Effect effect;
15 |
16 | Matrix world = Matrix.CreateTranslation(0, 0, 0);
17 | Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 10), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
18 | Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 600f, 0.1f, 100f);
19 | float angle = 0;
20 | float distance = 10;
21 |
22 | Model model;
23 |
24 | public Ambient()
25 | {
26 | graphics = new GraphicsDeviceManager(this);
27 | Content.RootDirectory = "Content";
28 | }
29 |
30 | protected override void Initialize()
31 | {
32 | base.Initialize();
33 | }
34 |
35 | protected override void LoadContent()
36 | {
37 | spriteBatch = new SpriteBatch(GraphicsDevice);
38 |
39 | model = Content.Load("Models/Helicopter");
40 | effect = Content.Load("Effects/Ambient");
41 | }
42 |
43 | protected override void UnloadContent()
44 | {
45 | }
46 |
47 | protected override void Update(GameTime gameTime)
48 | {
49 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
50 | Exit();
51 |
52 | angle += 0.01f;
53 | view = Matrix.CreateLookAt(distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
54 |
55 | base.Update(gameTime);
56 | }
57 | protected override void Draw(GameTime gameTime)
58 | {
59 | GraphicsDevice.Clear(Color.Black);
60 |
61 | //DrawModel(model, world, view, projection);
62 |
63 | DrawModelWithEffect(model, world, view, projection);
64 | base.Draw(gameTime);
65 | }
66 |
67 | private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
68 | {
69 | foreach (ModelMesh mesh in model.Meshes)
70 | {
71 | foreach (BasicEffect effect in mesh.Effects)
72 | {
73 | effect.EnableDefaultLighting();
74 | effect.PreferPerPixelLighting = true;
75 | effect.World = world * mesh.ParentBone.Transform;
76 | effect.View = view;
77 | effect.Projection = projection;
78 | }
79 | mesh.Draw();
80 | }
81 | }
82 |
83 | private void DrawModelWithEffect(Model model, Matrix world, Matrix view, Matrix projection)
84 | {
85 | foreach (ModelMesh mesh in model.Meshes)
86 | {
87 | foreach (ModelMeshPart part in mesh.MeshParts)
88 | {
89 | part.Effect = effect;
90 | effect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
91 | effect.Parameters["View"].SetValue(view);
92 | effect.Parameters["Projection"].SetValue(projection);
93 |
94 | //effect.Parameters["AmbientColor"].SetValue(Color.Green.ToVector4());
95 | //effect.Parameters["AmbientIntensity"].SetValue(0.5f);
96 | }
97 | mesh.Draw();
98 | }
99 | }
100 | }
101 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Content.mgcb:
--------------------------------------------------------------------------------
1 |
2 | #----------------------------- Global Properties ----------------------------#
3 |
4 | /outputDir:bin/$(Platform)
5 | /intermediateDir:obj/$(Platform)
6 | /platform:Windows
7 | /config:
8 | /profile:Reach
9 | /compress:False
10 |
11 | #-------------------------------- References --------------------------------#
12 |
13 |
14 | #---------------------------------- Content ---------------------------------#
15 |
16 | #begin Models/HelicopterTexture.png
17 | /importer:TextureImporter
18 | /processor:TextureProcessor
19 | /processorParam:ColorKeyColor=255,0,255,255
20 | /processorParam:ColorKeyEnabled=True
21 | /processorParam:GenerateMipmaps=False
22 | /processorParam:PremultiplyAlpha=True
23 | /processorParam:ResizeToPowerOfTwo=False
24 | /processorParam:MakeSquare=False
25 | /processorParam:TextureFormat=Color
26 | /build:Models/HelicopterTexture.png
27 |
28 | #begin Effects/Ambient.fx
29 | /importer:EffectImporter
30 | /processor:EffectProcessor
31 | /processorParam:DebugMode=Auto
32 | /build:Effects/Ambient.fx
33 |
34 | #begin Models/Helicopter.fbx
35 | /importer:FbxImporter
36 | /processor:ModelProcessor
37 | /processorParam:ColorKeyColor=0,0,0,0
38 | /processorParam:ColorKeyEnabled=True
39 | /processorParam:DefaultEffect=BasicEffect
40 | /processorParam:GenerateMipmaps=True
41 | /processorParam:GenerateTangentFrames=True
42 | /processorParam:PremultiplyTextureAlpha=True
43 | /processorParam:PremultiplyVertexColors=True
44 | /processorParam:ResizeTexturesToPowerOfTwo=False
45 | /processorParam:RotationX=0
46 | /processorParam:RotationY=0
47 | /processorParam:RotationZ=0
48 | /processorParam:Scale=1
49 | /processorParam:SwapWindingOrder=False
50 | /processorParam:TextureFormat=DxtCompressed
51 | /build:Models/Helicopter.fbx
52 |
53 | #begin Effects/Specular.fx
54 | /importer:EffectImporter
55 | /processor:EffectProcessor
56 | /processorParam:DebugMode=Auto
57 | /build:Effects/Specular.fx
58 |
59 | #begin Effects/Diffuse.fx
60 | /importer:EffectImporter
61 | /processor:EffectProcessor
62 | /processorParam:DebugMode=Auto
63 | /build:Effects/Diffuse.fx
64 |
65 | #begin Textures/HelicopterNormalMap.png
66 | /importer:TextureImporter
67 | /processor:TextureProcessor
68 | /processorParam:ColorKeyColor=255,0,255,255
69 | /processorParam:ColorKeyEnabled=True
70 | /processorParam:GenerateMipmaps=False
71 | /processorParam:PremultiplyAlpha=True
72 | /processorParam:ResizeToPowerOfTwo=False
73 | /processorParam:MakeSquare=False
74 | /processorParam:TextureFormat=Color
75 | /build:Textures/HelicopterNormalMap.png
76 |
77 | #begin Textures/HelicopterTexture.png
78 | /importer:TextureImporter
79 | /processor:TextureProcessor
80 | /processorParam:ColorKeyColor=255,0,255,255
81 | /processorParam:ColorKeyEnabled=True
82 | /processorParam:GenerateMipmaps=False
83 | /processorParam:PremultiplyAlpha=True
84 | /processorParam:ResizeToPowerOfTwo=False
85 | /processorParam:MakeSquare=False
86 | /processorParam:TextureFormat=Color
87 | /build:Textures/HelicopterTexture.png
88 |
89 | #begin Effects/Textured.fx
90 | /importer:EffectImporter
91 | /processor:EffectProcessor
92 | /processorParam:DebugMode=Auto
93 | /build:Effects/Textured.fx
94 |
95 | #begin Effects/NormalMap.fx
96 | /importer:EffectImporter
97 | /processor:EffectProcessor
98 | /processorParam:DebugMode=Auto
99 | /build:Effects/NormalMap.fx
100 |
101 | #begin Skyboxes/Sunset.dds
102 | /importer:TextureImporter
103 | /processor:TextureProcessor
104 | /processorParam:ColorKeyColor=255,0,255,255
105 | /processorParam:ColorKeyEnabled=True
106 | /processorParam:GenerateMipmaps=False
107 | /processorParam:PremultiplyAlpha=False
108 | /processorParam:ResizeToPowerOfTwo=False
109 | /processorParam:MakeSquare=False
110 | /processorParam:TextureFormat=Color
111 | /build:Skyboxes/Sunset.dds
112 |
113 | #begin Skyboxes/cube.FBX
114 | /importer:FbxImporter
115 | /processor:ModelProcessor
116 | /processorParam:ColorKeyColor=0,0,0,0
117 | /processorParam:ColorKeyEnabled=True
118 | /processorParam:DefaultEffect=BasicEffect
119 | /processorParam:GenerateMipmaps=True
120 | /processorParam:GenerateTangentFrames=False
121 | /processorParam:PremultiplyTextureAlpha=True
122 | /processorParam:PremultiplyVertexColors=True
123 | /processorParam:ResizeTexturesToPowerOfTwo=False
124 | /processorParam:RotationX=0
125 | /processorParam:RotationY=0
126 | /processorParam:RotationZ=0
127 | /processorParam:Scale=1
128 | /processorParam:SwapWindingOrder=False
129 | /processorParam:TextureFormat=DxtCompressed
130 | /build:Skyboxes/cube.FBX
131 |
132 | #begin Skyboxes/Skybox.fx
133 | /importer:EffectImporter
134 | /processor:EffectProcessor
135 | /processorParam:DebugMode=Auto
136 | /build:Skyboxes/Skybox.fx
137 |
138 | #begin Effects/Reflection.fx
139 | /importer:EffectImporter
140 | /processor:EffectProcessor
141 | /processorParam:DebugMode=Auto
142 | /build:Effects/Reflection.fx
143 |
144 | #begin Models/UntexturedSphere.FBX
145 | /importer:FbxImporter
146 | /processor:ModelProcessor
147 | /processorParam:ColorKeyColor=0,0,0,0
148 | /processorParam:ColorKeyEnabled=True
149 | /processorParam:DefaultEffect=BasicEffect
150 | /processorParam:GenerateMipmaps=True
151 | /processorParam:GenerateTangentFrames=False
152 | /processorParam:PremultiplyTextureAlpha=True
153 | /processorParam:PremultiplyVertexColors=True
154 | /processorParam:ResizeTexturesToPowerOfTwo=False
155 | /processorParam:RotationX=0
156 | /processorParam:RotationY=0
157 | /processorParam:RotationZ=90
158 | /processorParam:Scale=1
159 | /processorParam:SwapWindingOrder=False
160 | /processorParam:TextureFormat=DxtCompressed
161 | /build:Models/UntexturedSphere.FBX
162 |
163 | #begin Effects/Toon.fx
164 | /importer:EffectImporter
165 | /processor:EffectProcessor
166 | /processorParam:DebugMode=Auto
167 | /build:Effects/Toon.fx
168 |
169 | #begin Effects/ToonColored.fx
170 | /importer:EffectImporter
171 | /processor:EffectProcessor
172 | /processorParam:DebugMode=Auto
173 | /build:Effects/ToonColored.fx
174 |
175 | #begin Effects/Transparency.fx
176 | /importer:EffectImporter
177 | /processor:EffectProcessor
178 | /processorParam:DebugMode=Auto
179 | /build:Effects/Transparency.fx
180 |
181 |
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Effects/Ambient.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 | float4x4 World;
11 | float4x4 View;
12 | float4x4 Projection;
13 |
14 | float4 AmbientColor = float4(1, 1, 1, 1);
15 | float AmbientIntensity = 0.1;
16 |
17 | struct VertexShaderInput
18 | {
19 | float4 Position : POSITION0;
20 | };
21 |
22 | struct VertexShaderOutput
23 | {
24 | float4 Position : POSITION0;
25 | };
26 |
27 | VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
28 | {
29 | VertexShaderOutput output;
30 |
31 | float4 worldPosition = mul(input.Position, World);
32 | float4 viewPosition = mul(worldPosition, View);
33 | output.Position = mul(viewPosition, Projection);
34 |
35 | return output;
36 | }
37 |
38 | float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
39 | {
40 | return AmbientColor * AmbientIntensity;
41 | }
42 |
43 | technique Ambient
44 | {
45 | pass Pass1
46 | {
47 | VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
48 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
49 | }
50 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Effects/Diffuse.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 | float4x4 World;
11 | float4x4 View;
12 | float4x4 Projection;
13 |
14 | float4 AmbientColor = float4(1, 1, 1, 1);
15 | float AmbientIntensity = 0.1;
16 |
17 | float4x4 WorldInverseTranspose;
18 |
19 | float3 DiffuseLightDirection = float3(1, 0, 0);
20 | float4 DiffuseColor = float4(1, 1, 1, 1);
21 | float DiffuseIntensity = 1.0;
22 |
23 | struct VertexShaderInput
24 | {
25 | float4 Position : SV_POSITION;
26 | float4 Normal : NORMAL0;
27 | };
28 |
29 | struct VertexShaderOutput
30 | {
31 | float4 Position : SV_POSITION;
32 | float4 Color : COLOR0;
33 | };
34 |
35 | VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
36 | {
37 | VertexShaderOutput output;
38 |
39 | float4 worldPosition = mul(input.Position, World);
40 | float4 viewPosition = mul(worldPosition, View);
41 | output.Position = mul(viewPosition, Projection);
42 |
43 | float4 normal = mul(input.Normal, WorldInverseTranspose);
44 | float lightIntensity = dot(normal, DiffuseLightDirection);
45 | output.Color = saturate(DiffuseColor * DiffuseIntensity * lightIntensity);
46 |
47 | return output;
48 | }
49 |
50 | float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
51 | {
52 | return saturate(input.Color + AmbientColor * AmbientIntensity);
53 | }
54 |
55 | technique Ambient
56 | {
57 | pass Pass1
58 | {
59 | VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
60 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
61 | }
62 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Effects/NormalMap.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 | float4x4 World;
11 | float4x4 View;
12 | float4x4 Projection;
13 | float4x4 WorldInverseTranspose;
14 |
15 | float4 AmbientColor = float4(1, 1, 1, 1);
16 | float AmbientIntensity = 0.1;
17 |
18 | float3 DiffuseLightDirection = float3(-1, 0, 0);
19 | float4 DiffuseColor = float4(1, 1, 1, 1);
20 | float DiffuseIntensity = 1.0;
21 |
22 | float Shininess = 200;
23 | float4 SpecularColor = float4(1, 1, 1, 1);
24 | float SpecularIntensity = 1;
25 | float3 ViewVector = float3(1, 0, 0);
26 |
27 | texture ModelTexture;
28 | sampler2D textureSampler = sampler_state {
29 | Texture = (ModelTexture);
30 | MinFilter = Linear;
31 | MagFilter = Linear;
32 | AddressU = Clamp;
33 | AddressV = Clamp;
34 | };
35 |
36 | float BumpConstant = 1;
37 | texture NormalMap;
38 | sampler2D bumpSampler = sampler_state {
39 | Texture = (NormalMap);
40 | MinFilter = Linear;
41 | MagFilter = Linear;
42 | AddressU = Wrap;
43 | AddressV = Wrap;
44 | };
45 |
46 | struct VertexShaderInput
47 | {
48 | float4 Position : POSITION0;
49 | float3 Normal : NORMAL0;
50 | float3 Tangent : TANGENT0;
51 | float3 Binormal : BINORMAL0;
52 | float2 TextureCoordinate : TEXCOORD0;
53 | };
54 |
55 | struct VertexShaderOutput
56 | {
57 | float4 Position : POSITION0;
58 | float2 TextureCoordinate : TEXCOORD0;
59 | float3 Normal : TEXCOORD1;
60 | float3 Tangent : TEXCOORD2;
61 | float3 Binormal : TEXCOORD3;
62 | };
63 |
64 | VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
65 | {
66 | VertexShaderOutput output;
67 |
68 | float4 worldPosition = mul(input.Position, World);
69 | float4 viewPosition = mul(worldPosition, View);
70 | output.Position = mul(viewPosition, Projection);
71 |
72 | output.Normal = normalize(mul(input.Normal, WorldInverseTranspose));
73 | output.Tangent = normalize(mul(input.Tangent, WorldInverseTranspose));
74 | output.Binormal = normalize(mul(input.Binormal, WorldInverseTranspose));
75 |
76 | output.TextureCoordinate = input.TextureCoordinate;
77 | return output;
78 | }
79 |
80 | float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
81 | {
82 | // Calculate the normal, including the information in the bump map
83 | float3 bump = BumpConstant * (tex2D(bumpSampler, input.TextureCoordinate) - (0.5, 0.5, 0.5));
84 | float3 bumpNormal = input.Normal + (bump.x * input.Tangent + bump.y * input.Binormal);
85 | bumpNormal = normalize(bumpNormal);
86 |
87 | // Calculate the diffuse light component with the bump map normal
88 | float diffuseIntensity = dot(normalize(DiffuseLightDirection), bumpNormal);
89 | if(diffuseIntensity < 0)
90 | diffuseIntensity = 0;
91 |
92 | // Calculate the specular light component with the bump map normal
93 | float3 light = normalize(DiffuseLightDirection);
94 | float3 r = normalize(2 * dot(light, bumpNormal) * bumpNormal - light);
95 | float3 v = normalize(mul(normalize(ViewVector), World));
96 | float dotProduct = dot(r, v);
97 |
98 | float4 specular = SpecularIntensity * SpecularColor * max(pow(abs(dotProduct), Shininess), 0) * diffuseIntensity;
99 |
100 | // Calculate the texture color
101 | float4 textureColor = tex2D(textureSampler, input.TextureCoordinate);
102 | textureColor.a = 1;
103 |
104 | // Combine all of these values into one (including the ambient light)
105 | return saturate(textureColor * (diffuseIntensity) + AmbientColor * AmbientIntensity + specular);
106 | }
107 |
108 | technique BumpMapped
109 | {
110 | pass Pass1
111 | {
112 | VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
113 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
114 | }
115 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Effects/Reflection.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 | float4x4 World;
11 | float4x4 View;
12 | float4x4 Projection;
13 | float4x4 WorldInverseTranspose;
14 |
15 | float4 TintColor = float4(1, 1, 1, 1);
16 | float3 CameraPosition;
17 |
18 | Texture SkyboxTexture;
19 | samplerCUBE SkyboxSampler = sampler_state
20 | {
21 | texture = ;
22 | magfilter = LINEAR;
23 | minfilter = LINEAR;
24 | mipfilter = LINEAR;
25 | AddressU = Mirror;
26 | AddressV = Mirror;
27 | };
28 |
29 | struct VertexShaderInput
30 | {
31 | float4 Position : POSITION0;
32 | float4 Normal : NORMAL0;
33 | };
34 |
35 | struct VertexShaderOutput
36 | {
37 | float4 Position : SV_POSITION; // POSITION0 or this: no change
38 | float3 Reflection : TEXCOORD0;
39 | };
40 |
41 | VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
42 | {
43 | VertexShaderOutput output;
44 |
45 | float4 worldPosition = mul(input.Position, World);
46 | float4 viewPosition = mul(worldPosition, View);
47 | output.Position = mul(viewPosition, Projection);
48 |
49 | float4 VertexPosition = mul(input.Position, World);
50 | float3 ViewDirection = CameraPosition - VertexPosition;
51 |
52 | float3 Normal = normalize(mul(input.Normal, WorldInverseTranspose));
53 | output.Reflection = reflect(-normalize(ViewDirection), normalize(Normal));
54 |
55 | return output;
56 | }
57 |
58 | float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
59 | {
60 | return TintColor * texCUBE(SkyboxSampler, normalize(input.Reflection));
61 | }
62 |
63 | technique Reflection
64 | {
65 | pass Pass1
66 | {
67 | VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
68 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
69 | }
70 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Effects/Specular.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 |
11 | float4x4 World;
12 | float4x4 View;
13 | float4x4 Projection;
14 |
15 | float4 AmbientColor = float4(1.0, 1.0, 1.0, 1.0);
16 | float AmbientIntensity = 0.1;
17 |
18 | float Shininess = 100.0;
19 | float4 SpecularColor = float4(0.2, 0.2, 1.0, 1.0);
20 | float SpecularIntensity = 1.0;
21 | float3 ViewVector = float3(1.0, 0.0, 0.0);
22 |
23 | float4x4 WorldInverseTranspose;
24 |
25 | float3 DiffuseLightDirection = float3(1, 0, 0);
26 | float4 DiffuseColor = float4(1.0, 1.0, 1.0, 1.0);
27 | float DiffuseIntensity = 1.0;
28 |
29 | struct VertexShaderInput
30 | {
31 | float4 Position : SV_POSITION;
32 | float4 Normal : NORMAL0;
33 | };
34 |
35 | struct VertexShaderOutput
36 | {
37 | float4 Position : SV_POSITION;
38 | float4 Color : COLOR0;
39 | float3 Normal : TEXCOORD0;
40 | };
41 |
42 | VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
43 | {
44 | VertexShaderOutput output;
45 |
46 | float4 worldPosition = mul(input.Position, World);
47 | float4 viewPosition = mul(worldPosition, View);
48 | output.Position = mul(viewPosition, Projection);
49 |
50 | float4 normal = mul(input.Normal, WorldInverseTranspose);
51 | float lightIntensity = dot(normal, DiffuseLightDirection);
52 | output.Color = saturate(DiffuseColor * DiffuseIntensity * lightIntensity);
53 | output.Normal = normal;
54 |
55 | return output;
56 | }
57 |
58 | float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
59 | {
60 | float3 light = normalize(DiffuseLightDirection);
61 | float3 normal = normalize(input.Normal);
62 | float3 r = normalize(2.0 * dot(light, normal) * normal - light);
63 | float3 v = normalize(mul(normalize(ViewVector), World));
64 |
65 | float dotProduct = dot(r, v);
66 | float4 specular = SpecularIntensity * SpecularColor * max(pow(abs(dotProduct), Shininess), 0) * length(input.Color);
67 |
68 | return saturate(input.Color + AmbientColor * AmbientIntensity + specular);
69 | }
70 |
71 | technique Specular
72 | {
73 | pass Pass1
74 | {
75 | VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
76 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
77 | }
78 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Effects/Textured.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 | float4x4 World;
11 | float4x4 View;
12 | float4x4 Projection;
13 | float4x4 WorldInverseTranspose;
14 |
15 | float4 AmbientColor = float4(1, 1, 1, 1);
16 | float AmbientIntensity = 0.1;
17 |
18 | // change way of light to get the same as XNA version picture (?)
19 | // I guess there is something deeper below, which produce negative value instead of positive one or vice versa
20 | float3 DiffuseLightDirection = float3(-1, 0, 0);
21 | float4 DiffuseColor = float4(1, 1, 1, 1);
22 | float DiffuseIntensity = 1.0;
23 |
24 | float Shininess = 200;
25 | float4 SpecularColor = float4(1, 1, 1, 1);
26 | float SpecularIntensity = 1;
27 | float3 ViewVector = float3(1, 0, 0);
28 |
29 | // sampler work as-is ?? I can't believe it !
30 | texture ModelTexture;
31 | sampler2D textureSampler = sampler_state {
32 | Texture = (ModelTexture);
33 | MinFilter = Linear;
34 | MagFilter = Linear;
35 | AddressU = Clamp;
36 | AddressV = Clamp;
37 | };
38 |
39 | struct VertexShaderInput
40 | {
41 | float4 Position : SV_POSITION;
42 | float4 Normal : NORMAL0;
43 | float2 TextureCoordinate : TEXCOORD0;
44 | };
45 |
46 | struct VertexShaderOutput
47 | {
48 | float4 Position : SV_POSITION;
49 | float4 Color : COLOR0;
50 | float3 Normal : TEXCOORD0;
51 | float2 TextureCoordinate : TEXCOORD1;
52 | };
53 |
54 | VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
55 | {
56 | VertexShaderOutput output;
57 |
58 | float4 worldPosition = mul(input.Position, World);
59 | float4 viewPosition = mul(worldPosition, View);
60 | output.Position = mul(viewPosition, Projection);
61 |
62 | float4 normal = normalize(mul(input.Normal, WorldInverseTranspose));
63 | float lightIntensity = dot(normal, DiffuseLightDirection);
64 | output.Color = saturate(DiffuseColor * DiffuseIntensity * lightIntensity);
65 |
66 | output.Normal = normal;
67 |
68 | output.TextureCoordinate = input.TextureCoordinate;
69 | return output;
70 | }
71 |
72 | float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
73 | {
74 | float3 light = normalize(DiffuseLightDirection);
75 | float3 normal = normalize(input.Normal);
76 | float3 r = normalize(2 * dot(light, normal) * normal - light);
77 | float3 v = normalize(mul(normalize(ViewVector), World));
78 | float dotProduct = dot(r, v);
79 |
80 | float4 specular = SpecularIntensity * SpecularColor * max(pow(abs(dotProduct), Shininess), 0) * length(input.Color);
81 |
82 | float4 textureColor = tex2D(textureSampler, input.TextureCoordinate);
83 | textureColor.a = 1;
84 |
85 | return saturate(textureColor * (input.Color) + AmbientColor * AmbientIntensity + specular);
86 | }
87 |
88 | technique Textured
89 | {
90 | pass Pass1
91 | {
92 | VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
93 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
94 | }
95 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Effects/Toon.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 | //--------------------------- BASIC PROPERTIES ------------------------------
11 | // The world transformation
12 | float4x4 World;
13 |
14 | // The view transformation
15 | float4x4 View;
16 |
17 | // The projection transformation
18 | float4x4 Projection;
19 |
20 | // The transpose of the inverse of the world transformation,
21 | // used for transforming the vertex's normal
22 | float4x4 WorldInverseTranspose;
23 |
24 | //--------------------------- DIFFUSE LIGHT PROPERTIES ------------------------------
25 | // The direction of the diffuse light
26 | float3 DiffuseLightDirection = float3(-1, 0, 0);
27 |
28 | // The color of the diffuse light
29 | float4 DiffuseColor = float4(1, 1, 1, 1);
30 |
31 | // The intensity of the diffuse light
32 | float DiffuseIntensity = 1.0;
33 |
34 | //--------------------------- TOON SHADER PROPERTIES ------------------------------
35 | // The color to draw the lines in. Black is a good default.
36 | float4 LineColor = float4(0, 0, 0, 1);
37 |
38 | // The thickness of the lines. This may need to change, depending on the scale of
39 | // the objects you are drawing.
40 | float LineThickness = .03;
41 |
42 | //--------------------------- TEXTURE PROPERTIES ------------------------------
43 | // The texture being used for the object
44 | texture Texture;
45 |
46 | // The texture sampler, which will get the texture color
47 | sampler2D textureSampler = sampler_state
48 | {
49 | Texture = (Texture);
50 | MinFilter = Linear;
51 | MagFilter = Linear;
52 | AddressU = Clamp;
53 | AddressV = Clamp;
54 | };
55 |
56 | //--------------------------- DATA STRUCTURES ------------------------------
57 | // The structure used to store information between the application and the
58 | // vertex shader
59 | struct AppToVertex
60 | {
61 | float4 Position : POSITION0; // The position of the vertex
62 | float3 Normal : NORMAL0; // The vertex's normal
63 | float2 TextureCoordinate : TEXCOORD0; // The texture coordinate of the vertex
64 | };
65 |
66 | // The structure used to store information between the vertex shader and the
67 | // pixel shader
68 | struct VertexToPixel
69 | {
70 | float4 Position : POSITION0;
71 | float2 TextureCoordinate : TEXCOORD0;
72 | float3 Normal : TEXCOORD1;
73 | };
74 |
75 | //--------------------------- SHADERS ------------------------------
76 | // The vertex shader that does cel shading.
77 | // It really only does the basic transformation of the vertex location,
78 | // and normal, and copies the texture coordinate over.
79 | VertexToPixel CelVertexShader(AppToVertex input)
80 | {
81 | VertexToPixel output;
82 |
83 | // Transform the position
84 | float4 worldPosition = mul(input.Position, World);
85 | float4 viewPosition = mul(worldPosition, View);
86 | output.Position = mul(viewPosition, Projection);
87 |
88 | // Transform the normal
89 | output.Normal = normalize(mul(input.Normal, WorldInverseTranspose));
90 |
91 | // Copy over the texture coordinate
92 | output.TextureCoordinate = input.TextureCoordinate;
93 |
94 | return output;
95 | }
96 |
97 | // The pixel shader that does cel shading. Basically, it calculates
98 | // the color like is should, and then it discretizes the color into
99 | // one of four colors.
100 | float4 CelPixelShader(VertexToPixel input) : COLOR
101 | {
102 | // Calculate diffuse light amount
103 | float intensity = dot(normalize(DiffuseLightDirection), input.Normal);
104 | if(intensity < 0)
105 | intensity = 0;
106 |
107 | // Calculate what would normally be the final color, including texturing and diffuse lighting
108 | float4 color = tex2D(textureSampler, input.TextureCoordinate) * DiffuseColor * DiffuseIntensity;
109 | color.a = 1;
110 |
111 | // Discretize the intensity, based on a few cutoff points
112 | if (intensity > 0.95)
113 | color = float4(1.0,1,1,1.0) * color;
114 | else if (intensity > 0.5)
115 | color = float4(0.7,0.7,0.7,1.0) * color;
116 | else if (intensity > 0.05)
117 | color = float4(0.35,0.35,0.35,1.0) * color;
118 | else
119 | color = float4(0.1,0.1,0.1,1.0) * color;
120 |
121 | return color;
122 | }
123 |
124 | // The vertex shader that does the outlines
125 | VertexToPixel OutlineVertexShader(AppToVertex input)
126 | {
127 | VertexToPixel output = (VertexToPixel)0;
128 |
129 | // Calculate where the vertex ought to be. This line is equivalent
130 | // to the transformations in the CelVertexShader.
131 | float4 original = mul(mul(mul(input.Position, World), View), Projection);
132 |
133 | // Calculates the normal of the vertex like it ought to be.
134 | float4 normal = mul(mul(mul(input.Normal, World), View), Projection);
135 |
136 | // Take the correct "original" location and translate the vertex a little
137 | // bit in the direction of the normal to draw a slightly expanded object.
138 | // Later, we will draw over most of this with the right color, except the expanded
139 | // part, which will leave the outline that we want.
140 | output.Position = original + (mul(LineThickness, normal));
141 |
142 | return output;
143 | }
144 |
145 | // The pixel shader for the outline. It is pretty simple: draw everything with the
146 | // correct line color.
147 | float4 OutlinePixelShader(VertexToPixel input) : COLOR
148 | {
149 | return LineColor;
150 | }
151 |
152 | // The entire technique for doing toon shading
153 | technique Toon
154 | {
155 | // The first pass will go through and draw the back-facing triangles with the outline shader,
156 | // which will draw a slightly larger version of the model with the outline color. Later, the
157 | // model will get drawn normally, and draw over the top most of this, leaving only an outline.
158 | pass Pass1
159 | {
160 | VertexShader = compile VS_SHADERMODEL OutlineVertexShader();
161 | PixelShader = compile PS_SHADERMODEL OutlinePixelShader();
162 | CullMode = CW;
163 | }
164 |
165 | // The second pass will draw the model like normal, but with the cel pixel shader, which will
166 | // color the model with certain colors, giving us the cel/toon effect that we are looking for.
167 | pass Pass2
168 | {
169 | VertexShader = compile VS_SHADERMODEL CelVertexShader();
170 | PixelShader = compile PS_SHADERMODEL CelPixelShader();
171 | CullMode = CCW;
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Effects/ToonColored.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 | //--------------------------- BASIC PROPERTIES ------------------------------
11 | // The world transformation
12 | float4x4 World;
13 |
14 | // The view transformation
15 | float4x4 View;
16 |
17 | // The projection transformation
18 | float4x4 Projection;
19 |
20 | // The transpose of the inverse of the world transformation,
21 | // used for transforming the vertex's normal
22 | float4x4 WorldInverseTranspose;
23 |
24 | //--------------------------- DIFFUSE LIGHT PROPERTIES ------------------------------
25 | // The direction of the diffuse light
26 | float3 DiffuseLightDirection = float3(1, 0, 0);
27 |
28 | // The color of the diffuse light
29 | float4 DiffuseColor = float4(1, 1, 1, 1);
30 |
31 | // The intensity of the diffuse light
32 | float DiffuseIntensity = 1.0;
33 |
34 | //--------------------------- TOON SHADER PROPERTIES ------------------------------
35 | // The color to draw the lines in. Black is a good default.
36 | float4 LineColor = float4(0, 0, 0, 1);
37 |
38 | // The thickness of the lines. This may need to change, depending on the scale of
39 | // the objects you are drawing.
40 | float LineThickness = .03;
41 |
42 | //--------------------------- DATA STRUCTURES ------------------------------
43 | // The structure used to store information between the application and the
44 | // vertex shader
45 | struct AppToVertex
46 | {
47 | float4 Position : POSITION0; // The position of the vertex
48 | float3 Normal : NORMAL0; // The vertex's normal
49 | float4 Color : COLOR0; // The vertex's color
50 | };
51 |
52 | // The structure used to store information between the vertex shader and the
53 | // pixel shader
54 | struct VertexToPixel
55 | {
56 | float4 Position : POSITION0;
57 | float4 Color : COLOR0;
58 | float3 Normal : TEXCOORD1;
59 | };
60 |
61 | //--------------------------- SHADERS ------------------------------
62 | // The vertex shader that does cel shading.
63 | // It really only does the basic transformation of the vertex location,
64 | // and normal, and copies the texture coordinate over.
65 | VertexToPixel CelVertexShader(AppToVertex input)
66 | {
67 | VertexToPixel output;
68 |
69 | // Transform the position
70 | float4 worldPosition = mul(input.Position, World);
71 | float4 viewPosition = mul(worldPosition, View);
72 | output.Position = mul(viewPosition, Projection);
73 |
74 | // Transform the normal
75 | output.Normal = normalize(mul(input.Normal, WorldInverseTranspose));
76 |
77 | // Copy over the texture coordinate
78 | output.Color = input.Color;
79 |
80 | return output;
81 | }
82 |
83 | // The pixel shader that does cel shading. Basically, it calculates
84 | // the color like is should, and then it discretizes the color into
85 | // one of four colors.
86 | float4 CelPixelShader(VertexToPixel input) : COLOR
87 | {
88 | // Calculate diffuse light amount
89 | float intensity = dot(normalize(DiffuseLightDirection), input.Normal);
90 | if(intensity < 0)
91 | intensity = 0;
92 |
93 | // Calculate what would normally be the final color, including texturing and diffuse lighting
94 | float4 color = input.Color * DiffuseColor * DiffuseIntensity;
95 | color.a = 1;
96 |
97 | // Discretize the intensity, based on a few cutoff points
98 | if (intensity > 0.95)
99 | color = float4(1.0,1,1,1.0) * color;
100 | else if (intensity > 0.5)
101 | color = float4(0.7,0.7,0.7,1.0) * color;
102 | else if (intensity > 0.05)
103 | color = float4(0.35,0.35,0.35,1.0) * color;
104 | else
105 | color = float4(0.1,0.1,0.1,1.0) * color;
106 |
107 | return color;
108 | }
109 |
110 | // The vertex shader that does the outlines
111 | VertexToPixel OutlineVertexShader(AppToVertex input)
112 | {
113 | VertexToPixel output = (VertexToPixel)0;
114 |
115 | // Calculate where the vertex ought to be. This line is equivalent
116 | // to the transformations in the CelVertexShader.
117 | float4 original = mul(mul(mul(input.Position, World), View), Projection);
118 |
119 | // Calculates the normal of the vertex like it ought to be.
120 | float4 normal = mul(mul(mul(input.Normal, World), View), Projection);
121 |
122 | // Take the correct "original" location and translate the vertex a little
123 | // bit in the direction of the normal to draw a slightly expanded object.
124 | // Later, we will draw over most of this with the right color, except the expanded
125 | // part, which will leave the outline that we want.
126 | output.Position = original + (mul(LineThickness, normal));
127 |
128 | return output;
129 | }
130 |
131 | // The pixel shader for the outline. It is pretty simple: draw everything with the
132 | // correct line color.
133 | float4 OutlinePixelShader(VertexToPixel input) : COLOR
134 | {
135 | return LineColor;
136 | }
137 |
138 | // The entire technique for doing toon shading
139 | technique Toon
140 | {
141 | // The first pass will go through and draw the back-facing triangles with the outline shader,
142 | // which will draw a slightly larger version of the model with the outline color. Later, the
143 | // model will get drawn normally, and draw over the top most of this, leaving only an outline.
144 | pass Pass1
145 | {
146 | VertexShader = compile VS_SHADERMODEL OutlineVertexShader();
147 | PixelShader = compile PS_SHADERMODEL OutlinePixelShader();
148 | CullMode = CW;
149 | }
150 |
151 | // The second pass will draw the model like normal, but with the cel pixel shader, which will
152 | // color the model with certain colors, giving us the cel/toon effect that we are looking for.
153 | pass Pass2
154 | {
155 | VertexShader = compile VS_SHADERMODEL CelVertexShader();
156 | PixelShader = compile PS_SHADERMODEL CelPixelShader();
157 | CullMode = CCW;
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Effects/Transparency.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 | float4x4 World;
11 | float4x4 View;
12 | float4x4 Projection;
13 | float4x4 WorldInverseTranspose;
14 |
15 | float4 AmbientColor = float4(1, 1, 1, 1);
16 | float AmbientIntensity = 0.1;
17 | float Transparency = 0.5;
18 |
19 | // change way of light to get the same as XNA version picture (?)
20 | // I guess there is something deeper below, which produce negative value instead of positive one or vice versa
21 | float3 DiffuseLightDirection = float3(-1, 0, 0);
22 | float4 DiffuseColor = float4(1, 1, 1, 1);
23 | float DiffuseIntensity = 1.0;
24 |
25 | float Shininess = 200;
26 | float4 SpecularColor = float4(1, 1, 1, 1);
27 | float SpecularIntensity = 1;
28 | float3 ViewVector = float3(1, 0, 0);
29 |
30 | // sampler work as-is ?? I can't believe it !
31 | texture ModelTexture;
32 | sampler2D textureSampler = sampler_state {
33 | Texture = (ModelTexture);
34 | MinFilter = Linear;
35 | MagFilter = Linear;
36 | AddressU = Clamp;
37 | AddressV = Clamp;
38 | };
39 |
40 | struct VertexShaderInput
41 | {
42 | float4 Position : SV_POSITION;
43 | float4 Normal : NORMAL0;
44 | float2 TextureCoordinate : TEXCOORD0;
45 | };
46 |
47 | struct VertexShaderOutput
48 | {
49 | float4 Position : SV_POSITION;
50 | float4 Color : COLOR0;
51 | float3 Normal : TEXCOORD0;
52 | float2 TextureCoordinate : TEXCOORD1;
53 | };
54 |
55 | VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
56 | {
57 | VertexShaderOutput output;
58 |
59 | float4 worldPosition = mul(input.Position, World);
60 | float4 viewPosition = mul(worldPosition, View);
61 | output.Position = mul(viewPosition, Projection);
62 |
63 | float4 normal = normalize(mul(input.Normal, WorldInverseTranspose));
64 | float lightIntensity = dot(normal, DiffuseLightDirection);
65 | output.Color = saturate(DiffuseColor * DiffuseIntensity * lightIntensity);
66 |
67 | output.Normal = normal;
68 |
69 | output.TextureCoordinate = input.TextureCoordinate;
70 | return output;
71 | }
72 |
73 | float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
74 | {
75 | float3 light = normalize(DiffuseLightDirection);
76 | float3 normal = normalize(input.Normal);
77 | float3 r = normalize(2 * dot(light, normal) * normal - light);
78 | float3 v = normalize(mul(normalize(ViewVector), World));
79 | float dotProduct = dot(r, v);
80 |
81 | float4 specular = SpecularIntensity * SpecularColor * max(pow(abs(dotProduct), Shininess), 0) * length(input.Color);
82 |
83 | float4 textureColor = tex2D(textureSampler, input.TextureCoordinate);
84 | textureColor.a = 1;
85 |
86 | float4 color = saturate(textureColor * (input.Color) + AmbientColor * AmbientIntensity + specular);
87 | color.a = Transparency;
88 | return color;
89 | }
90 |
91 | technique AlphaT
92 | {
93 | pass Pass1
94 | {
95 | AlphaBlendEnable = TRUE;
96 |
97 | // example doesn't work if these two lines are enabled ! (skybox is not displayed, except for thevery first frame or two)
98 | //DestBlend = INVSRCALPHA;
99 | //SrcBlend = SRCALPHA;
100 | VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
101 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
102 | }
103 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Models/HelicopterTexture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RBWithakersShaders/Content/Models/HelicopterTexture.png
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Models/UntexturedSphere.FBX:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RBWithakersShaders/Content/Models/UntexturedSphere.FBX
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Skyboxes/Skybox.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 |
11 | //Exception levée : 'SharpDX.SharpDXException' dans SharpDX.dll
12 | //Warning: Vertex shader uses semantic 'SV_Position' for input register. Please update the shader and use the semantic 'POSITION0' instead. //The semantic 'SV_Position' should only be used for the vertex shader output or pixel shader input!
13 |
14 | float4x4 World;
15 | float4x4 View;
16 | float4x4 Projection;
17 |
18 | float3 CameraPosition;
19 |
20 | Texture SkyBoxTexture;
21 | samplerCUBE SkyBoxSampler = sampler_state
22 | {
23 | texture = ;
24 | magfilter = LINEAR;
25 | minfilter = LINEAR;
26 | mipfilter = LINEAR;
27 | AddressU = Mirror;
28 | AddressV = Mirror;
29 | };
30 |
31 | struct VertexShaderInput
32 | {
33 | float4 Position : POSITION0;
34 | };
35 |
36 | struct VertexShaderOutput
37 | {
38 | float4 Position : POSITION0;
39 | float3 TextureCoordinate : TEXCOORD0;
40 | };
41 |
42 | VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
43 | {
44 | VertexShaderOutput output;
45 |
46 | float4 worldPosition = mul(input.Position, World);
47 | float4 viewPosition = mul(worldPosition, View);
48 | output.Position = mul(viewPosition, Projection);
49 |
50 | float4 VertexPosition = mul(input.Position, World);
51 | output.TextureCoordinate = VertexPosition - CameraPosition;
52 |
53 | return output;
54 | }
55 |
56 | float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
57 | {
58 | return texCUBE(SkyBoxSampler, normalize(input.TextureCoordinate));
59 | }
60 |
61 | technique Skybox
62 | {
63 | pass Pass1
64 | {
65 | VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
66 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
67 | }
68 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Skyboxes/Sunset.dds:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RBWithakersShaders/Content/Skyboxes/Sunset.dds
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Skyboxes/cube.FBX:
--------------------------------------------------------------------------------
1 | ; FBX 7.3.0 project file
2 | ; Copyright (C) 1997-2010 Autodesk Inc. and/or its licensors.
3 | ; All rights reserved.
4 | ; ----------------------------------------------------
5 |
6 | FBXHeaderExtension: {
7 | FBXHeaderVersion: 1003
8 | FBXVersion: 7300
9 | CreationTimeStamp: {
10 | Version: 1000
11 | Year: 2016
12 | Month: 4
13 | Day: 12
14 | Hour: 11
15 | Minute: 22
16 | Second: 39
17 | Millisecond: 395
18 | }
19 | Creator: "FBX SDK/FBX Plugins version 2015.1"
20 | SceneInfo: "SceneInfo::GlobalInfo", "UserData" {
21 | Type: "UserData"
22 | Version: 100
23 | MetaData: {
24 | Version: 100
25 | Title: ""
26 | Subject: ""
27 | Author: ""
28 | Keywords: ""
29 | Revision: ""
30 | Comment: ""
31 | }
32 | Properties70: {
33 | P: "DocumentUrl", "KString", "Url", "", "K:\dev\MonoGame\ShadersConversion\RBWithakersShaders\Content\Skyboxes\cube.FBX"
34 | P: "SrcDocumentUrl", "KString", "Url", "", "K:\dev\MonoGame\ShadersConversion\RBWithakersShaders\Content\Skyboxes\cube.FBX"
35 | P: "Original", "Compound", "", ""
36 | P: "Original|ApplicationVendor", "KString", "", "", "Autodesk"
37 | P: "Original|ApplicationName", "KString", "", "", "3ds Max"
38 | P: "Original|ApplicationVersion", "KString", "", "", "2014"
39 | P: "Original|DateTime_GMT", "DateTime", "", "", "12/04/2016 09:22:39.394"
40 | P: "Original|FileName", "KString", "", "", "K:\dev\MonoGame\ShadersConversion\RBWithakersShaders\Content\Skyboxes\cube.FBX"
41 | P: "LastSaved", "Compound", "", ""
42 | P: "LastSaved|ApplicationVendor", "KString", "", "", "Autodesk"
43 | P: "LastSaved|ApplicationName", "KString", "", "", "3ds Max"
44 | P: "LastSaved|ApplicationVersion", "KString", "", "", "2014"
45 | P: "LastSaved|DateTime_GMT", "DateTime", "", "", "12/04/2016 09:22:39.394"
46 | }
47 | }
48 | }
49 | GlobalSettings: {
50 | Version: 1000
51 | Properties70: {
52 | P: "UpAxis", "int", "Integer", "",1
53 | P: "UpAxisSign", "int", "Integer", "",1
54 | P: "FrontAxis", "int", "Integer", "",2
55 | P: "FrontAxisSign", "int", "Integer", "",1
56 | P: "CoordAxis", "int", "Integer", "",0
57 | P: "CoordAxisSign", "int", "Integer", "",1
58 | P: "OriginalUpAxis", "int", "Integer", "",2
59 | P: "OriginalUpAxisSign", "int", "Integer", "",1
60 | P: "UnitScaleFactor", "double", "Number", "",1
61 | P: "OriginalUnitScaleFactor", "double", "Number", "",2.54
62 | P: "AmbientColor", "ColorRGB", "Color", "",0,0,0
63 | P: "DefaultCamera", "KString", "", "", "Producer Perspective"
64 | P: "TimeMode", "enum", "", "",6
65 | P: "TimeProtocol", "enum", "", "",2
66 | P: "SnapOnFrameMode", "enum", "", "",0
67 | P: "TimeSpanStart", "KTime", "Time", "",0
68 | P: "TimeSpanStop", "KTime", "Time", "",153953860000
69 | P: "CustomFrameRate", "double", "Number", "",-1
70 | P: "TimeMarker", "Compound", "", ""
71 | P: "CurrentTimeMarker", "int", "Integer", "",-1
72 | }
73 | }
74 |
75 | ; Documents Description
76 | ;------------------------------------------------------------------
77 |
78 | Documents: {
79 | Count: 1
80 | Document: 1277068448, "", "Scene" {
81 | Properties70: {
82 | P: "SourceObject", "object", "", ""
83 | P: "ActiveAnimStackName", "KString", "", "", ""
84 | }
85 | RootNode: 0
86 | }
87 | }
88 |
89 | ; Document References
90 | ;------------------------------------------------------------------
91 |
92 | References: {
93 | }
94 |
95 | ; Object definitions
96 | ;------------------------------------------------------------------
97 |
98 | Definitions: {
99 | Version: 100
100 | Count: 6
101 | ObjectType: "GlobalSettings" {
102 | Count: 1
103 | }
104 | ObjectType: "AnimationStack" {
105 | Count: 1
106 | PropertyTemplate: "FbxAnimStack" {
107 | Properties70: {
108 | P: "Description", "KString", "", "", ""
109 | P: "LocalStart", "KTime", "Time", "",0
110 | P: "LocalStop", "KTime", "Time", "",0
111 | P: "ReferenceStart", "KTime", "Time", "",0
112 | P: "ReferenceStop", "KTime", "Time", "",0
113 | }
114 | }
115 | }
116 | ObjectType: "AnimationLayer" {
117 | Count: 1
118 | PropertyTemplate: "FbxAnimLayer" {
119 | Properties70: {
120 | P: "Weight", "Number", "", "A",100
121 | P: "Mute", "bool", "", "",0
122 | P: "Solo", "bool", "", "",0
123 | P: "Lock", "bool", "", "",0
124 | P: "Color", "ColorRGB", "Color", "",0.8,0.8,0.8
125 | P: "BlendMode", "enum", "", "",0
126 | P: "RotationAccumulationMode", "enum", "", "",0
127 | P: "ScaleAccumulationMode", "enum", "", "",0
128 | P: "BlendModeBypass", "ULongLong", "", "",0
129 | }
130 | }
131 | }
132 | ObjectType: "Model" {
133 | Count: 1
134 | PropertyTemplate: "FbxNode" {
135 | Properties70: {
136 | P: "QuaternionInterpolate", "enum", "", "",0
137 | P: "RotationOffset", "Vector3D", "Vector", "",0,0,0
138 | P: "RotationPivot", "Vector3D", "Vector", "",0,0,0
139 | P: "ScalingOffset", "Vector3D", "Vector", "",0,0,0
140 | P: "ScalingPivot", "Vector3D", "Vector", "",0,0,0
141 | P: "TranslationActive", "bool", "", "",0
142 | P: "TranslationMin", "Vector3D", "Vector", "",0,0,0
143 | P: "TranslationMax", "Vector3D", "Vector", "",0,0,0
144 | P: "TranslationMinX", "bool", "", "",0
145 | P: "TranslationMinY", "bool", "", "",0
146 | P: "TranslationMinZ", "bool", "", "",0
147 | P: "TranslationMaxX", "bool", "", "",0
148 | P: "TranslationMaxY", "bool", "", "",0
149 | P: "TranslationMaxZ", "bool", "", "",0
150 | P: "RotationOrder", "enum", "", "",0
151 | P: "RotationSpaceForLimitOnly", "bool", "", "",0
152 | P: "RotationStiffnessX", "double", "Number", "",0
153 | P: "RotationStiffnessY", "double", "Number", "",0
154 | P: "RotationStiffnessZ", "double", "Number", "",0
155 | P: "AxisLen", "double", "Number", "",10
156 | P: "PreRotation", "Vector3D", "Vector", "",0,0,0
157 | P: "PostRotation", "Vector3D", "Vector", "",0,0,0
158 | P: "RotationActive", "bool", "", "",0
159 | P: "RotationMin", "Vector3D", "Vector", "",0,0,0
160 | P: "RotationMax", "Vector3D", "Vector", "",0,0,0
161 | P: "RotationMinX", "bool", "", "",0
162 | P: "RotationMinY", "bool", "", "",0
163 | P: "RotationMinZ", "bool", "", "",0
164 | P: "RotationMaxX", "bool", "", "",0
165 | P: "RotationMaxY", "bool", "", "",0
166 | P: "RotationMaxZ", "bool", "", "",0
167 | P: "InheritType", "enum", "", "",0
168 | P: "ScalingActive", "bool", "", "",0
169 | P: "ScalingMin", "Vector3D", "Vector", "",0,0,0
170 | P: "ScalingMax", "Vector3D", "Vector", "",1,1,1
171 | P: "ScalingMinX", "bool", "", "",0
172 | P: "ScalingMinY", "bool", "", "",0
173 | P: "ScalingMinZ", "bool", "", "",0
174 | P: "ScalingMaxX", "bool", "", "",0
175 | P: "ScalingMaxY", "bool", "", "",0
176 | P: "ScalingMaxZ", "bool", "", "",0
177 | P: "GeometricTranslation", "Vector3D", "Vector", "",0,0,0
178 | P: "GeometricRotation", "Vector3D", "Vector", "",0,0,0
179 | P: "GeometricScaling", "Vector3D", "Vector", "",1,1,1
180 | P: "MinDampRangeX", "double", "Number", "",0
181 | P: "MinDampRangeY", "double", "Number", "",0
182 | P: "MinDampRangeZ", "double", "Number", "",0
183 | P: "MaxDampRangeX", "double", "Number", "",0
184 | P: "MaxDampRangeY", "double", "Number", "",0
185 | P: "MaxDampRangeZ", "double", "Number", "",0
186 | P: "MinDampStrengthX", "double", "Number", "",0
187 | P: "MinDampStrengthY", "double", "Number", "",0
188 | P: "MinDampStrengthZ", "double", "Number", "",0
189 | P: "MaxDampStrengthX", "double", "Number", "",0
190 | P: "MaxDampStrengthY", "double", "Number", "",0
191 | P: "MaxDampStrengthZ", "double", "Number", "",0
192 | P: "PreferedAngleX", "double", "Number", "",0
193 | P: "PreferedAngleY", "double", "Number", "",0
194 | P: "PreferedAngleZ", "double", "Number", "",0
195 | P: "LookAtProperty", "object", "", ""
196 | P: "UpVectorProperty", "object", "", ""
197 | P: "Show", "bool", "", "",1
198 | P: "NegativePercentShapeSupport", "bool", "", "",1
199 | P: "DefaultAttributeIndex", "int", "Integer", "",-1
200 | P: "Freeze", "bool", "", "",0
201 | P: "LODBox", "bool", "", "",0
202 | P: "Lcl Translation", "Lcl Translation", "", "A",0,0,0
203 | P: "Lcl Rotation", "Lcl Rotation", "", "A",0,0,0
204 | P: "Lcl Scaling", "Lcl Scaling", "", "A",1,1,1
205 | P: "Visibility", "Visibility", "", "A",1
206 | P: "Visibility Inheritance", "Visibility Inheritance", "", "",1
207 | }
208 | }
209 | }
210 | ObjectType: "Material" {
211 | Count: 1
212 | PropertyTemplate: "FbxSurfacePhong" {
213 | Properties70: {
214 | P: "ShadingModel", "KString", "", "", "Phong"
215 | P: "MultiLayer", "bool", "", "",0
216 | P: "EmissiveColor", "Color", "", "A",0,0,0
217 | P: "EmissiveFactor", "Number", "", "A",1
218 | P: "AmbientColor", "Color", "", "A",0.2,0.2,0.2
219 | P: "AmbientFactor", "Number", "", "A",1
220 | P: "DiffuseColor", "Color", "", "A",0.8,0.8,0.8
221 | P: "DiffuseFactor", "Number", "", "A",1
222 | P: "Bump", "Vector3D", "Vector", "",0,0,0
223 | P: "NormalMap", "Vector3D", "Vector", "",0,0,0
224 | P: "BumpFactor", "double", "Number", "",1
225 | P: "TransparentColor", "Color", "", "A",0,0,0
226 | P: "TransparencyFactor", "Number", "", "A",0
227 | P: "DisplacementColor", "ColorRGB", "Color", "",0,0,0
228 | P: "DisplacementFactor", "double", "Number", "",1
229 | P: "VectorDisplacementColor", "ColorRGB", "Color", "",0,0,0
230 | P: "VectorDisplacementFactor", "double", "Number", "",1
231 | P: "SpecularColor", "Color", "", "A",0.2,0.2,0.2
232 | P: "SpecularFactor", "Number", "", "A",1
233 | P: "ShininessExponent", "Number", "", "A",20
234 | P: "ReflectionColor", "Color", "", "A",0,0,0
235 | P: "ReflectionFactor", "Number", "", "A",1
236 | }
237 | }
238 | }
239 | ObjectType: "Geometry" {
240 | Count: 1
241 | PropertyTemplate: "FbxMesh" {
242 | Properties70: {
243 | P: "Color", "ColorRGB", "Color", "",0.8,0.8,0.8
244 | P: "BBoxMin", "Vector3D", "Vector", "",0,0,0
245 | P: "BBoxMax", "Vector3D", "Vector", "",0,0,0
246 | P: "Primary Visibility", "bool", "", "",1
247 | P: "Casts Shadows", "bool", "", "",1
248 | P: "Receive Shadows", "bool", "", "",1
249 | }
250 | }
251 | }
252 | }
253 |
254 | ; Object properties
255 | ;------------------------------------------------------------------
256 |
257 | Objects: {
258 | Geometry: 1923091072, "Geometry::", "Mesh" {
259 | Vertices: *24 {
260 | a: -1,-1,1,-1,1,1,1,1,1,1,-1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1
261 | }
262 | PolygonVertexIndex: *36 {
263 | a: 2,1,-1,2,0,-4,2,3,-7,3,7,-7,3,0,-8,0,4,-8,1,2,-6,2,6,-6,7,4,-6,7,5,-7,0,1,-5,1,5,-5
264 | }
265 | Edges: *18 {
266 | a: 0,1,2,4,5,7,8,9,10,13,15,16,19,20,22,25,26,31
267 | }
268 | GeometryVersion: 124
269 | LayerElementNormal: 0 {
270 | Version: 101
271 | Name: ""
272 | MappingInformationType: "ByPolygonVertex"
273 | ReferenceInformationType: "Direct"
274 | Normals: *108 {
275 | a: 0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854
276 | }
277 | }
278 | LayerElementSmoothing: 0 {
279 | Version: 102
280 | Name: ""
281 | MappingInformationType: "ByPolygon"
282 | ReferenceInformationType: "Direct"
283 | Smoothing: *12 {
284 | a: 1,1,1,1,1,1,1,1,1,1,1,1
285 | }
286 | }
287 | LayerElementMaterial: 0 {
288 | Version: 101
289 | Name: ""
290 | MappingInformationType: "AllSame"
291 | ReferenceInformationType: "IndexToDirect"
292 | Materials: *1 {
293 | a: 0
294 | }
295 | }
296 | Layer: 0 {
297 | Version: 100
298 | LayerElement: {
299 | Type: "LayerElementNormal"
300 | TypedIndex: 0
301 | }
302 | LayerElement: {
303 | Type: "LayerElementMaterial"
304 | TypedIndex: 0
305 | }
306 | LayerElement: {
307 | Type: "LayerElementSmoothing"
308 | TypedIndex: 0
309 | }
310 | }
311 | }
312 | Model: 1922364208, "Model::cube1", "Mesh" {
313 | Version: 232
314 | Properties70: {
315 | P: "PreRotation", "Vector3D", "Vector", "",-90,-0,0
316 | P: "RotationActive", "bool", "", "",1
317 | P: "InheritType", "enum", "", "",1
318 | P: "ScalingMax", "Vector3D", "Vector", "",0,0,0
319 | P: "DefaultAttributeIndex", "int", "Integer", "",0
320 | P: "Lcl Rotation", "Lcl Rotation", "", "A",90.0000025044782,-0,0
321 | P: "Lcl Scaling", "Lcl Scaling", "", "A",0.999999977350235,0.999999977350235,0.999999977350235
322 | P: "MaxHandle", "int", "Integer", "UH",2
323 | }
324 | Shading: T
325 | Culling: "CullingOff"
326 | }
327 | Material: 1276274944, "Material::default", "" {
328 | Version: 102
329 | ShadingModel: "phong"
330 | MultiLayer: 0
331 | Properties70: {
332 | P: "ShadingModel", "KString", "", "", "phong"
333 | P: "EmissiveFactor", "Number", "", "A",0
334 | P: "AmbientColor", "Color", "", "A",1,1,1
335 | P: "DiffuseColor", "Color", "", "A",1,1,1
336 | P: "TransparentColor", "Color", "", "A",1,1,1
337 | P: "SpecularColor", "Color", "", "A",1,1,1
338 | P: "ShininessExponent", "Number", "", "A",128
339 | P: "Emissive", "Vector3D", "Vector", "",0,0,0
340 | P: "Ambient", "Vector3D", "Vector", "",1,1,1
341 | P: "Diffuse", "Vector3D", "Vector", "",1,1,1
342 | P: "Specular", "Vector3D", "Vector", "",1,1,1
343 | P: "Shininess", "double", "Number", "",128
344 | P: "Opacity", "double", "Number", "",1
345 | P: "Reflectivity", "double", "Number", "",0
346 | }
347 | }
348 | }
349 |
350 | ; Object connections
351 | ;------------------------------------------------------------------
352 |
353 | Connections: {
354 |
355 | ;Model::cube1, Model::RootNode
356 | C: "OO",1922364208,0
357 |
358 | ;AnimLayer::BaseLayer, AnimStack::Take 001
359 | C: "OO",1217557904,1283358384
360 |
361 | ;Material::default, Model::cube1
362 | C: "OO",1276274944,1922364208
363 |
364 | ;Geometry::, Model::cube1
365 | C: "OO",1923091072,1922364208
366 | }
367 |
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Textures/HelicopterNormalMap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RBWithakersShaders/Content/Textures/HelicopterNormalMap.png
--------------------------------------------------------------------------------
/RBWithakersShaders/Content/Textures/HelicopterTexture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RBWithakersShaders/Content/Textures/HelicopterTexture.png
--------------------------------------------------------------------------------
/RBWithakersShaders/Diffuse.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 |
8 | namespace RBWithakersShaders
9 | {
10 | public class Diffuse : Microsoft.Xna.Framework.Game
11 | {
12 | GraphicsDeviceManager graphics;
13 | SpriteBatch spriteBatch;
14 | Effect effect;
15 |
16 | Matrix world = Matrix.CreateTranslation(0, 0, 0);
17 | Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 10), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
18 | Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 600f, 0.1f, 100f);
19 | float angle = 0;
20 | float distance = 10;
21 |
22 | Model model;
23 |
24 | public Diffuse()
25 | {
26 | graphics = new GraphicsDeviceManager(this);
27 | Content.RootDirectory = "Content";
28 | }
29 |
30 | protected override void Initialize()
31 | {
32 | base.Initialize();
33 | }
34 |
35 | protected override void LoadContent()
36 | {
37 | spriteBatch = new SpriteBatch(GraphicsDevice);
38 |
39 | model = Content.Load("Models/Helicopter");
40 | effect = Content.Load("Effects/Diffuse");
41 | }
42 |
43 | protected override void UnloadContent()
44 | {
45 | }
46 |
47 | protected override void Update(GameTime gameTime)
48 | {
49 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
50 | Exit();
51 |
52 | angle += 0.01f;
53 | view = Matrix.CreateLookAt(distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
54 |
55 | base.Update(gameTime);
56 | }
57 |
58 | protected override void Draw(GameTime gameTime)
59 | {
60 | GraphicsDevice.Clear(Color.Black);
61 |
62 | //DrawModel(model, world, view, projection);
63 |
64 | DrawModelWithEffect(model, world, view, projection);
65 | base.Draw(gameTime);
66 | }
67 |
68 | private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
69 | {
70 | foreach (ModelMesh mesh in model.Meshes)
71 | {
72 | foreach (BasicEffect effect in mesh.Effects)
73 | {
74 | effect.EnableDefaultLighting();
75 | effect.PreferPerPixelLighting = true;
76 | effect.World = world * mesh.ParentBone.Transform;
77 | effect.View = view;
78 | effect.Projection = projection;
79 | }
80 | mesh.Draw();
81 | }
82 | }
83 |
84 | private void DrawModelWithEffect(Model model, Matrix world, Matrix view, Matrix projection)
85 | {
86 | foreach (ModelMesh mesh in model.Meshes)
87 | {
88 | foreach (ModelMeshPart part in mesh.MeshParts)
89 | {
90 | part.Effect = effect;
91 | effect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
92 | effect.Parameters["View"].SetValue(view);
93 | effect.Parameters["Projection"].SetValue(projection);
94 |
95 | //effect.Parameters["AmbientColor"].SetValue(Color.Green.ToVector4());
96 | //effect.Parameters["AmbientIntensity"].SetValue(0.5f);
97 |
98 | //diffuse
99 | Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * world));
100 | effect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix);
101 |
102 | }
103 | mesh.Draw();
104 | }
105 | }
106 | }
107 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RBWithakersShaders/Icon.ico
--------------------------------------------------------------------------------
/RBWithakersShaders/NormalMap.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 |
8 | namespace RBWithakersShaders
9 | {
10 | public class NormalMap : Microsoft.Xna.Framework.Game
11 | {
12 | GraphicsDeviceManager graphics;
13 | SpriteBatch spriteBatch;
14 | Effect effect;
15 |
16 | Matrix world = Matrix.CreateTranslation(0, 0, 0);
17 | Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 10), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
18 | Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 600f, 0.1f, 100f);
19 | float angle = 0;
20 | float distance = 10;
21 |
22 | Model model;
23 | Texture2D texture;
24 | private Texture2D normalMap;
25 |
26 | Vector3 viewVector;
27 |
28 | public NormalMap()
29 | {
30 | graphics = new GraphicsDeviceManager(this);
31 | Content.RootDirectory = "Content";
32 | }
33 |
34 | protected override void Initialize()
35 | {
36 | base.Initialize();
37 | }
38 |
39 | protected override void LoadContent()
40 | {
41 | spriteBatch = new SpriteBatch(GraphicsDevice);
42 |
43 | model = Content.Load("Models/Helicopter");
44 | effect = Content.Load("Effects/NormalMap");
45 | texture = Content.Load("Textures/HelicopterTexture");
46 | normalMap = Content.Load("Textures/HelicopterNormalMap");
47 | }
48 |
49 | protected override void UnloadContent()
50 | {
51 | }
52 |
53 | protected override void Update(GameTime gameTime)
54 | {
55 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
56 | Exit();
57 |
58 | angle += 0.01f;
59 | Vector3 cameraLocation = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
60 | Vector3 cameraTarget = new Vector3(0, 0, 0);
61 | viewVector = Vector3.Transform(cameraTarget - cameraLocation, Matrix.CreateRotationY(0));
62 | viewVector.Normalize();
63 | view = Matrix.CreateLookAt(cameraLocation, cameraTarget, new Vector3(0, 1, 0));
64 |
65 | base.Update(gameTime);
66 | }
67 | protected override void Draw(GameTime gameTime)
68 | {
69 | GraphicsDevice.Clear(Color.Black);
70 |
71 | DrawModelWithEffect(model, world, view, projection);
72 | base.Draw(gameTime);
73 | }
74 |
75 |
76 | private void DrawModelWithEffect(Model model, Matrix world, Matrix view, Matrix projection)
77 | {
78 | foreach (ModelMesh mesh in model.Meshes)
79 | {
80 | foreach (ModelMeshPart part in mesh.MeshParts)
81 | {
82 | part.Effect = effect;
83 | effect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
84 | effect.Parameters["View"].SetValue(view);
85 | effect.Parameters["Projection"].SetValue(projection);
86 | effect.Parameters["ViewVector"].SetValue(viewVector);
87 | effect.Parameters["ModelTexture"].SetValue(texture);
88 | effect.Parameters["NormalMap"].SetValue(normalMap);
89 |
90 | //effect.Parameters["AmbientColor"].SetValue(Color.Green.ToVector4());
91 | //effect.Parameters["AmbientIntensity"].SetValue(0.5f);
92 |
93 | Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * world));
94 | effect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix);
95 | }
96 | mesh.Draw();
97 | }
98 | }
99 | }
100 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace RBWithakersShaders
4 | {
5 | #if WINDOWS || LINUX
6 | public static class Program
7 | {
8 | [STAThread]
9 | static void Main()
10 | {
11 | using (var game = new Transparency())
12 | game.Run();
13 | }
14 | }
15 | #endif
16 | }
17 |
--------------------------------------------------------------------------------
/RBWithakersShaders/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("RBWithakersShaders")]
9 | [assembly: AssemblyProduct("RBWithakersShaders")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("ef318749-9db3-462a-9188-d9da1db8b92d")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/RBWithakersShaders/RBWithakersShaders.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | x86
7 | 8.0.30703
8 | 2.0
9 | {9E2E7EE3-43E0-4E7C-AC9B-260A2B7D1B64}
10 | WinExe
11 | Properties
12 | RBWithakersShaders
13 | RBWithakersShaders
14 | 512
15 | Windows
16 | v4.5
17 |
18 |
19 | x86
20 | true
21 | full
22 | false
23 | bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\
24 | DEBUG;TRACE;WINDOWS
25 | prompt
26 | 4
27 |
28 |
29 | x86
30 | pdbonly
31 | true
32 | bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\
33 | TRACE;WINDOWS
34 | prompt
35 | 4
36 |
37 |
38 | Icon.ico
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | False
57 | C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
76 |
--------------------------------------------------------------------------------
/RBWithakersShaders/RBWithakersShaders.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 14 for Windows Desktop
4 | VisualStudioVersion = 14.0.24720.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RBWithakersShaders", "RBWithakersShaders.csproj", "{9E2E7EE3-43E0-4E7C-AC9B-260A2B7D1B64}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x86 = Debug|x86
11 | Release|x86 = Release|x86
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {9E2E7EE3-43E0-4E7C-AC9B-260A2B7D1B64}.Debug|x86.ActiveCfg = Debug|x86
15 | {9E2E7EE3-43E0-4E7C-AC9B-260A2B7D1B64}.Debug|x86.Build.0 = Debug|x86
16 | {9E2E7EE3-43E0-4E7C-AC9B-260A2B7D1B64}.Release|x86.ActiveCfg = Release|x86
17 | {9E2E7EE3-43E0-4E7C-AC9B-260A2B7D1B64}.Release|x86.Build.0 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/RBWithakersShaders/Reflection.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 |
8 | namespace RBWithakersShaders
9 | {
10 | public class Reflection : Microsoft.Xna.Framework.Game
11 | {
12 | GraphicsDeviceManager graphics;
13 | SpriteBatch spriteBatch;
14 |
15 | Skybox skybox;
16 | Matrix world = Matrix.Identity;
17 | Matrix view = Matrix.CreateLookAt(new Vector3(20, 0, 0), new Vector3(0, 0, 0), Vector3.UnitY);
18 | Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 0.1f, 100f);
19 | Vector3 cameraPosition;
20 | float angle = 0;
21 | float distance = 20;
22 |
23 | private Model model;
24 | private Effect effect;
25 | private TextureCube skyboxTexture;
26 |
27 | Vector3 viewVector;
28 |
29 | public Reflection()
30 | {
31 | graphics = new GraphicsDeviceManager(this);
32 | Content.RootDirectory = "Content";
33 | }
34 |
35 | protected override void Initialize()
36 | {
37 | base.Initialize();
38 | }
39 |
40 | protected override void LoadContent()
41 | {
42 | spriteBatch = new SpriteBatch(GraphicsDevice);
43 |
44 | skyboxTexture = Content.Load("Skyboxes/Sunset");
45 | model = Content.Load("Models/UntexturedSphere");
46 | effect = Content.Load("Effects/Reflection");
47 |
48 | skybox = new Skybox("Skyboxes/Sunset", Content);
49 | }
50 |
51 | protected override void UnloadContent()
52 | {
53 | }
54 |
55 | protected override void Update(GameTime gameTime)
56 | {
57 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
58 | Exit();
59 |
60 | cameraPosition = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
61 | Vector3 cameraTarget = new Vector3(0, 0, 0);
62 | viewVector = Vector3.Transform(cameraTarget - cameraPosition, Matrix.CreateRotationY(0));
63 | viewVector.Normalize();
64 |
65 | angle += 0.002f;
66 | view = Matrix.CreateLookAt(cameraPosition, new Vector3(0, 0, 0), Vector3.UnitY);
67 |
68 | base.Update(gameTime);
69 | }
70 |
71 |
72 | protected override void Draw(GameTime gameTime)
73 | {
74 | GraphicsDevice.Clear(Color.Black);
75 |
76 | RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState;
77 | RasterizerState rasterizerState = new RasterizerState();
78 | rasterizerState.CullMode = CullMode.None;
79 | graphics.GraphicsDevice.RasterizerState = rasterizerState;
80 |
81 | skybox.Draw(view, projection, cameraPosition);
82 |
83 | graphics.GraphicsDevice.RasterizerState = originalRasterizerState;
84 |
85 | DrawModelWithEffect(model, world, view, projection);
86 |
87 | base.Draw(gameTime);
88 | }
89 |
90 |
91 | private void DrawModelWithEffect(Model model, Matrix world, Matrix view, Matrix projection)
92 | {
93 | foreach (ModelMesh mesh in model.Meshes)
94 | {
95 | foreach (ModelMeshPart part in mesh.MeshParts)
96 | {
97 | part.Effect = effect;
98 | effect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
99 | effect.Parameters["View"].SetValue(view);
100 | effect.Parameters["Projection"].SetValue(projection);
101 | effect.Parameters["SkyboxTexture"].SetValue(skyboxTexture);
102 | effect.Parameters["CameraPosition"].SetValue(this.cameraPosition);
103 | effect.Parameters["WorldInverseTranspose"].SetValue(
104 | Matrix.Transpose(Matrix.Invert(world * mesh.ParentBone.Transform)));
105 | }
106 | mesh.Draw();
107 | }
108 | }
109 | }
110 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Skybox.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | using Microsoft.Xna.Framework;
5 | using Microsoft.Xna.Framework.Graphics;
6 | using Microsoft.Xna.Framework.Content;
7 |
8 | namespace RBWithakersShaders
9 | {
10 | ///
11 | /// Handles all of the aspects of working with a skybox.
12 | ///
13 | public class Skybox
14 | {
15 | ///
16 | /// The skybox model, which will just be a cube
17 | ///
18 | private Model skyBox;
19 |
20 | ///
21 | /// The actual skybox texture
22 | ///
23 | private TextureCube skyBoxTexture;
24 |
25 | ///
26 | /// The effect file that the skybox will use to render
27 | ///
28 | private Effect skyBoxEffect;
29 |
30 | ///
31 | /// The size of the cube, used so that we can resize the box
32 | /// for different sized environments.
33 | ///
34 | private float size = 50f;
35 |
36 | ///
37 | /// Creates a new skybox
38 | ///
39 | /// the name of the skybox texture to use
40 | public Skybox(string skyboxTexture, ContentManager Content)
41 | {
42 | skyBox = Content.Load("Skyboxes/cube");
43 | skyBoxTexture = Content.Load(skyboxTexture);
44 | skyBoxEffect = Content.Load("Skyboxes/Skybox");
45 | }
46 |
47 | ///
48 | /// Does the actual drawing of the skybox with our skybox effect.
49 | /// There is no world matrix, because we're assuming the skybox won't
50 | /// be moved around. The size of the skybox can be changed with the size
51 | /// variable.
52 | ///
53 | /// The view matrix for the effect
54 | /// The projection matrix for the effect
55 | /// The position of the camera
56 | public void Draw(Matrix view, Matrix projection, Vector3 cameraPosition)
57 | {
58 | // Go through each pass in the effect, but we know there is only one...
59 | foreach (EffectPass pass in skyBoxEffect.CurrentTechnique.Passes)
60 | {
61 | // Draw all of the components of the mesh, but we know the cube really
62 | // only has one mesh
63 | foreach (ModelMesh mesh in skyBox.Meshes)
64 | {
65 | // Assign the appropriate values to each of the parameters
66 | foreach (ModelMeshPart part in mesh.MeshParts)
67 | {
68 | part.Effect = skyBoxEffect;
69 | part.Effect.Parameters["World"].SetValue(
70 | Matrix.CreateScale(size) * Matrix.CreateTranslation(cameraPosition));
71 | part.Effect.Parameters["View"].SetValue(view);
72 | part.Effect.Parameters["Projection"].SetValue(projection);
73 | part.Effect.Parameters["SkyBoxTexture"].SetValue(skyBoxTexture);
74 | part.Effect.Parameters["CameraPosition"].SetValue(cameraPosition);
75 | }
76 |
77 | // Draw the mesh with the skybox effect
78 | mesh.Draw();
79 | }
80 | }
81 | }
82 | }
83 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Skybox.fx:
--------------------------------------------------------------------------------
1 | #if OPENGL
2 | #define SV_POSITION POSITION
3 | #define VS_SHADERMODEL vs_3_0
4 | #define PS_SHADERMODEL ps_3_0
5 | #else
6 | #define VS_SHADERMODEL vs_4_0_level_9_1
7 | #define PS_SHADERMODEL ps_4_0_level_9_1
8 | #endif
9 |
10 | float4x4 World;
11 | float4x4 View;
12 | float4x4 Projection;
13 |
14 | float3 CameraPosition;
15 |
16 | Texture SkyBoxTexture;
17 | samplerCUBE SkyBoxSampler = sampler_state
18 | {
19 | texture = ;
20 | magfilter = LINEAR;
21 | minfilter = LINEAR;
22 | mipfilter = LINEAR;
23 | AddressU = Mirror;
24 | AddressV = Mirror;
25 | };
26 |
27 | struct VertexShaderInput
28 | {
29 | float4 Position : SV_POSITION;
30 | };
31 |
32 | struct VertexShaderOutput
33 | {
34 | float4 Position : SV_POSITION;
35 | float3 TextureCoordinate : TEXCOORD0;
36 | };
37 |
38 | VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
39 | {
40 | VertexShaderOutput output;
41 |
42 | float4 worldPosition = mul(input.Position, World);
43 | float4 viewPosition = mul(worldPosition, View);
44 | output.Position = mul(viewPosition, Projection);
45 |
46 | float4 VertexPosition = mul(input.Position, World);
47 | output.TextureCoordinate = VertexPosition - CameraPosition;
48 |
49 | return output;
50 | }
51 |
52 | float4 PixelShaderFunction(VertexShaderOutput input) : COLOR
53 | {
54 | return texCUBE(SkyBoxSampler, normalize(input.TextureCoordinate));
55 | }
56 |
57 | technique Skybox
58 | {
59 | pass Pass1
60 | {
61 | VertexShader = compile VS_SHADERMODEL VertexShaderFunction();
62 | PixelShader = compile PS_SHADERMODEL PixelShaderFunction();
63 | }
64 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/SkyboxShader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 | namespace RBWithakersShaders
8 | {
9 | class SkyboxShader : Microsoft.Xna.Framework.Game
10 | {
11 | GraphicsDeviceManager graphics;
12 | SpriteBatch spriteBatch;
13 | Effect effect;
14 |
15 | Skybox skybox;
16 | Matrix world = Matrix.Identity;
17 | Matrix view = Matrix.CreateLookAt(new Vector3(20, 0, 0), new Vector3(0, 0, 0), Vector3.UnitY);
18 | Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 600f, 0.1f, 100f);
19 | Vector3 cameraPosition;
20 | float angle = 0;
21 | float distance = 20;
22 |
23 | Vector3 viewVector;
24 |
25 | Model model;
26 | Texture2D texture;
27 | private Texture2D normalMap;
28 |
29 | public SkyboxShader()
30 | {
31 | graphics = new GraphicsDeviceManager(this);
32 | Content.RootDirectory = "Content";
33 | }
34 |
35 | protected override void Initialize()
36 | {
37 | base.Initialize();
38 | }
39 |
40 | protected override void LoadContent()
41 | {
42 | spriteBatch = new SpriteBatch(GraphicsDevice);
43 |
44 | model = Content.Load("Models/Helicopter");
45 | effect = Content.Load("Effects/NormalMap");
46 | texture = Content.Load("Textures/HelicopterTexture");
47 | normalMap = Content.Load("Textures/HelicopterNormalMap");
48 |
49 | skybox = new Skybox("Skyboxes/Sunset", Content);
50 | }
51 |
52 | protected override void UnloadContent()
53 | {
54 | }
55 |
56 | protected override void Update(GameTime gameTime)
57 | {
58 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
59 | Exit();
60 |
61 | cameraPosition = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
62 | Vector3 cameraTarget = new Vector3(0, 0, 0);
63 | viewVector = Vector3.Transform(cameraTarget - cameraPosition, Matrix.CreateRotationY(0));
64 | viewVector.Normalize();
65 |
66 | angle += 0.002f;
67 | view = Matrix.CreateLookAt(cameraPosition, new Vector3(0, 0, 0), Vector3.UnitY);
68 |
69 | base.Update(gameTime);
70 | }
71 | protected override void Draw(GameTime gameTime)
72 | {
73 | GraphicsDevice.Clear(Color.Black);
74 |
75 | RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState;
76 | RasterizerState rasterizerState = new RasterizerState();
77 | rasterizerState.CullMode = CullMode.None;
78 | graphics.GraphicsDevice.RasterizerState = rasterizerState;
79 |
80 | skybox.Draw(view, projection, cameraPosition);
81 |
82 | graphics.GraphicsDevice.RasterizerState = originalRasterizerState;
83 |
84 | DrawModelWithEffect(model, world, view, projection);
85 |
86 | base.Draw(gameTime);
87 | }
88 |
89 | private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
90 | {
91 | foreach (ModelMesh mesh in model.Meshes)
92 | {
93 | foreach (BasicEffect effect in mesh.Effects)
94 | {
95 | effect.EnableDefaultLighting();
96 | effect.PreferPerPixelLighting = true;
97 | effect.World = world * mesh.ParentBone.Transform;
98 | effect.View = view;
99 | effect.Projection = projection;
100 | }
101 | mesh.Draw();
102 | }
103 | }
104 |
105 | private void DrawModelWithEffect(Model model, Matrix world, Matrix view, Matrix projection)
106 | {
107 | foreach (ModelMesh mesh in model.Meshes)
108 | {
109 | foreach (ModelMeshPart part in mesh.MeshParts)
110 | {
111 | part.Effect = effect;
112 | effect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
113 | effect.Parameters["View"].SetValue(view);
114 | effect.Parameters["Projection"].SetValue(projection);
115 | effect.Parameters["ViewVector"].SetValue(viewVector);
116 | effect.Parameters["ModelTexture"].SetValue(texture);
117 | effect.Parameters["NormalMap"].SetValue(normalMap);
118 |
119 | Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * world));
120 | effect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix);
121 | }
122 | mesh.Draw();
123 | }
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/RBWithakersShaders/Specular.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 |
8 | namespace RBWithakersShaders
9 | {
10 | public class Specular : Microsoft.Xna.Framework.Game
11 | {
12 | GraphicsDeviceManager graphics;
13 | SpriteBatch spriteBatch;
14 | Effect effect;
15 |
16 | Matrix world = Matrix.CreateTranslation(0, 0, 0);
17 | Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 10), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
18 | Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 600f, 0.1f, 100f);
19 | float angle = 0;
20 | float distance = 10;
21 |
22 | Model model;
23 |
24 | Vector3 viewVector;
25 |
26 | public Specular()
27 | {
28 | graphics = new GraphicsDeviceManager(this);
29 | Content.RootDirectory = "Content";
30 | }
31 |
32 | protected override void Initialize()
33 | {
34 | base.Initialize();
35 | }
36 |
37 | protected override void LoadContent()
38 | {
39 | spriteBatch = new SpriteBatch(GraphicsDevice);
40 |
41 | model = Content.Load("Models/Helicopter");
42 | //effect = Content.Load("Effects/Ambient");
43 | //effect = Content.Load("Effects/Diffuse");
44 | effect = Content.Load("Effects/Specular");
45 | }
46 |
47 | protected override void UnloadContent()
48 | {
49 | }
50 |
51 | protected override void Update(GameTime gameTime)
52 | {
53 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
54 | Exit();
55 |
56 | angle += 0.01f;
57 | //view = Matrix.CreateLookAt(distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
58 |
59 | //specular
60 | Vector3 cameraLocation = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
61 | Vector3 cameraTarget = new Vector3(0, 0, 0);
62 | viewVector = Vector3.Transform(cameraTarget - cameraLocation, Matrix.CreateRotationY(0));
63 | viewVector.Normalize();
64 | view = Matrix.CreateLookAt(cameraLocation, cameraTarget, new Vector3(0, 1, 0));
65 |
66 | base.Update(gameTime);
67 | }
68 | protected override void Draw(GameTime gameTime)
69 | {
70 | GraphicsDevice.Clear(Color.Black);
71 |
72 | //DrawModel(model, world, view, projection);
73 |
74 | DrawModelWithEffect(model, world, view, projection);
75 | base.Draw(gameTime);
76 | }
77 |
78 | private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
79 | {
80 | foreach (ModelMesh mesh in model.Meshes)
81 | {
82 | foreach (BasicEffect effect in mesh.Effects)
83 | {
84 | effect.EnableDefaultLighting();
85 | effect.PreferPerPixelLighting = true;
86 | effect.World = world * mesh.ParentBone.Transform;
87 | effect.View = view;
88 | effect.Projection = projection;
89 | }
90 | mesh.Draw();
91 | }
92 | }
93 |
94 | private void DrawModelWithEffect(Model model, Matrix world, Matrix view, Matrix projection)
95 | {
96 | foreach (ModelMesh mesh in model.Meshes)
97 | {
98 | foreach (ModelMeshPart part in mesh.MeshParts)
99 | {
100 | part.Effect = effect;
101 | effect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
102 | effect.Parameters["View"].SetValue(view);
103 | effect.Parameters["Projection"].SetValue(projection);
104 |
105 | //effect.Parameters["AmbientColor"].SetValue(Color.Green.ToVector4());
106 | //effect.Parameters["AmbientIntensity"].SetValue(0.5f);
107 |
108 | //diffuse
109 | Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * world));
110 | effect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix);
111 |
112 | //specular
113 | effect.Parameters["ViewVector"].SetValue(viewVector);
114 | }
115 | mesh.Draw();
116 | }
117 | }
118 | }
119 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Textured.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 |
8 | namespace RBWithakersShaders
9 | {
10 | public class Textured : Microsoft.Xna.Framework.Game
11 | {
12 | GraphicsDeviceManager graphics;
13 | SpriteBatch spriteBatch;
14 | Effect effect;
15 |
16 | Matrix world = Matrix.CreateTranslation(0, 0, 0);
17 | Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 10), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
18 | Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 600f, 0.1f, 100f);
19 | float angle = 0;
20 | float distance = 10;
21 |
22 | Model model;
23 | Texture2D texture;
24 |
25 | Vector3 viewVector;
26 |
27 | public Textured()
28 | {
29 | graphics = new GraphicsDeviceManager(this);
30 | Content.RootDirectory = "Content";
31 | }
32 |
33 | protected override void Initialize()
34 | {
35 | base.Initialize();
36 | }
37 |
38 | protected override void LoadContent()
39 | {
40 | spriteBatch = new SpriteBatch(GraphicsDevice);
41 |
42 | model = Content.Load("Models/Helicopter");
43 | effect = Content.Load("Effects/Textured");
44 | texture = Content.Load("Textures/HelicopterTexture");
45 | }
46 |
47 | protected override void UnloadContent()
48 | {
49 | }
50 |
51 | protected override void Update(GameTime gameTime)
52 | {
53 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
54 | Exit();
55 |
56 | angle += 0.01f;
57 | Vector3 cameraLocation = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
58 | Vector3 cameraTarget = new Vector3(0, 0, 0);
59 | viewVector = Vector3.Transform(cameraTarget - cameraLocation, Matrix.CreateRotationY(0));
60 | viewVector.Normalize();
61 | view = Matrix.CreateLookAt(cameraLocation, cameraTarget, new Vector3(0, 1, 0));
62 |
63 | base.Update(gameTime);
64 | }
65 | protected override void Draw(GameTime gameTime)
66 | {
67 | GraphicsDevice.Clear(Color.Black);
68 |
69 | DrawModelWithEffect(model, world, view, projection);
70 | base.Draw(gameTime);
71 | }
72 |
73 |
74 | private void DrawModelWithEffect(Model model, Matrix world, Matrix view, Matrix projection)
75 | {
76 | foreach (ModelMesh mesh in model.Meshes)
77 | {
78 | foreach (ModelMeshPart part in mesh.MeshParts)
79 | {
80 | part.Effect = effect;
81 | effect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
82 | effect.Parameters["View"].SetValue(view);
83 | effect.Parameters["Projection"].SetValue(projection);
84 | effect.Parameters["ViewVector"].SetValue(viewVector);
85 | effect.Parameters["ModelTexture"].SetValue(texture);
86 |
87 | //effect.Parameters["AmbientColor"].SetValue(Color.Green.ToVector4());
88 | //effect.Parameters["AmbientIntensity"].SetValue(0.5f);
89 |
90 | Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * world));
91 | effect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix);
92 | }
93 | mesh.Draw();
94 | }
95 | }
96 | }
97 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Toon.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 |
8 | namespace RBWithakersShaders
9 | {
10 | public class Toon : Microsoft.Xna.Framework.Game
11 | {
12 | GraphicsDeviceManager graphics;
13 | SpriteBatch spriteBatch;
14 |
15 | Matrix world = Matrix.Identity;
16 | Matrix view = Matrix.CreateLookAt(new Vector3(20, 0, 0), new Vector3(0, 0, 0), Vector3.UnitY);
17 | Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 480f, 0.1f, 100f);
18 | Vector3 cameraPosition;
19 | float angle = 0;
20 | float distance = 20;
21 |
22 | private Model model;
23 | private Effect effect;
24 | private Texture2D texture;
25 |
26 | Vector3 viewVector;
27 |
28 | public Toon()
29 | {
30 | graphics = new GraphicsDeviceManager(this);
31 | Content.RootDirectory = "Content";
32 | }
33 |
34 | protected override void Initialize()
35 | {
36 | base.Initialize();
37 | }
38 |
39 | protected override void LoadContent()
40 | {
41 | spriteBatch = new SpriteBatch(GraphicsDevice);
42 |
43 | texture = Content.Load("Textures/HelicopterTexture");
44 | model = Content.Load("Models/Helicopter");
45 | effect = Content.Load("Effects/Toon");
46 | }
47 |
48 | protected override void UnloadContent()
49 | {
50 | }
51 |
52 | protected override void Update(GameTime gameTime)
53 | {
54 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
55 | this.Exit();
56 |
57 | cameraPosition = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
58 | Vector3 cameraTarget = new Vector3(0, 0, 0);
59 | viewVector = Vector3.Transform(cameraTarget - cameraPosition, Matrix.CreateRotationY(0));
60 | viewVector.Normalize();
61 |
62 | angle += 0.01f;
63 | view = Matrix.CreateLookAt(cameraPosition, new Vector3(0, 0, 0), Vector3.UnitY);
64 |
65 | base.Update(gameTime);
66 | }
67 | protected override void Draw(GameTime gameTime)
68 | {
69 | GraphicsDevice.Clear(Color.CornflowerBlue);
70 |
71 | DrawModelWithEffect(model, world, view, projection);
72 |
73 | base.Draw(gameTime);
74 | }
75 |
76 |
77 | private void DrawModelWithEffect(Model model, Matrix world, Matrix view, Matrix projection)
78 | {
79 | foreach (ModelMesh mesh in model.Meshes)
80 | {
81 | foreach (ModelMeshPart part in mesh.MeshParts)
82 | {
83 | part.Effect = effect;
84 | effect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
85 | effect.Parameters["View"].SetValue(view);
86 | effect.Parameters["Projection"].SetValue(projection);
87 | effect.Parameters["WorldInverseTranspose"].SetValue(Matrix.Transpose(Matrix.Invert(world * mesh.ParentBone.Transform)));
88 | effect.Parameters["Texture"].SetValue(texture);
89 | }
90 | mesh.Draw();
91 | }
92 | }
93 | }
94 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/Transparency.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | using Microsoft.Xna.Framework;
4 | using Microsoft.Xna.Framework.Graphics;
5 | using Microsoft.Xna.Framework.Input;
6 |
7 |
8 | namespace RBWithakersShaders
9 | {
10 | public class Transparency : Microsoft.Xna.Framework.Game
11 | {
12 | GraphicsDeviceManager graphics;
13 | SpriteBatch spriteBatch;
14 | Effect effect;
15 |
16 | Matrix world = Matrix.Identity;
17 | Matrix view = Matrix.CreateLookAt(new Vector3(20, 0, 0), new Vector3(0, 0, 0), Vector3.UnitY);
18 | Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 600f, 0.1f, 100f);
19 | float angle = 0;
20 | float distance = 10;
21 |
22 | Model model; //, modelB;
23 | Texture2D texture;
24 |
25 | Vector3 cameraPosition;
26 | Skybox skybox;
27 |
28 | //Matrix[] choppersPos;
29 |
30 | Vector3 viewVector;
31 |
32 | float transparency;
33 |
34 | public Transparency()
35 | {
36 | graphics = new GraphicsDeviceManager(this);
37 | Content.RootDirectory = "Content";
38 | }
39 |
40 | protected override void Initialize()
41 | {
42 | transparency = 0.2f;
43 |
44 | //choppersPos = new Matrix[10];
45 |
46 | //for (Byte i = 0; i < 10; i++)
47 | //{
48 | // choppersPos[i] = Matrix.CreateTranslation(10, 1 + 3 * i, -30);
49 | //}
50 |
51 | base.Initialize();
52 | }
53 |
54 | protected override void LoadContent()
55 | {
56 | spriteBatch = new SpriteBatch(GraphicsDevice);
57 |
58 | model = Content.Load("Models/Helicopter");
59 | //modelB = Content.Load("Models/UntexturedSphere");
60 | effect = Content.Load("Effects/Transparency");
61 | texture = Content.Load("Textures/HelicopterTexture");
62 |
63 | skybox = new Skybox("Skyboxes/Sunset", Content);
64 | }
65 |
66 |
67 | protected override void UnloadContent()
68 | {
69 | Content.Unload();
70 | }
71 |
72 |
73 | protected override void Update(GameTime gameTime)
74 | {
75 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
76 | Exit();
77 |
78 |
79 | cameraPosition = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
80 | Vector3 cameraTarget = new Vector3(0, 0, 0);
81 | viewVector = Vector3.Transform(cameraTarget - cameraPosition, Matrix.CreateRotationY(0));
82 | viewVector.Normalize();
83 |
84 | angle += 0.006f;
85 | view = Matrix.CreateLookAt(cameraPosition, new Vector3(0, 0, 0), Vector3.UnitY);
86 |
87 | base.Update(gameTime);
88 | }
89 |
90 |
91 | protected override void Draw(GameTime gameTime)
92 | {
93 | //GraphicsDevice.Clear(Color.LightSeaGreen);
94 | GraphicsDevice.Clear(Color.Black);
95 |
96 | //for (Byte i = 0; i < 10; i++)
97 | //{
98 | // // drawing cannot be mixed ??? DrawModel => exception
99 | // DrawModel(modelB, choppersPos[i], view, projection);
100 | //}
101 |
102 | RasterizerState originalRasterizerState = graphics.GraphicsDevice.RasterizerState;
103 | RasterizerState rasterizerState = new RasterizerState();
104 | rasterizerState.CullMode = CullMode.None;
105 | graphics.GraphicsDevice.RasterizerState = rasterizerState;
106 |
107 | skybox.Draw(view, projection, cameraPosition);
108 |
109 | graphics.GraphicsDevice.RasterizerState = originalRasterizerState;
110 |
111 | // warning: if the same model is used, even with too separated content.load calls,
112 | // the use of DrawModel don't work cause effect cannot be cast into BasicEffect type (is here any static somewhere ?)
113 | DrawModelWithEffect(model, world, view, projection);
114 |
115 | base.Draw(gameTime);
116 | }
117 |
118 |
119 | private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
120 | {
121 | foreach (ModelMesh mesh in model.Meshes)
122 | {
123 | foreach (BasicEffect effect in mesh.Effects)
124 | {
125 | effect.EnableDefaultLighting();
126 | effect.PreferPerPixelLighting = true;
127 | effect.World = world * mesh.ParentBone.Transform;
128 | effect.View = view;
129 | effect.Projection = projection;
130 | }
131 | mesh.Draw();
132 | }
133 | }
134 |
135 |
136 | private void DrawModelWithEffect(Model model, Matrix world, Matrix view, Matrix projection)
137 | {
138 | foreach (ModelMesh mesh in model.Meshes)
139 | {
140 | foreach (ModelMeshPart part in mesh.MeshParts)
141 | {
142 | part.Effect = effect;
143 | effect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
144 | effect.Parameters["View"].SetValue(view);
145 | effect.Parameters["Projection"].SetValue(projection);
146 | effect.Parameters["ViewVector"].SetValue(viewVector);
147 | effect.Parameters["ModelTexture"].SetValue(texture);
148 | effect.Parameters["Transparency"].SetValue(transparency);
149 |
150 | //effect.Parameters["AmbientColor"].SetValue(Color.Green.ToVector4());
151 | //effect.Parameters["AmbientIntensity"].SetValue(0.5f);
152 |
153 | Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * world));
154 | effect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix);
155 | }
156 | mesh.Draw();
157 | }
158 | }
159 | }
160 | }
--------------------------------------------------------------------------------
/RBWithakersShaders/cube.FBX:
--------------------------------------------------------------------------------
1 | ; FBX 7.3.0 project file
2 | ; Copyright (C) 1997-2010 Autodesk Inc. and/or its licensors.
3 | ; All rights reserved.
4 | ; ----------------------------------------------------
5 |
6 | FBXHeaderExtension: {
7 | FBXHeaderVersion: 1003
8 | FBXVersion: 7300
9 | CreationTimeStamp: {
10 | Version: 1000
11 | Year: 2016
12 | Month: 4
13 | Day: 12
14 | Hour: 11
15 | Minute: 22
16 | Second: 39
17 | Millisecond: 395
18 | }
19 | Creator: "FBX SDK/FBX Plugins version 2015.1"
20 | SceneInfo: "SceneInfo::GlobalInfo", "UserData" {
21 | Type: "UserData"
22 | Version: 100
23 | MetaData: {
24 | Version: 100
25 | Title: ""
26 | Subject: ""
27 | Author: ""
28 | Keywords: ""
29 | Revision: ""
30 | Comment: ""
31 | }
32 | Properties70: {
33 | P: "DocumentUrl", "KString", "Url", "", "K:\dev\MonoGame\ShadersConversion\RBWithakersShaders\Content\Skyboxes\cube.FBX"
34 | P: "SrcDocumentUrl", "KString", "Url", "", "K:\dev\MonoGame\ShadersConversion\RBWithakersShaders\Content\Skyboxes\cube.FBX"
35 | P: "Original", "Compound", "", ""
36 | P: "Original|ApplicationVendor", "KString", "", "", "Autodesk"
37 | P: "Original|ApplicationName", "KString", "", "", "3ds Max"
38 | P: "Original|ApplicationVersion", "KString", "", "", "2014"
39 | P: "Original|DateTime_GMT", "DateTime", "", "", "12/04/2016 09:22:39.394"
40 | P: "Original|FileName", "KString", "", "", "K:\dev\MonoGame\ShadersConversion\RBWithakersShaders\Content\Skyboxes\cube.FBX"
41 | P: "LastSaved", "Compound", "", ""
42 | P: "LastSaved|ApplicationVendor", "KString", "", "", "Autodesk"
43 | P: "LastSaved|ApplicationName", "KString", "", "", "3ds Max"
44 | P: "LastSaved|ApplicationVersion", "KString", "", "", "2014"
45 | P: "LastSaved|DateTime_GMT", "DateTime", "", "", "12/04/2016 09:22:39.394"
46 | }
47 | }
48 | }
49 | GlobalSettings: {
50 | Version: 1000
51 | Properties70: {
52 | P: "UpAxis", "int", "Integer", "",1
53 | P: "UpAxisSign", "int", "Integer", "",1
54 | P: "FrontAxis", "int", "Integer", "",2
55 | P: "FrontAxisSign", "int", "Integer", "",1
56 | P: "CoordAxis", "int", "Integer", "",0
57 | P: "CoordAxisSign", "int", "Integer", "",1
58 | P: "OriginalUpAxis", "int", "Integer", "",2
59 | P: "OriginalUpAxisSign", "int", "Integer", "",1
60 | P: "UnitScaleFactor", "double", "Number", "",1
61 | P: "OriginalUnitScaleFactor", "double", "Number", "",2.54
62 | P: "AmbientColor", "ColorRGB", "Color", "",0,0,0
63 | P: "DefaultCamera", "KString", "", "", "Producer Perspective"
64 | P: "TimeMode", "enum", "", "",6
65 | P: "TimeProtocol", "enum", "", "",2
66 | P: "SnapOnFrameMode", "enum", "", "",0
67 | P: "TimeSpanStart", "KTime", "Time", "",0
68 | P: "TimeSpanStop", "KTime", "Time", "",153953860000
69 | P: "CustomFrameRate", "double", "Number", "",-1
70 | P: "TimeMarker", "Compound", "", ""
71 | P: "CurrentTimeMarker", "int", "Integer", "",-1
72 | }
73 | }
74 |
75 | ; Documents Description
76 | ;------------------------------------------------------------------
77 |
78 | Documents: {
79 | Count: 1
80 | Document: 1277068448, "", "Scene" {
81 | Properties70: {
82 | P: "SourceObject", "object", "", ""
83 | P: "ActiveAnimStackName", "KString", "", "", ""
84 | }
85 | RootNode: 0
86 | }
87 | }
88 |
89 | ; Document References
90 | ;------------------------------------------------------------------
91 |
92 | References: {
93 | }
94 |
95 | ; Object definitions
96 | ;------------------------------------------------------------------
97 |
98 | Definitions: {
99 | Version: 100
100 | Count: 6
101 | ObjectType: "GlobalSettings" {
102 | Count: 1
103 | }
104 | ObjectType: "AnimationStack" {
105 | Count: 1
106 | PropertyTemplate: "FbxAnimStack" {
107 | Properties70: {
108 | P: "Description", "KString", "", "", ""
109 | P: "LocalStart", "KTime", "Time", "",0
110 | P: "LocalStop", "KTime", "Time", "",0
111 | P: "ReferenceStart", "KTime", "Time", "",0
112 | P: "ReferenceStop", "KTime", "Time", "",0
113 | }
114 | }
115 | }
116 | ObjectType: "AnimationLayer" {
117 | Count: 1
118 | PropertyTemplate: "FbxAnimLayer" {
119 | Properties70: {
120 | P: "Weight", "Number", "", "A",100
121 | P: "Mute", "bool", "", "",0
122 | P: "Solo", "bool", "", "",0
123 | P: "Lock", "bool", "", "",0
124 | P: "Color", "ColorRGB", "Color", "",0.8,0.8,0.8
125 | P: "BlendMode", "enum", "", "",0
126 | P: "RotationAccumulationMode", "enum", "", "",0
127 | P: "ScaleAccumulationMode", "enum", "", "",0
128 | P: "BlendModeBypass", "ULongLong", "", "",0
129 | }
130 | }
131 | }
132 | ObjectType: "Model" {
133 | Count: 1
134 | PropertyTemplate: "FbxNode" {
135 | Properties70: {
136 | P: "QuaternionInterpolate", "enum", "", "",0
137 | P: "RotationOffset", "Vector3D", "Vector", "",0,0,0
138 | P: "RotationPivot", "Vector3D", "Vector", "",0,0,0
139 | P: "ScalingOffset", "Vector3D", "Vector", "",0,0,0
140 | P: "ScalingPivot", "Vector3D", "Vector", "",0,0,0
141 | P: "TranslationActive", "bool", "", "",0
142 | P: "TranslationMin", "Vector3D", "Vector", "",0,0,0
143 | P: "TranslationMax", "Vector3D", "Vector", "",0,0,0
144 | P: "TranslationMinX", "bool", "", "",0
145 | P: "TranslationMinY", "bool", "", "",0
146 | P: "TranslationMinZ", "bool", "", "",0
147 | P: "TranslationMaxX", "bool", "", "",0
148 | P: "TranslationMaxY", "bool", "", "",0
149 | P: "TranslationMaxZ", "bool", "", "",0
150 | P: "RotationOrder", "enum", "", "",0
151 | P: "RotationSpaceForLimitOnly", "bool", "", "",0
152 | P: "RotationStiffnessX", "double", "Number", "",0
153 | P: "RotationStiffnessY", "double", "Number", "",0
154 | P: "RotationStiffnessZ", "double", "Number", "",0
155 | P: "AxisLen", "double", "Number", "",10
156 | P: "PreRotation", "Vector3D", "Vector", "",0,0,0
157 | P: "PostRotation", "Vector3D", "Vector", "",0,0,0
158 | P: "RotationActive", "bool", "", "",0
159 | P: "RotationMin", "Vector3D", "Vector", "",0,0,0
160 | P: "RotationMax", "Vector3D", "Vector", "",0,0,0
161 | P: "RotationMinX", "bool", "", "",0
162 | P: "RotationMinY", "bool", "", "",0
163 | P: "RotationMinZ", "bool", "", "",0
164 | P: "RotationMaxX", "bool", "", "",0
165 | P: "RotationMaxY", "bool", "", "",0
166 | P: "RotationMaxZ", "bool", "", "",0
167 | P: "InheritType", "enum", "", "",0
168 | P: "ScalingActive", "bool", "", "",0
169 | P: "ScalingMin", "Vector3D", "Vector", "",0,0,0
170 | P: "ScalingMax", "Vector3D", "Vector", "",1,1,1
171 | P: "ScalingMinX", "bool", "", "",0
172 | P: "ScalingMinY", "bool", "", "",0
173 | P: "ScalingMinZ", "bool", "", "",0
174 | P: "ScalingMaxX", "bool", "", "",0
175 | P: "ScalingMaxY", "bool", "", "",0
176 | P: "ScalingMaxZ", "bool", "", "",0
177 | P: "GeometricTranslation", "Vector3D", "Vector", "",0,0,0
178 | P: "GeometricRotation", "Vector3D", "Vector", "",0,0,0
179 | P: "GeometricScaling", "Vector3D", "Vector", "",1,1,1
180 | P: "MinDampRangeX", "double", "Number", "",0
181 | P: "MinDampRangeY", "double", "Number", "",0
182 | P: "MinDampRangeZ", "double", "Number", "",0
183 | P: "MaxDampRangeX", "double", "Number", "",0
184 | P: "MaxDampRangeY", "double", "Number", "",0
185 | P: "MaxDampRangeZ", "double", "Number", "",0
186 | P: "MinDampStrengthX", "double", "Number", "",0
187 | P: "MinDampStrengthY", "double", "Number", "",0
188 | P: "MinDampStrengthZ", "double", "Number", "",0
189 | P: "MaxDampStrengthX", "double", "Number", "",0
190 | P: "MaxDampStrengthY", "double", "Number", "",0
191 | P: "MaxDampStrengthZ", "double", "Number", "",0
192 | P: "PreferedAngleX", "double", "Number", "",0
193 | P: "PreferedAngleY", "double", "Number", "",0
194 | P: "PreferedAngleZ", "double", "Number", "",0
195 | P: "LookAtProperty", "object", "", ""
196 | P: "UpVectorProperty", "object", "", ""
197 | P: "Show", "bool", "", "",1
198 | P: "NegativePercentShapeSupport", "bool", "", "",1
199 | P: "DefaultAttributeIndex", "int", "Integer", "",-1
200 | P: "Freeze", "bool", "", "",0
201 | P: "LODBox", "bool", "", "",0
202 | P: "Lcl Translation", "Lcl Translation", "", "A",0,0,0
203 | P: "Lcl Rotation", "Lcl Rotation", "", "A",0,0,0
204 | P: "Lcl Scaling", "Lcl Scaling", "", "A",1,1,1
205 | P: "Visibility", "Visibility", "", "A",1
206 | P: "Visibility Inheritance", "Visibility Inheritance", "", "",1
207 | }
208 | }
209 | }
210 | ObjectType: "Material" {
211 | Count: 1
212 | PropertyTemplate: "FbxSurfacePhong" {
213 | Properties70: {
214 | P: "ShadingModel", "KString", "", "", "Phong"
215 | P: "MultiLayer", "bool", "", "",0
216 | P: "EmissiveColor", "Color", "", "A",0,0,0
217 | P: "EmissiveFactor", "Number", "", "A",1
218 | P: "AmbientColor", "Color", "", "A",0.2,0.2,0.2
219 | P: "AmbientFactor", "Number", "", "A",1
220 | P: "DiffuseColor", "Color", "", "A",0.8,0.8,0.8
221 | P: "DiffuseFactor", "Number", "", "A",1
222 | P: "Bump", "Vector3D", "Vector", "",0,0,0
223 | P: "NormalMap", "Vector3D", "Vector", "",0,0,0
224 | P: "BumpFactor", "double", "Number", "",1
225 | P: "TransparentColor", "Color", "", "A",0,0,0
226 | P: "TransparencyFactor", "Number", "", "A",0
227 | P: "DisplacementColor", "ColorRGB", "Color", "",0,0,0
228 | P: "DisplacementFactor", "double", "Number", "",1
229 | P: "VectorDisplacementColor", "ColorRGB", "Color", "",0,0,0
230 | P: "VectorDisplacementFactor", "double", "Number", "",1
231 | P: "SpecularColor", "Color", "", "A",0.2,0.2,0.2
232 | P: "SpecularFactor", "Number", "", "A",1
233 | P: "ShininessExponent", "Number", "", "A",20
234 | P: "ReflectionColor", "Color", "", "A",0,0,0
235 | P: "ReflectionFactor", "Number", "", "A",1
236 | }
237 | }
238 | }
239 | ObjectType: "Geometry" {
240 | Count: 1
241 | PropertyTemplate: "FbxMesh" {
242 | Properties70: {
243 | P: "Color", "ColorRGB", "Color", "",0.8,0.8,0.8
244 | P: "BBoxMin", "Vector3D", "Vector", "",0,0,0
245 | P: "BBoxMax", "Vector3D", "Vector", "",0,0,0
246 | P: "Primary Visibility", "bool", "", "",1
247 | P: "Casts Shadows", "bool", "", "",1
248 | P: "Receive Shadows", "bool", "", "",1
249 | }
250 | }
251 | }
252 | }
253 |
254 | ; Object properties
255 | ;------------------------------------------------------------------
256 |
257 | Objects: {
258 | Geometry: 1923091072, "Geometry::", "Mesh" {
259 | Vertices: *24 {
260 | a: -1,-1,1,-1,1,1,1,1,1,1,-1,1,-1,-1,-1,-1,1,-1,1,1,-1,1,-1,-1
261 | }
262 | PolygonVertexIndex: *36 {
263 | a: 2,1,-1,2,0,-4,2,3,-7,3,7,-7,3,0,-8,0,4,-8,1,2,-6,2,6,-6,7,4,-6,7,5,-7,0,1,-5,1,5,-5
264 | }
265 | Edges: *18 {
266 | a: 0,1,2,4,5,7,8,9,10,13,15,16,19,20,22,25,26,31
267 | }
268 | GeometryVersion: 124
269 | LayerElementNormal: 0 {
270 | Version: 101
271 | Name: ""
272 | MappingInformationType: "ByPolygonVertex"
273 | ReferenceInformationType: "Direct"
274 | Normals: *108 {
275 | a: 0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,0.577350318431854,0.577350318431854,-0.577350318431854,0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854,-0.577350318431854
276 | }
277 | }
278 | LayerElementSmoothing: 0 {
279 | Version: 102
280 | Name: ""
281 | MappingInformationType: "ByPolygon"
282 | ReferenceInformationType: "Direct"
283 | Smoothing: *12 {
284 | a: 1,1,1,1,1,1,1,1,1,1,1,1
285 | }
286 | }
287 | LayerElementMaterial: 0 {
288 | Version: 101
289 | Name: ""
290 | MappingInformationType: "AllSame"
291 | ReferenceInformationType: "IndexToDirect"
292 | Materials: *1 {
293 | a: 0
294 | }
295 | }
296 | Layer: 0 {
297 | Version: 100
298 | LayerElement: {
299 | Type: "LayerElementNormal"
300 | TypedIndex: 0
301 | }
302 | LayerElement: {
303 | Type: "LayerElementMaterial"
304 | TypedIndex: 0
305 | }
306 | LayerElement: {
307 | Type: "LayerElementSmoothing"
308 | TypedIndex: 0
309 | }
310 | }
311 | }
312 | Model: 1922364208, "Model::cube1", "Mesh" {
313 | Version: 232
314 | Properties70: {
315 | P: "PreRotation", "Vector3D", "Vector", "",-90,-0,0
316 | P: "RotationActive", "bool", "", "",1
317 | P: "InheritType", "enum", "", "",1
318 | P: "ScalingMax", "Vector3D", "Vector", "",0,0,0
319 | P: "DefaultAttributeIndex", "int", "Integer", "",0
320 | P: "Lcl Rotation", "Lcl Rotation", "", "A",90.0000025044782,-0,0
321 | P: "Lcl Scaling", "Lcl Scaling", "", "A",0.999999977350235,0.999999977350235,0.999999977350235
322 | P: "MaxHandle", "int", "Integer", "UH",2
323 | }
324 | Shading: T
325 | Culling: "CullingOff"
326 | }
327 | Material: 1276274944, "Material::default", "" {
328 | Version: 102
329 | ShadingModel: "phong"
330 | MultiLayer: 0
331 | Properties70: {
332 | P: "ShadingModel", "KString", "", "", "phong"
333 | P: "EmissiveFactor", "Number", "", "A",0
334 | P: "AmbientColor", "Color", "", "A",1,1,1
335 | P: "DiffuseColor", "Color", "", "A",1,1,1
336 | P: "TransparentColor", "Color", "", "A",1,1,1
337 | P: "SpecularColor", "Color", "", "A",1,1,1
338 | P: "ShininessExponent", "Number", "", "A",128
339 | P: "Emissive", "Vector3D", "Vector", "",0,0,0
340 | P: "Ambient", "Vector3D", "Vector", "",1,1,1
341 | P: "Diffuse", "Vector3D", "Vector", "",1,1,1
342 | P: "Specular", "Vector3D", "Vector", "",1,1,1
343 | P: "Shininess", "double", "Number", "",128
344 | P: "Opacity", "double", "Number", "",1
345 | P: "Reflectivity", "double", "Number", "",0
346 | }
347 | }
348 | }
349 |
350 | ; Object connections
351 | ;------------------------------------------------------------------
352 |
353 | Connections: {
354 |
355 | ;Model::cube1, Model::RootNode
356 | C: "OO",1922364208,0
357 |
358 | ;AnimLayer::BaseLayer, AnimStack::Take 001
359 | C: "OO",1217557904,1283358384
360 |
361 | ;Material::default, Model::cube1
362 | C: "OO",1276274944,1922364208
363 |
364 | ;Geometry::, Model::cube1
365 | C: "OO",1923091072,1922364208
366 | }
367 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MonoGameShaders
2 | MonoGame conversion/port of various XNA shaders tutorials
3 |
4 | Plan:
5 | -RB Whitaker tutorials (WIP 7/10)
6 | -digitalerr0r tutorials
7 | -a few from Riemers
8 | -another few from MS XBox creator club
9 | -other sources (catalinzima, dhpoware, ...)
10 |
--------------------------------------------------------------------------------
/RiemersHLSLTuTorial.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25123.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RiemersHLSLTutorial", "RiemersHLSLTutorial\RiemersHLSLTutorial.csproj", "{51D542E1-2364-4B96-BF1A-889A0F651C14}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x86 = Debug|x86
11 | Release|x86 = Release|x86
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {51D542E1-2364-4B96-BF1A-889A0F651C14}.Debug|x86.ActiveCfg = Debug|x86
15 | {51D542E1-2364-4B96-BF1A-889A0F651C14}.Debug|x86.Build.0 = Debug|x86
16 | {51D542E1-2364-4B96-BF1A-889A0F651C14}.Release|x86.ActiveCfg = Release|x86
17 | {51D542E1-2364-4B96-BF1A-889A0F651C14}.Release|x86.Build.0 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Content/Content.mgcb:
--------------------------------------------------------------------------------
1 |
2 | #----------------------------- Global Properties ----------------------------#
3 |
4 | /outputDir:bin/$(Platform)
5 | /intermediateDir:obj/$(Platform)
6 | /platform:Windows
7 | /config:
8 | /profile:Reach
9 | /compress:False
10 |
11 | #-------------------------------- References --------------------------------#
12 |
13 |
14 | #---------------------------------- Content ---------------------------------#
15 |
16 | #begin lamppost.x
17 | /importer:XImporter
18 | /processor:ModelProcessor
19 | /processorParam:ColorKeyColor=0,0,0,0
20 | /processorParam:ColorKeyEnabled=True
21 | /processorParam:DefaultEffect=BasicEffect
22 | /processorParam:GenerateMipmaps=True
23 | /processorParam:GenerateTangentFrames=False
24 | /processorParam:PremultiplyTextureAlpha=True
25 | /processorParam:PremultiplyVertexColors=True
26 | /processorParam:ResizeTexturesToPowerOfTwo=False
27 | /processorParam:RotationX=0
28 | /processorParam:RotationY=0
29 | /processorParam:RotationZ=0
30 | /processorParam:Scale=1
31 | /processorParam:SwapWindingOrder=False
32 | /processorParam:TextureFormat=DxtCompressed
33 | /build:lamppost.x
34 |
35 | #begin car.x
36 | /importer:XImporter
37 | /processor:ModelProcessor
38 | /processorParam:ColorKeyColor=0,0,0,0
39 | /processorParam:ColorKeyEnabled=True
40 | /processorParam:DefaultEffect=BasicEffect
41 | /processorParam:GenerateMipmaps=True
42 | /processorParam:GenerateTangentFrames=False
43 | /processorParam:PremultiplyTextureAlpha=True
44 | /processorParam:PremultiplyVertexColors=True
45 | /processorParam:ResizeTexturesToPowerOfTwo=False
46 | /processorParam:RotationX=0
47 | /processorParam:RotationY=0
48 | /processorParam:RotationZ=0
49 | /processorParam:Scale=1
50 | /processorParam:SwapWindingOrder=False
51 | /processorParam:TextureFormat=DxtCompressed
52 | /build:car.x
53 |
54 | #begin chasis.jpg
55 | /importer:TextureImporter
56 | /processor:TextureProcessor
57 | /processorParam:ColorKeyColor=255,0,255,255
58 | /processorParam:ColorKeyEnabled=True
59 | /processorParam:GenerateMipmaps=False
60 | /processorParam:PremultiplyAlpha=True
61 | /processorParam:ResizeToPowerOfTwo=False
62 | /processorParam:MakeSquare=False
63 | /processorParam:TextureFormat=Color
64 | /build:chasis.jpg
65 |
66 | #begin chasis_a.jpg
67 | /importer:TextureImporter
68 | /processor:TextureProcessor
69 | /processorParam:ColorKeyColor=255,0,255,255
70 | /processorParam:ColorKeyEnabled=True
71 | /processorParam:GenerateMipmaps=False
72 | /processorParam:PremultiplyAlpha=True
73 | /processorParam:ResizeToPowerOfTwo=False
74 | /processorParam:MakeSquare=False
75 | /processorParam:TextureFormat=Color
76 | /build:chasis_a.jpg
77 |
78 | #begin ruedas.jpg
79 | /importer:TextureImporter
80 | /processor:TextureProcessor
81 | /processorParam:ColorKeyColor=255,0,255,255
82 | /processorParam:ColorKeyEnabled=True
83 | /processorParam:GenerateMipmaps=False
84 | /processorParam:PremultiplyAlpha=True
85 | /processorParam:ResizeToPowerOfTwo=False
86 | /processorParam:MakeSquare=False
87 | /processorParam:TextureFormat=Color
88 | /build:ruedas.jpg
89 |
90 | #begin ventanas.jpg
91 | /importer:TextureImporter
92 | /processor:TextureProcessor
93 | /processorParam:ColorKeyColor=255,0,255,255
94 | /processorParam:ColorKeyEnabled=True
95 | /processorParam:GenerateMipmaps=False
96 | /processorParam:PremultiplyAlpha=True
97 | /processorParam:ResizeToPowerOfTwo=False
98 | /processorParam:MakeSquare=False
99 | /processorParam:TextureFormat=Color
100 | /build:ventanas.jpg
101 |
102 | #begin streettexture.jpg
103 | /importer:TextureImporter
104 | /processor:TextureProcessor
105 | /processorParam:ColorKeyColor=255,0,255,255
106 | /processorParam:ColorKeyEnabled=True
107 | /processorParam:GenerateMipmaps=False
108 | /processorParam:PremultiplyAlpha=True
109 | /processorParam:ResizeToPowerOfTwo=False
110 | /processorParam:MakeSquare=False
111 | /processorParam:TextureFormat=Color
112 | /build:streettexture.jpg
113 |
114 | #begin Effect4.fx
115 | /importer:EffectImporter
116 | /processor:EffectProcessor
117 | /processorParam:DebugMode=Auto
118 | /build:Effect4.fx
119 |
120 |
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Content/Effect4.fx:
--------------------------------------------------------------------------------
1 | struct VertexToPixel
2 | {
3 | float4 Position : POSITION;
4 | float2 TexCoords : TEXCOORD0;
5 | float3 Normal : TEXCOORD1;
6 | float3 Position3D : TEXCOORD2;
7 | };
8 |
9 | struct PixelToFrame
10 | {
11 | float4 Color : COLOR0;
12 | };
13 |
14 | struct SMapVertexToPixel
15 | {
16 | float4 Position : POSITION;
17 | float4 Position2D : TEXCOORD0;
18 | };
19 |
20 | struct SMapPixelToFrame
21 | {
22 | float4 Color : COLOR0;
23 | };
24 |
25 |
26 | struct SSceneVertexToPixel
27 | {
28 | float4 Position : POSITION;
29 | float4 Pos2DAsSeenByLight : TEXCOORD0;
30 | float2 TexCoords : TEXCOORD1;
31 | float3 Normal : TEXCOORD2;
32 | float4 Position3D : TEXCOORD3;
33 | };
34 |
35 | struct SScenePixelToFrame
36 | {
37 | float4 Color : COLOR0;
38 | };
39 |
40 | float3 xLightPos;
41 | float xLightPower;
42 | float xAmbient;
43 |
44 | float4x4 xWorld;
45 | float4x4 xWorldViewProjection;
46 | Texture xTexture;
47 |
48 | float4x4 xLightsWorldViewProjection;
49 |
50 | sampler TextureSampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};
51 |
52 | Texture xShadowMap;
53 |
54 | sampler ShadowMapSampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = clamp; AddressV = clamp;};
55 |
56 |
57 | VertexToPixel SimplestVertexShader( float4 inPos : POSITION0, float3 inNormal: NORMAL0, float2 inTexCoords : TEXCOORD0)
58 | {
59 | VertexToPixel Output = (VertexToPixel)0;
60 |
61 | Output.Position = mul(inPos, xWorldViewProjection);
62 | Output.TexCoords = inTexCoords;
63 | Output.Normal = normalize(mul(inNormal, (float3x3)xWorld));
64 | Output.Position3D = mul(inPos, xWorld);
65 |
66 | return Output;
67 | }
68 |
69 | float DotProduct(float3 lightPos, float3 pos3D, float3 normal)
70 | {
71 | float3 lightDir = normalize(pos3D - lightPos);
72 | return dot(-lightDir, normal);
73 | }
74 |
75 | PixelToFrame OurFirstPixelShader(VertexToPixel PSIn)
76 | {
77 | PSIn.TexCoords.y--;
78 | PixelToFrame Output = (PixelToFrame)0;
79 |
80 | float diffuseLightingFactor = DotProduct(xLightPos, PSIn.Position3D, PSIn.Normal);
81 | diffuseLightingFactor = saturate(diffuseLightingFactor);
82 | diffuseLightingFactor *= xLightPower;
83 |
84 | //Output.Color = diffuseLightingFactor; //tex2D(TextureSampler, PSIn.TexCoords);
85 |
86 | float4 baseColor = tex2D(TextureSampler, PSIn.TexCoords);
87 | Output.Color = baseColor*(diffuseLightingFactor + xAmbient);
88 |
89 |
90 | return Output;
91 | }
92 |
93 |
94 |
95 | technique SimplestTex
96 | {
97 | pass Pass0
98 | {
99 | VertexShader = compile vs_4_0_level_9_3 SimplestVertexShader();
100 | PixelShader = compile ps_4_0_level_9_3 OurFirstPixelShader();
101 | }
102 | }
103 |
104 |
105 | SMapVertexToPixel ShadowMapVertexShader( float4 inPos : POSITION)
106 | {
107 | SMapVertexToPixel Output = (SMapVertexToPixel)0;
108 |
109 | Output.Position = mul(inPos, xLightsWorldViewProjection);
110 | Output.Position2D = Output.Position;
111 |
112 | return Output;
113 | }
114 |
115 |
116 | SMapPixelToFrame ShadowMapPixelShader(SMapVertexToPixel PSIn)
117 | {
118 | SMapPixelToFrame Output = (SMapPixelToFrame)0;
119 |
120 | Output.Color = PSIn.Position2D.z/PSIn.Position2D.w;
121 |
122 | return Output;
123 | }
124 |
125 | technique ShadowMap
126 | {
127 | pass Pass0
128 | {
129 | VertexShader = compile vs_4_0_level_9_3 ShadowMapVertexShader();
130 | PixelShader = compile ps_4_0_level_9_3 ShadowMapPixelShader();
131 | }
132 | }
133 |
134 |
135 | SSceneVertexToPixel ShadowedSceneVertexShader( float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0, float3 inNormal : NORMAL)
136 | {
137 | SSceneVertexToPixel Output = (SSceneVertexToPixel)0;
138 |
139 | Output.Position = mul(inPos, xWorldViewProjection);
140 | Output.Pos2DAsSeenByLight = mul(inPos, xLightsWorldViewProjection);
141 | Output.Normal = normalize(mul(inNormal, (float3x3)xWorld));
142 | Output.Position3D = mul(inPos, xWorld);
143 | Output.TexCoords = inTexCoords;
144 |
145 | return Output;
146 | }
147 |
148 |
149 | SScenePixelToFrame ShadowedScenePixelShader(SSceneVertexToPixel PSIn)
150 | {
151 | SScenePixelToFrame Output = (SScenePixelToFrame)0;
152 |
153 | float2 ProjectedTexCoords;
154 | ProjectedTexCoords[0] = PSIn.Pos2DAsSeenByLight.x/PSIn.Pos2DAsSeenByLight.w/2.0f +0.5f;
155 | ProjectedTexCoords[1] = -PSIn.Pos2DAsSeenByLight.y/PSIn.Pos2DAsSeenByLight.w/2.0f +0.5f;
156 |
157 | float diffuseLightingFactor = 0;
158 | if ((saturate(ProjectedTexCoords).x == ProjectedTexCoords.x) && (saturate(ProjectedTexCoords).y == ProjectedTexCoords.y))
159 | {
160 | float depthStoredInShadowMap = tex2D(ShadowMapSampler, ProjectedTexCoords).r;
161 | float realDistance = PSIn.Pos2DAsSeenByLight.z/PSIn.Pos2DAsSeenByLight.w;
162 | if ((realDistance - 1.0f/100.0f) <= depthStoredInShadowMap)
163 | {
164 | diffuseLightingFactor = DotProduct(xLightPos, PSIn.Position3D, PSIn.Normal);
165 | diffuseLightingFactor = saturate(diffuseLightingFactor);
166 | diffuseLightingFactor *= xLightPower;
167 | }
168 | }
169 |
170 | float4 baseColor = tex2D(TextureSampler, PSIn.TexCoords);
171 | Output.Color = baseColor*(diffuseLightingFactor + xAmbient);
172 |
173 | return Output;
174 | }
175 |
176 | technique ShadowedScene
177 | {
178 | pass Pass0
179 | {
180 | VertexShader = compile vs_4_0_level_9_3 ShadowedSceneVertexShader();
181 | PixelShader = compile ps_4_0_level_9_3 ShadowedScenePixelShader();
182 | }
183 | }
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Content/car.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RiemersHLSLTutorial/Content/car.x
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Content/chasis.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RiemersHLSLTutorial/Content/chasis.jpg
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Content/chasis_a.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RiemersHLSLTutorial/Content/chasis_a.jpg
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Content/lamppost.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RiemersHLSLTutorial/Content/lamppost.x
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Content/ruedas.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RiemersHLSLTutorial/Content/ruedas.jpg
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Content/streettexture.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RiemersHLSLTutorial/Content/streettexture.jpg
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Content/ventanas.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RiemersHLSLTutorial/Content/ventanas.jpg
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/RiemersHLSLTutorial/Icon.ico
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace XNAseries3
4 | {
5 | #if WINDOWS || XBOX
6 | static class Program
7 | {
8 | static void Main(string[] args)
9 | {
10 | using (var game = new Game1())
11 | {
12 | game.Run();
13 | }
14 | }
15 | }
16 | #endif
17 | }
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("RiemersHLSLTutorial")]
9 | [assembly: AssemblyProduct("RiemersHLSLTutorial")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("875b50f6-845e-44ed-9d31-8e97a8df4499")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/RiemersHLSLTutorial.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | x86
7 | 8.0.30703
8 | 2.0
9 | {51D542E1-2364-4B96-BF1A-889A0F651C14}
10 | WinExe
11 | Properties
12 | RiemersHLSLTutorial
13 | RiemersHLSLTutorial
14 | 512
15 | Windows
16 | v4.5
17 |
18 |
19 | x86
20 | true
21 | full
22 | false
23 | bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\
24 | DEBUG;TRACE;WINDOWS
25 | prompt
26 | 4
27 |
28 |
29 | x86
30 | pdbonly
31 | true
32 | bin\$(MonoGamePlatform)\$(Platform)\$(Configuration)\
33 | TRACE;WINDOWS
34 | prompt
35 | 4
36 |
37 |
38 | Icon.ico
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | False
48 | H:\MonoGame-dev\Windows\AnyCPU\Debug\MonoGame.Framework.dll
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
67 |
--------------------------------------------------------------------------------
/RiemersHLSLTutorial/game1.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Graphics;
3 | using Microsoft.Xna.Framework.Input;
4 |
5 |
6 | namespace XNAseries3
7 | {
8 | public struct MyOwnVertexFormatT
9 | {
10 | private Vector3 position;
11 | private Vector2 texCoord;
12 | private Vector3 normal;
13 |
14 | public MyOwnVertexFormatT(Vector3 position, Vector2 texCoord, Vector3 normal)
15 | {
16 | this.position = position;
17 | this.texCoord = texCoord;
18 | this.normal = normal;
19 | }
20 |
21 | public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration
22 | (
23 | new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
24 | new VertexElement(sizeof(float) * 3, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
25 | new VertexElement(sizeof(float) * (3 + 2), VertexElementFormat.Vector3, VertexElementUsage.Normal, 0)
26 | );
27 | }
28 |
29 |
30 | public class Game1 : Microsoft.Xna.Framework.Game
31 | {
32 | GraphicsDeviceManager graphics;
33 | GraphicsDevice device;
34 |
35 | public KeyboardState KeyboardInput;
36 | public KeyboardState PreviousKeyboardInput;
37 |
38 | Effect effect;
39 | Matrix viewMatrix;
40 | Matrix projectionMatrix;
41 | VertexBuffer vertexBuffer;
42 | Vector3 cameraPos;
43 | Texture2D streetTexture;
44 | Model carModel;
45 | Model lamppost;
46 | Texture2D[] carTextures;
47 | Texture2D[] lampTextures;
48 |
49 | Vector3 lightPos;
50 | float lightPower;
51 | float ambientPower;
52 |
53 |
54 | Matrix lightsViewProjectionMatrix;
55 | RenderTarget2D renderTarget;
56 | Texture2D shadowMap;
57 |
58 | private SpriteBatch spriteBatch;
59 |
60 | public Game1()
61 | {
62 | graphics = new GraphicsDeviceManager(this);
63 | Content.RootDirectory = "Content";
64 | }
65 |
66 | protected override void Initialize()
67 | {
68 | graphics.PreferredBackBufferWidth = 1024;
69 | graphics.PreferredBackBufferHeight = 768;
70 | graphics.IsFullScreen = false;
71 | graphics.ApplyChanges();
72 | Window.Title = "Riemer's XNA Tutorials -- Series 3";
73 |
74 | lightPos = new Vector3(-18, 5, -2);
75 | ambientPower = 0.2f;
76 | lightPower = 1.0f;
77 |
78 | base.Initialize();
79 | }
80 |
81 | protected override void LoadContent()
82 | {
83 | device = GraphicsDevice;
84 |
85 | spriteBatch = new SpriteBatch(GraphicsDevice);
86 |
87 | PresentationParameters pp = device.PresentationParameters;
88 | //renderTarget = new RenderTarget2D(device, pp.BackBufferWidth, pp.BackBufferHeight, true, device.DisplayMode.Format, DepthFormat.Depth24);
89 | renderTarget = new RenderTarget2D(device, pp.BackBufferWidth, pp.BackBufferHeight, false, SurfaceFormat.Color, DepthFormat.Depth24);
90 |
91 | //effect = Content.Load("effects");
92 | effect = Content.Load("Effect4");
93 | streetTexture = Content.Load("streettexture");
94 | carModel = LoadModel("car", out carTextures);
95 | lamppost = LoadModel("lamppost", out lampTextures);
96 | //lamppost = Content.Load("lamppost");
97 | SetUpVertices();
98 | SetUpCamera();
99 | }
100 |
101 |
102 | private void SetUpVertices()
103 | {
104 | MyOwnVertexFormatT[] vertices = new MyOwnVertexFormatT[18];
105 |
106 | vertices[0] = new MyOwnVertexFormatT(new Vector3(-20, 0, 10), new Vector2(-0.25f, 25.0f), new Vector3(0, 1, 0));
107 | vertices[1] = new MyOwnVertexFormatT(new Vector3(-20, 0, -100), new Vector2(-0.25f, 0.0f), new Vector3(0, 1, 0));
108 | vertices[2] = new MyOwnVertexFormatT(new Vector3(2, 0, 10), new Vector2(0.25f, 25.0f), new Vector3(0, 1, 0));
109 | vertices[3] = new MyOwnVertexFormatT(new Vector3(2, 0, -100), new Vector2(0.25f, 0.0f), new Vector3(0, 1, 0));
110 | vertices[4] = new MyOwnVertexFormatT(new Vector3(2, 0, 10), new Vector2(0.25f, 25.0f), new Vector3(-1, 0, 0));
111 | vertices[5] = new MyOwnVertexFormatT(new Vector3(2, 0, -100), new Vector2(0.25f, 0.0f), new Vector3(-1, 0, 0));
112 | vertices[6] = new MyOwnVertexFormatT(new Vector3(2, 1, 10), new Vector2(0.375f, 25.0f), new Vector3(-1, 0, 0));
113 | vertices[7] = new MyOwnVertexFormatT(new Vector3(2, 1, -100), new Vector2(0.375f, 0.0f), new Vector3(-1, 0, 0));
114 | vertices[8] = new MyOwnVertexFormatT(new Vector3(2, 1, 10), new Vector2(0.375f, 25.0f), new Vector3(0, 1, 0));
115 | vertices[9] = new MyOwnVertexFormatT(new Vector3(2, 1, -100), new Vector2(0.375f, 0.0f), new Vector3(0, 1, 0));
116 | vertices[10] = new MyOwnVertexFormatT(new Vector3(3, 1, 10), new Vector2(0.5f, 25.0f), new Vector3(0, 1, 0));
117 | vertices[11] = new MyOwnVertexFormatT(new Vector3(3, 1, -100), new Vector2(0.5f, 0.0f), new Vector3(0, 1, 0));
118 | vertices[12] = new MyOwnVertexFormatT(new Vector3(13, 1, 10), new Vector2(0.75f, 25.0f), new Vector3(0, 1, 0));
119 | vertices[13] = new MyOwnVertexFormatT(new Vector3(13, 1, -100), new Vector2(0.75f, 0.0f), new Vector3(0, 1, 0));
120 | vertices[14] = new MyOwnVertexFormatT(new Vector3(13, 1, 10), new Vector2(0.75f, 25.0f), new Vector3(-1, 0, 0));
121 | vertices[15] = new MyOwnVertexFormatT(new Vector3(13, 1, -100), new Vector2(0.75f, 0.0f), new Vector3(-1, 0, 0));
122 | vertices[16] = new MyOwnVertexFormatT(new Vector3(13, 21, 10), new Vector2(1.25f, 25.0f), new Vector3(-1, 0, 0));
123 | vertices[17] = new MyOwnVertexFormatT(new Vector3(13, 21, -100), new Vector2(1.25f, 0.0f), new Vector3(-1, 0, 0));
124 |
125 | vertexBuffer = new VertexBuffer(device, MyOwnVertexFormatT.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
126 | vertexBuffer.SetData(vertices);
127 | }
128 |
129 |
130 | private void SetUpCamera()
131 | {
132 | cameraPos = new Vector3(-25, 13, 18);
133 | viewMatrix = Matrix.CreateLookAt(cameraPos, new Vector3(0, 2, -12), new Vector3(0, 1, 0));
134 | projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 1.0f, 200.0f);
135 | }
136 |
137 | protected override void UnloadContent()
138 | {
139 | }
140 |
141 | protected override void Update(GameTime gameTime)
142 | {
143 | PreviousKeyboardInput = KeyboardInput;
144 | KeyboardInput = Keyboard.GetState();
145 |
146 | if (KeyboardInput.IsKeyDown(Keys.Escape))
147 | {
148 | Exit();
149 | }
150 |
151 | if (KeyboardInput.IsKeyDown(Keys.NumPad0))
152 | {
153 | lightPos.X += 0.5f;
154 | }
155 | if (KeyboardInput.IsKeyDown(Keys.NumPad8))
156 | {
157 | lightPos.X -= 0.5f;
158 | }
159 | if (KeyboardInput.IsKeyDown(Keys.NumPad4))
160 | {
161 | lightPos.Z += 0.5f;
162 | }
163 | if (KeyboardInput.IsKeyDown(Keys.NumPad6))
164 | {
165 | lightPos.Z -= 0.5f;
166 | }
167 | if (KeyboardInput.IsKeyDown(Keys.NumPad7))
168 | {
169 | lightPos.Y += 0.5f;
170 | }
171 | if (KeyboardInput.IsKeyDown(Keys.NumPad1))
172 | {
173 | lightPos.Y -= 0.5f;
174 | }
175 |
176 | if (KeyboardInput.IsKeyDown(Keys.A))
177 | {
178 | ambientPower += 0.1f;
179 | }
180 | if (KeyboardInput.IsKeyDown(Keys.Q))
181 | {
182 | ambientPower -= 0.1f;
183 | }
184 |
185 | if (KeyboardInput.IsKeyDown(Keys.Z))
186 | {
187 | lightPower += 0.1f;
188 | }
189 | if (KeyboardInput.IsKeyDown(Keys.S))
190 | {
191 | lightPower -= 0.1f;
192 | }
193 |
194 |
195 |
196 | UpdateLightData();
197 |
198 | base.Update(gameTime);
199 | }
200 |
201 | protected override void Draw(GameTime gameTime)
202 | {
203 | //device.SetRenderTarget(renderTarget);
204 | //device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
205 |
206 | //DrawScene("ShadowMap");
207 | //device.SetRenderTarget(null);
208 | //shadowMap = (Texture2D)renderTarget;
209 |
210 | //device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.DarkSlateBlue, 1.0f, 0);
211 | //using (SpriteBatch sprite = new SpriteBatch(device))
212 | //{
213 | // sprite.Begin();
214 | // sprite.Draw(shadowMap, new Vector2(0, 0), null, Color.White, 0, new Vector2(0, 0), 0.4f, SpriteEffects.None, 1);
215 | // sprite.End();
216 | //}
217 |
218 |
219 |
220 |
221 | device.SetRenderTarget(renderTarget);
222 | device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
223 |
224 | DrawScene("ShadowMap");
225 |
226 | device.SetRenderTarget(null);
227 | shadowMap = (Texture2D)renderTarget;
228 |
229 | device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
230 | DrawScene("ShadowedScene");
231 |
232 |
233 | //debug => spb mess up with drawing here
234 | spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.PointClamp, null, null);
235 | Rectangle rect = new Rectangle(0, 0, 256, 256);
236 | spriteBatch.Draw((Texture2D)renderTarget, rect, Color.White);
237 | spriteBatch.End();
238 |
239 | GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
240 | //debug
241 |
242 | shadowMap = null;
243 |
244 | base.Draw(gameTime);
245 |
246 |
247 |
248 |
249 |
250 | //device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.DarkSlateBlue, 1.0f, 0);
251 | //GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
252 |
253 | //DrawScene("ShadowMap");
254 |
255 | //effect.CurrentTechnique = effect.Techniques["SimplestTex"];
256 | //effect.Parameters["xTexture"].SetValue(streetTexture);
257 | //effect.Parameters["xWorldViewProjection"].SetValue(Matrix.Identity * viewMatrix * projectionMatrix);
258 |
259 | //effect.Parameters["xWorld"].SetValue(Matrix.Identity);
260 | //effect.Parameters["xLightPos"].SetValue(lightPos);
261 | //effect.Parameters["xLightPower"].SetValue(lightPower);
262 | //effect.Parameters["xAmbient"].SetValue(ambientPower);
263 |
264 | //effect.Parameters["xLightsWorldViewProjection"].SetValue(Matrix.Identity * lightsViewProjectionMatrix);
265 |
266 | //foreach (EffectPass pass in effect.CurrentTechnique.Passes)
267 | //{
268 | // pass.Apply();
269 |
270 | // device.SetVertexBuffer(vertexBuffer);
271 | // device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 16);
272 | //}
273 |
274 | //Matrix car1Matrix = Matrix.CreateScale(4f) * Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateTranslation(-3, 0, -15);
275 | //DrawModel(carModel, carTextures, car1Matrix, "SimplestTex");
276 |
277 | //Matrix car2Matrix = Matrix.CreateScale(4f) * Matrix.CreateRotationY(MathHelper.Pi * 5.0f / 8.0f) * Matrix.CreateTranslation(-28, 0, -1.9f);
278 | //DrawModel(carModel, carTextures, car2Matrix, "SimplestTex");
279 |
280 | //base.Draw(gameTime);
281 | }
282 |
283 | private Model LoadModel(string assetName, out Texture2D[] textures)
284 | {
285 |
286 | Model newModel = Content.Load(assetName);
287 | textures = new Texture2D[7];
288 | int i = 0;
289 | foreach (ModelMesh mesh in newModel.Meshes)
290 | foreach (BasicEffect currentEffect in mesh.Effects)
291 | textures[i++] = currentEffect.Texture;
292 |
293 | foreach (ModelMesh mesh in newModel.Meshes)
294 | foreach (ModelMeshPart meshPart in mesh.MeshParts)
295 | meshPart.Effect = effect.Clone();
296 |
297 | return newModel;
298 | }
299 |
300 | private void DrawModel(Model model, Texture2D[] textures, Matrix wMatrix, string technique)
301 | {
302 | Matrix[] modelTransforms = new Matrix[model.Bones.Count];
303 | model.CopyAbsoluteBoneTransformsTo(modelTransforms);
304 | int i = 0;
305 | foreach (ModelMesh mesh in model.Meshes)
306 | {
307 | foreach (Effect currentEffect in mesh.Effects)
308 | {
309 | Matrix worldMatrix = modelTransforms[mesh.ParentBone.Index] * wMatrix;
310 | currentEffect.CurrentTechnique = currentEffect.Techniques[technique];
311 | currentEffect.Parameters["xWorldViewProjection"].SetValue(worldMatrix * viewMatrix * projectionMatrix);
312 |
313 | if (textures != null && textures[i] != null)
314 | {
315 | currentEffect.Parameters["xTexture"].SetValue(textures[i++]);
316 | }
317 |
318 | currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
319 | currentEffect.Parameters["xLightPos"].SetValue(lightPos);
320 | currentEffect.Parameters["xLightPower"].SetValue(lightPower);
321 | currentEffect.Parameters["xAmbient"].SetValue(ambientPower);
322 |
323 | currentEffect.Parameters["xLightsWorldViewProjection"].SetValue(worldMatrix * lightsViewProjectionMatrix);
324 | currentEffect.Parameters["xShadowMap"].SetValue(shadowMap);
325 | }
326 | mesh.Draw();
327 | }
328 | }
329 |
330 | //private void UpdateLightData()
331 | //{
332 | // lightPos = new Vector3(-10, 4, -2);
333 | // lightPower = 1.0f;
334 | // ambientPower = 0.001f;
335 | //}
336 |
337 | private void UpdateLightData()
338 | {
339 |
340 |
341 | Matrix lightsView = Matrix.CreateLookAt(lightPos, new Vector3(-2, 3, -10), new Vector3(0, 1, 0));
342 | Matrix lightsProjection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver2, 1f, 5f, 100f);
343 |
344 | lightsViewProjectionMatrix = lightsView * lightsProjection;
345 | }
346 |
347 | private void DrawScene(string technique)
348 | {
349 | effect.CurrentTechnique = effect.Techniques[technique];
350 | effect.Parameters["xWorldViewProjection"].SetValue(Matrix.Identity * viewMatrix * projectionMatrix);
351 | effect.Parameters["xTexture"].SetValue(streetTexture);
352 | effect.Parameters["xWorld"].SetValue(Matrix.Identity);
353 | effect.Parameters["xLightPos"].SetValue(lightPos);
354 | effect.Parameters["xLightPower"].SetValue(lightPower);
355 | effect.Parameters["xAmbient"].SetValue(ambientPower);
356 | effect.Parameters["xLightsWorldViewProjection"].SetValue(Matrix.Identity * lightsViewProjectionMatrix);
357 | effect.Parameters["xShadowMap"].SetValue(shadowMap);
358 |
359 | foreach (EffectPass pass in effect.CurrentTechnique.Passes)
360 | {
361 | pass.Apply();
362 |
363 | device.SetVertexBuffer(vertexBuffer);
364 | device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 16);
365 | }
366 |
367 | //Matrix lampp1matrix = Matrix.CreateScale(0.05f) * Matrix.CreateRotationY(MathHelper.PiOver2) * Matrix.CreateTranslation(-4.0f, 5, 1);
368 | //DrawModel(lamppost, null, lampp1matrix, technique);
369 |
370 | Matrix car1Matrix = Matrix.CreateScale(4f) * Matrix.CreateRotationY(MathHelper.Pi) * Matrix.CreateTranslation(-3, 0, -15);
371 | DrawModel(carModel, carTextures, car1Matrix, technique);
372 |
373 | Matrix car2Matrix = Matrix.CreateScale(4f) * Matrix.CreateRotationY(MathHelper.Pi * 5.0f / 8.0f) * Matrix.CreateTranslation(-28, 0, -1.9f);
374 | DrawModel(carModel, carTextures, car2Matrix, technique);
375 | }
376 | }
377 | }
--------------------------------------------------------------------------------
/pictures/BumpMap.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/pictures/BumpMap.jpg
--------------------------------------------------------------------------------
/pictures/Reflection-issue.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/pictures/Reflection-issue.jpg
--------------------------------------------------------------------------------
/pictures/Toon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/pictures/Toon.jpg
--------------------------------------------------------------------------------
/pictures/ambient.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/pictures/ambient.jpg
--------------------------------------------------------------------------------
/pictures/diffuse.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/pictures/diffuse.jpg
--------------------------------------------------------------------------------
/pictures/skybox.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/pictures/skybox.jpg
--------------------------------------------------------------------------------
/pictures/specular1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/pictures/specular1.jpg
--------------------------------------------------------------------------------
/pictures/textured1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/pictures/textured1.jpg
--------------------------------------------------------------------------------
/pictures/textured2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/pictures/textured2.jpg
--------------------------------------------------------------------------------
/pictures/transparency-1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/pictures/transparency-1.jpg
--------------------------------------------------------------------------------
/specular1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/specular1.jpg
--------------------------------------------------------------------------------
/textured1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/textured1.jpg
--------------------------------------------------------------------------------
/textured2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/InfiniteProductions/MonoGameShaders/ac6a1482c838b1440436015efd3ca0fdba8aed08/textured2.jpg
--------------------------------------------------------------------------------