diff --git a/P3D.sln b/P3D.sln index 457419d4a..141663bfd 100644 --- a/P3D.sln +++ b/P3D.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P3D.ContentPipeline", "lib\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kolben", "lib\kolben\Kolben\Kolben.csproj", "{ED665F9B-07F4-4415-BD72-A728CF1EA909}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{7877D883-AA51-4C27-ADA5-C4F85F86F4EE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -50,6 +52,7 @@ Global GlobalSection(NestedProjects) = preSolution {C0456069-ED23-4009-BC24-C5B35B25E63B} = {3CE8099E-129D-40F9-8D23-005DFF32E2A2} {ED665F9B-07F4-4415-BD72-A728CF1EA909} = {3CE8099E-129D-40F9-8D23-005DFF32E2A2} + {7877D883-AA51-4C27-ADA5-C4F85F86F4EE} = {3CE8099E-129D-40F9-8D23-005DFF32E2A2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {8FE3951F-DE18-41FF-A035-32DF597A91F2} diff --git a/P3D/Core/Core.vb b/P3D/Core/Core.vb index f878da328..d9187ecb2 100644 --- a/P3D/Core/Core.vb +++ b/P3D/Core/Core.vb @@ -1,17 +1,38 @@ Public Module Core + Public GameInstance As GameController + + Public ReadOnly Property GraphicsManager As GraphicsDeviceManager + Get + Return GameInstance.Graphics + End Get + End Property + + Public ReadOnly Property GraphicsDevice As GraphicsDevice + Get + Return GameInstance.GraphicsDevice + End Get + End Property + + Public ReadOnly Property Content As ContentManager + Get + Return GameInstance.Content + End Get + End Property + + Public ReadOnly Property Window As GameWindow + Get + Return GameInstance.Window + End Get + End Property + Public SpriteBatch As CoreSpriteBatch Public FontRenderer As SpriteBatch - Public GraphicsDevice As GraphicsDevice - Public GraphicsManager As GraphicsDeviceManager - Public Content As ContentManager Public GameTime As GameTime - Public GameInstance As GameController Public Random As System.Random = New System.Random() Public KeyboardInput As KeyboardInput - Public window As GameWindow Public windowSize As Rectangle = New Rectangle(0, 0, 1200, 680) Public GameMessage As GameMessage @@ -33,17 +54,10 @@ Public Sub Initialize(ByVal gameReference As GameController) GameInstance = gameReference - GraphicsManager = GameInstance.Graphics - GraphicsDevice = GameInstance.GraphicsDevice - Content = GameInstance.Content - SpriteBatch = New CoreSpriteBatch(GraphicsDevice) - FontRenderer = New CoreSpriteBatch(GraphicsDevice) - window = GameInstance.Window - If CommandLineArgHandler.ForceGraphics = True Then - window.Title = GameController.GAMENAME & " " & GameController.GAMEDEVELOPMENTSTAGE & " " & GameController.GAMEVERSION & " (FORCED GRAPHICS)" + Window.Title = GameController.GAMENAME & " " & GameController.GAMEDEVELOPMENTSTAGE & " " & GameController.GAMEVERSION & " (FORCED GRAPHICS)" Else - window.Title = GameController.GAMENAME & " " & GameController.GAMEDEVELOPMENTSTAGE & " " & GameController.GAMEVERSION + Window.Title = GameController.GAMENAME & " " & GameController.GAMEDEVELOPMENTSTAGE & " " & GameController.GAMEVERSION End If GameOptions = New GameOptions() @@ -57,9 +71,13 @@ windowSize = New Rectangle(0, 0, CInt(GameOptions.WindowSize.X), CInt(GameOptions.WindowSize.Y)) GraphicsManager.PreferMultiSampling = True + GraphicsManager.GraphicsProfile = GraphicsProfile.HiDef GraphicsManager.ApplyChanges() + SpriteBatch = New CoreSpriteBatch(GraphicsDevice) + FontRenderer = New CoreSpriteBatch(GraphicsDevice) + Canvas.SetupCanvas() Player = New Player() GameJoltSave = New GameJolt.GamejoltSave() diff --git a/P3D/Modules/Extensions.vb b/P3D/Modules/Extensions.vb index a00b87803..31431cd17 100644 --- a/P3D/Modules/Extensions.vb +++ b/P3D/Modules/Extensions.vb @@ -40,31 +40,6 @@ Module Extensions Return GetSplit(fullString, valueIndex, ",") End Function - - Public Function SetSplit(ByVal fullString As String, ByVal valueIndex As Integer, ByVal newValue As String, ByVal seperator As String, ByVal replace As Boolean) As String - Dim s() As String = fullString.Split({seperator}, System.StringSplitOptions.None) - - fullString = "" - - For x = 0 To s.Count - 1 - If x = valueIndex Then - If replace = True Then - fullString &= newValue - Else - fullString &= newValue & seperator & s(x) - End If - Else - fullString &= s(x) - End If - - If x <> s.Count - 1 Then - fullString &= seperator - End If - Next - - Return fullString - End Function - Public Function CountSplits(ByVal fullString As String, ByVal seperator As String) As Integer Dim i As Integer = 0 diff --git a/P3D/MonoGame.Framework.dll.config b/P3D/MonoGame.Framework.dll.config deleted file mode 100644 index 09710ae46..000000000 --- a/P3D/MonoGame.Framework.dll.config +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/P3D/P3D.vbproj b/P3D/P3D.vbproj index f31ec4beb..b75c51a71 100644 --- a/P3D/P3D.vbproj +++ b/P3D/P3D.vbproj @@ -12,7 +12,7 @@ P3D Pokemon3D 512 - DesktopGL + Windows v4.5 @@ -49,6 +49,8 @@ bin\Debug\ + + @@ -56,6 +58,7 @@ bin\Release\ + @@ -63,6 +66,7 @@ bin\Release\ + @@ -70,6 +74,7 @@ bin\Debug\ + @@ -77,9 +82,35 @@ - - ..\packages\MonoGame.Framework.DesktopGL.3.6.0.1625\lib\net40\MonoGame.Framework.dll - True + + ..\packages\MonoGame.Framework.DX.3.7.0.1289-develop\lib\net45\MonoGame.Framework.dll + + + ..\packages\SharpDX.4.0.1\lib\net45\SharpDX.dll + + + ..\packages\SharpDX.Direct2D1.4.0.1\lib\net45\SharpDX.Direct2D1.dll + + + ..\packages\SharpDX.Direct3D11.4.0.1\lib\net45\SharpDX.Direct3D11.dll + + + ..\packages\SharpDX.Direct3D9.4.0.1\lib\net45\SharpDX.Direct3D9.dll + + + ..\packages\SharpDX.DXGI.4.0.1\lib\net45\SharpDX.DXGI.dll + + + ..\packages\SharpDX.Mathematics.4.0.1\lib\net45\SharpDX.Mathematics.dll + + + ..\packages\SharpDX.MediaFoundation.4.0.1\lib\net45\SharpDX.MediaFoundation.dll + + + ..\packages\SharpDX.XAudio2.4.0.1\lib\net45\SharpDX.XAudio2.dll + + + ..\packages\SharpDX.XInput.4.0.1\lib\net45\SharpDX.XInput.dll @@ -25856,7 +25887,6 @@ PreserveNewest - diff --git a/P3D/Screens/GUI/Canvas.vb b/P3D/Screens/GUI/Canvas.vb index 76ecc6cd8..a9116e983 100644 --- a/P3D/Screens/GUI/Canvas.vb +++ b/P3D/Screens/GUI/Canvas.vb @@ -3,11 +3,8 @@ Private Shared Canvas As Texture2D Public Shared Sub SetupCanvas() - Dim tempData(0) As Color - tempData(0) = Color.White - Canvas = New Texture2D(Core.GraphicsDevice, 1, 1) - Canvas.SetData(tempData) + Canvas.SetData({Color.White}) End Sub Public Shared Sub DrawRectangle(ByVal Rectangle As Rectangle, ByVal color As Color) diff --git a/P3D/packages.config b/P3D/packages.config index 9b38dcf77..a6cfe62ae 100644 --- a/P3D/packages.config +++ b/P3D/packages.config @@ -1,4 +1,13 @@  - + + + + + + + + + + \ No newline at end of file diff --git a/lib/P3D.ContentPipeline/Content/Content.mgcb b/lib/P3D.ContentPipeline/Content/Content.mgcb index 33ad2d32e..906f5dfbd 100644 --- a/lib/P3D.ContentPipeline/Content/Content.mgcb +++ b/lib/P3D.ContentPipeline/Content/Content.mgcb @@ -3,10 +3,10 @@ /outputDir:bin /intermediateDir:obj -/platform:DesktopGL +/platform:Windows /config: /profile:Reach -/compress:True +/compress:False #-------------------------------- References --------------------------------# @@ -19,24 +19,6 @@ /processorParam:DebugMode=Auto /build:Effects/BackdropShader.fx -#begin Effects/BlurEffect.fx -/importer:EffectImporter -/processor:EffectProcessor -/processorParam:DebugMode=Auto -/build:Effects/BlurEffect.fx - -#begin Effects/DiffuseShader.fx -/importer:EffectImporter -/processor:EffectProcessor -/processorParam:DebugMode=Auto -/build:Effects/DiffuseShader.fx - -#begin Effects/Toon.fx -/importer:EffectImporter -/processor:EffectProcessor -/processorParam:DebugMode=Auto -/build:Effects/Toon.fx - #begin Fonts/BMP/Braille.png /importer:TextureImporter /processor:FontTextureProcessor diff --git a/lib/P3D.ContentPipeline/Content/Effects/BackdropShader.fx b/lib/P3D.ContentPipeline/Content/Effects/BackdropShader.fx index aa4cab07d..8e2f70fb6 100644 --- a/lib/P3D.ContentPipeline/Content/Effects/BackdropShader.fx +++ b/lib/P3D.ContentPipeline/Content/Effects/BackdropShader.fx @@ -10,52 +10,61 @@ texture offset; float4 DiffuseColor; float2 TexStretch; -sampler color_sampler = sampler_state { texture = < color > ; }; -sampler normal_sampler = sampler_state { texture = < normals > ; }; -sampler offset_sampler = sampler_state { texture = < offset > ; }; +sampler color_sampler = sampler_state +{ + texture = ; +}; +sampler normal_sampler = sampler_state +{ + texture = ; +}; +sampler offset_sampler = sampler_state +{ + texture = ; +}; struct VertexShaderInput { - float4 Position : POSITION0; - float2 TexCoord : TEXCOORD0; - float3 Normal : NORMAL; + float4 Position : POSITION0; + float2 TexCoord : TEXCOORD0; + float3 Normal : NORMAL; }; struct VertexShaderOutput { - float4 Position : POSITION0; - float2 TexCoord : TEXCOORD1; - float4 Normal : TEXCOORD0; + float4 Position : POSITION0; + float2 TexCoord : TEXCOORD1; + float4 Normal : TEXCOORD0; }; VertexShaderOutput VertexShaderFunction(VertexShaderInput input) { - VertexShaderOutput output; + VertexShaderOutput output; - float4 worldPosition = mul(input.Position, World); - float4 viewPosition = mul(worldPosition, View); + float4 worldPosition = mul(input.Position, World); + float4 viewPosition = mul(worldPosition, View); - output.Position = mul(viewPosition, Projection); - output.Normal = mul(input.Normal, World); - output.TexCoord = input.TexCoord; + output.Position = mul(viewPosition, Projection); + output.Normal = mul(input.Normal, World); + output.TexCoord = input.TexCoord; - return output; + return output; } float4 TextureShaderFunction(VertexShaderOutput input) : COLOR0 { - float4 resultColor = tex2D(color_sampler, float2(input.TexCoord.x * TexStretch.x, input.TexCoord.y * TexStretch.y)) * DiffuseColor; + float4 resultColor = tex2D(color_sampler, float2(input.TexCoord.x * TexStretch.x, input.TexCoord.y * TexStretch.y)) * DiffuseColor; - return resultColor; + return resultColor; } technique Texture { - pass Pass1 - { + pass Pass1 + { // TODO: set renderstates here. - VertexShader = compile vs_2_0 VertexShaderFunction(); - PixelShader = compile ps_2_0 TextureShaderFunction(); - } + VertexShader = compile vs_5_0 VertexShaderFunction(); + PixelShader = compile ps_5_0 TextureShaderFunction(); + } } \ No newline at end of file diff --git a/lib/P3D.ContentPipeline/Content/Effects/BlurEffect.fx b/lib/P3D.ContentPipeline/Content/Effects/BlurEffect.fx deleted file mode 100644 index 43c014241..000000000 --- a/lib/P3D.ContentPipeline/Content/Effects/BlurEffect.fx +++ /dev/null @@ -1,243 +0,0 @@ -//------------------------------------------- Defines ------------------------------------------- - -#define Pi 3.14159265 - -//------------------------------------- Top Level Variables ------------------------------------- - -// Top level variables can and have to be set at runtime -float4 AmbientColor; -float AmbientIntensity; -float4 DiffuseColor; -texture ScreenTexture; -texture2D SpotlightTexture; - -float WorldRotation; - -int TextureWidth; - -// Matrices for 3D perspective projection -float4x4 View, Projection, World, WorldIT; - -//---------------------------------- Input / Output structures ---------------------------------- - -// Each member of the struct has to be given a "semantic", to indicate what kind of data should go in -// here and how it should be treated. Read more about the POSITION0 and the many other semantics in -// the MSDN library -struct VertexShaderInput -{ - float4 Position3D : POSITION0; - float4 Normals3D : NORMAL0; -}; - -// The output of the vertex shader. After being passed through the interpolator/rasterizer it is also -// the input of the pixel shader. -// Note 1: The values that you pass into this struct in the vertex shader are not the same as what -// you get as input for the pixel shader. A vertex shader has a single vertex as input, the pixel -// shader has 3 vertices as input, and lets you determine the color of each pixel in the triangle -// defined by these three vertices. Therefor, all the values in the struct that you get as input for -// the pixel shaders have been linearly interpolated between there three vertices! -// Note 2: You cannot use the data with the POSITION0 semantic in the pixel shader. -struct VertexShaderOutput -{ - float4 Position2D : POSITION0; - float4 Normals : TEXCOORD0; - float4 lightDir : TEXCOORD1; - float4 lambertLightDir : TEXCOORD2; - float4 Position : TEXCOORD3; -}; - -//---------------------------------------- Technique: Simple ---------------------------------------- - -VertexShaderOutput SimpleVertexShader(VertexShaderInput input) -{ - // Allocate an empty output struct - VertexShaderOutput output = (VertexShaderOutput)0; - - input.Position3D.w = 1.0f; - - // Do the matrix multiplications for perspective projection and the world transform - float4 worldPosition = mul(input.Position3D, World); - float4 viewPosition = mul(worldPosition, View); - output.Position2D = mul(viewPosition, Projection); - output.Position = mul(viewPosition, Projection); - output.Normals = mul(input.Normals3D, WorldIT); - float4 lightPoint = { -3, -2, -2, 0 }; - output.lightDir = normalize(worldPosition - lightPoint); - output.lambertLightDir = float4(30, 30, 20, 0); - - return output; -} - -float4 SimplePixelShader(VertexShaderOutput input) : COLOR0 -{ - - float4 color = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir)); - color += AmbientColor * AmbientIntensity; - - return color; -} - -float4 SpotlightPixelShader(VertexShaderOutput input) : COLOR0 -{ - float4 lightDirection = { 1, 1, 1, 0 }; - float theta = 20.0f; - float phi = 40.0f; - float4 color; - float4 lambert = DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir)); - float angle = acos(dot(input.lightDir, normalize(lightDirection))); - - if (angle > radians(phi)) - color = AmbientColor * AmbientIntensity; - else if (angle < radians(theta)) - color = lambert; - else - color = max(AmbientColor * AmbientIntensity, smoothstep(radians(phi), radians(theta), angle) * lambert); - - return color; -} - -sampler SpotlightTextureSampler :register(s2) = sampler_state -{ - Texture = ; -}; - -float4 TexturedSpotlightPixelShader(VertexShaderOutput input) : COLOR0 -{ - float4 color; - - float2 TextureCoordinates; - TextureCoordinates.x = input.Position.x / input.Position.w / 2.0f + 0.5f; - TextureCoordinates.y = -input.Position.y / input.Position.w / 2.0f + 0.5f; - - float4 lightDirection = { 1, 1, 1, 0 }; - float theta = 20.0f; - float phi = 40.0f; - float angle = acos(dot(input.lightDir, normalize(lightDirection))); - color = AmbientColor * AmbientIntensity + DiffuseColor * 0.2 * max(0, dot(input.Normals, input.lambertLightDir)); - color *= 0.6; - if (angle < radians(phi)) - color += tex2D(SpotlightTextureSampler, TextureCoordinates); - - return color; -} - -sampler TextureSampler = sampler_state -{ - Texture = ; -}; - -float4 GrayscalePixelShader(float2 TextureCoordinate : TEXCOORD0) : COLOR0 -{ - // Get the color. - float4 color = tex2D(TextureSampler, TextureCoordinate); - - // Turn pixel to grayscale. - float grayscale = dot(color.rgb, float3(0.3, 0.59, 0.11)); - color.r = grayscale; - color.g = grayscale; - color.b = grayscale; - color.a = 1.0f; - - // Return the result. - return color; -} - -float Pixels[13] = -{ - -6, - -5, - -4, - -3, - -2, - -1, - 0, - 1, - 2, - 3, - 4, - 5, - 6, -}; - -float BlurWeights[13] = -{ - 0.002216, - 0.008764, - 0.026995, - 0.064759, - 0.120985, - 0.176033, - 0.199471, - 0.176033, - 0.120985, - 0.064759, - 0.026995, - 0.008764, - 0.002216, -}; - - -float4 GaussianPixelShader(float2 TextureCoordinate : TEXCOORD0) : COLOR -{ - // Pixel width - float pixelWidth = 1.0 / (float)TextureWidth; - - float4 color = { 0, 0, 0, 1 }; - - float2 blur; - blur.y = TextureCoordinate.y; - - for (int i = 0; i < 13; i++) - { - blur.x = TextureCoordinate.x + Pixels[i] * (pixelWidth * 2); - blur.y = TextureCoordinate.y + Pixels[i] * (pixelWidth * 2); - color += tex2D(TextureSampler, blur.xy) * BlurWeights[i]; - } - - return color; -} - - -technique Simple -{ - - pass Pass0 - { - VertexShader = compile vs_2_0 SimpleVertexShader(); - PixelShader = compile ps_2_0 SimplePixelShader(); - } -} - -technique Spotlight -{ - pass Pass0 - { - VertexShader = compile vs_2_0 SimpleVertexShader(); - PixelShader = compile ps_2_0 SpotlightPixelShader(); - } -} - -technique Greyscale -{ - pass Pass0 - { - PixelShader = compile ps_2_0 GrayscalePixelShader(); - } -} - -technique GaussianBlur -{ - pass Pass0 - { - PixelShader = compile ps_2_0 GaussianPixelShader(); - } -} - -technique TexturedLight -{ - pass Pass0 - { - VertexShader = compile vs_2_0 SimpleVertexShader(); - PixelShader = compile ps_2_0 TexturedSpotlightPixelShader(); - } -} diff --git a/lib/P3D.ContentPipeline/Content/Effects/DiffuseShader.fx b/lib/P3D.ContentPipeline/Content/Effects/DiffuseShader.fx deleted file mode 100644 index 1d83604ae..000000000 --- a/lib/P3D.ContentPipeline/Content/Effects/DiffuseShader.fx +++ /dev/null @@ -1,75 +0,0 @@ -float4x4 WorldMatrix; -float4x4 ViewMatrix; -float4x4 ProjectionMatrix; - -float4 AmbienceColor = float4(0.1f, 0.1f, 0.1f, 1.0f); - -// For Diffuse Lightning -float4x4 WorldInverseTransposeMatrix; -float3 DiffuseLightDirection = float3(-1.0f, 0.0f, 0.0f); -float4 DiffuseColor = float4(1.0f, 1.0f, 1.0f, 1.0f); - -// For Texture -texture ModelTexture; -sampler2D TextureSampler = sampler_state { - Texture = (ModelTexture); - MagFilter = Linear; - MinFilter = Linear; - AddressU = Clamp; - AddressV = Clamp; -}; - -struct VertexShaderInput -{ - float4 Position : POSITION0; - // For Diffuse Lightning - float4 NormalVector : NORMAL0; - // For Texture - float2 TextureCoordinate : TEXCOORD0; -}; - -struct VertexShaderOutput -{ - float4 Position : POSITION0; - // For Diffuse Lightning - float4 VertexColor : COLOR0; - // For Texture - float2 TextureCoordinate : TEXCOORD0; -}; - -VertexShaderOutput VertexShaderFunction(VertexShaderInput input) -{ - VertexShaderOutput output; - - float4 worldPosition = mul(input.Position, WorldMatrix); - float4 viewPosition = mul(worldPosition, ViewMatrix); - output.Position = mul(viewPosition, ProjectionMatrix); - - // For Diffuse Lightning - float4 normal = normalize(mul(input.NormalVector, WorldInverseTransposeMatrix)); - float lightIntensity = dot(normal, DiffuseLightDirection); - output.VertexColor = saturate(DiffuseColor * lightIntensity); - - // For Texture - output.TextureCoordinate = input.TextureCoordinate; - - return output; -} - -float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0 -{ - // For Texture - float4 VertexTextureColor = tex2D(TextureSampler, input.TextureCoordinate); - VertexTextureColor.a = 1; - - return saturate(VertexTextureColor * input.VertexColor + AmbienceColor); -} - -technique Texture -{ - pass Pass1 - { - VertexShader = compile vs_2_0 VertexShaderFunction(); - PixelShader = compile ps_2_0 PixelShaderFunction(); - } -} \ No newline at end of file diff --git a/lib/P3D.ContentPipeline/Content/Effects/GaussianBlur.fx b/lib/P3D.ContentPipeline/Content/Effects/GaussianBlur.fx index de1d5099d..f8366ff43 100644 --- a/lib/P3D.ContentPipeline/Content/Effects/GaussianBlur.fx +++ b/lib/P3D.ContentPipeline/Content/Effects/GaussianBlur.fx @@ -16,10 +16,10 @@ texture colorMapTexture; sampler2D colorMap = sampler_state { - Texture = ; - MipFilter = Linear; - MinFilter = Linear; - MagFilter = Linear; + Texture = ; + MipFilter = Linear; + MinFilter = Linear; + MagFilter = Linear; }; //----------------------------------------------------------------------------- @@ -28,12 +28,12 @@ sampler2D colorMap = sampler_state float4 PS_GaussianBlur(float2 texCoord : TEXCOORD) : COLOR0 { - float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f); + float4 color = float4(0.0f, 0.0f, 0.0f, 0.0f); - for (int i = 0; i < KERNEL_SIZE; ++i) - color += tex2D(colorMap, texCoord + offsets[i]) * weights[i]; + for (int i = 0; i < KERNEL_SIZE; ++i) + color += tex2D(colorMap, texCoord + offsets[i]) * weights[i]; - return color; + return color; } //----------------------------------------------------------------------------- @@ -42,8 +42,8 @@ float4 PS_GaussianBlur(float2 texCoord : TEXCOORD) : COLOR0 technique GaussianBlur { - pass - { - PixelShader = compile ps_2_0 PS_GaussianBlur(); - } + pass + { + PixelShader = compile ps_5_0 PS_GaussianBlur(); + } } diff --git a/lib/P3D.ContentPipeline/Content/Effects/Toon.fx b/lib/P3D.ContentPipeline/Content/Effects/Toon.fx deleted file mode 100644 index b84047333..000000000 --- a/lib/P3D.ContentPipeline/Content/Effects/Toon.fx +++ /dev/null @@ -1,164 +0,0 @@ -//--------------------------- BASIC PROPERTIES ------------------------------ -// The world transformation -float4x4 World; - -// The view transformation -float4x4 View; - -// The projection transformation -float4x4 Projection; - -// The transpose of the inverse of the world transformation, -// used for transforming the vertex's normal -float4x4 WorldInverseTranspose; - -//--------------------------- DIFFUSE LIGHT PROPERTIES ------------------------------ -// The direction of the diffuse light -float3 DiffuseLightDirection = float3(1, 0, 0); - -// The color of the diffuse light -float4 DiffuseColor = float4(1, 1, 1, 1); - -// The intensity of the diffuse light -float DiffuseIntensity = 1.0; - -//--------------------------- TOON SHADER PROPERTIES ------------------------------ -// The color to draw the lines in. Black is a good default. -float4 LineColor = float4(0, 0, 0, 1); - -// The thickness of the lines. This may need to change, depending on the scale of -// the objects you are drawing. -float LineThickness = .03; - -//--------------------------- TEXTURE PROPERTIES ------------------------------ -// The texture being used for the object -texture Texture; - -// The texture sampler, which will get the texture color -sampler2D textureSampler = sampler_state -{ - Texture = (Texture); - MinFilter = Linear; - MagFilter = Linear; - AddressU = Clamp; - AddressV = Clamp; -}; - -//--------------------------- DATA STRUCTURES ------------------------------ -// The structure used to store information between the application and the -// vertex shader -struct AppToVertex -{ - float4 Position : POSITION0; // The position of the vertex - float3 Normal : NORMAL0; // The vertex's normal - float2 TextureCoordinate : TEXCOORD0; // The texture coordinate of the vertex -}; - -// The structure used to store information between the vertex shader and the -// pixel shader -struct VertexToPixel -{ - float4 Position : POSITION0; - float2 TextureCoordinate : TEXCOORD0; - float3 Normal : TEXCOORD1; -}; - -//--------------------------- SHADERS ------------------------------ -// The vertex shader that does cel shading. -// It really only does the basic transformation of the vertex location, -// and normal, and copies the texture coordinate over. -VertexToPixel CelVertexShader(AppToVertex input) -{ - VertexToPixel output; - - // Transform the position - float4 worldPosition = mul(input.Position, World); - float4 viewPosition = mul(worldPosition, View); - output.Position = mul(viewPosition, Projection); - - // Transform the normal - output.Normal = normalize(mul(input.Normal, WorldInverseTranspose)); - - // Copy over the texture coordinate - output.TextureCoordinate = input.TextureCoordinate; - - return output; -} - -// The pixel shader that does cel shading. Basically, it calculates -// the color like is should, and then it discretizes the color into -// one of four colors. -float4 CelPixelShader(VertexToPixel input) : COLOR0 -{ - // Calculate diffuse light amount - float intensity = dot(normalize(DiffuseLightDirection), input.Normal); - if (intensity < 0) - intensity = 0; - - // Calculate what would normally be the final color, including texturing and diffuse lighting - float4 color = tex2D(textureSampler, input.TextureCoordinate) * DiffuseColor * DiffuseIntensity; - color.a = 1; - - // Discretize the intensity, based on a few cutoff points - if (intensity > 0.95) - color = float4(1.0, 1, 1, 1.0) * color; - else if (intensity > 0.5) - color = float4(0.7, 0.7, 0.7, 1.0) * color; - else if (intensity > 0.05) - color = float4(0.35, 0.35, 0.35, 1.0) * color; - else - color = float4(0.1, 0.1, 0.1, 1.0) * color; - - return color; -} - -// The vertex shader that does the outlines -VertexToPixel OutlineVertexShader(AppToVertex input) -{ - VertexToPixel output = (VertexToPixel)0; - - // Calculate where the vertex ought to be. This line is equivalent - // to the transformations in the CelVertexShader. - float4 original = mul(mul(mul(input.Position, World), View), Projection); - - // Calculates the normal of the vertex like it ought to be. - float4 normal = mul(mul(mul(input.Normal, World), View), Projection); - - // Take the correct "original" location and translate the vertex a little - // bit in the direction of the normal to draw a slightly expanded object. - // Later, we will draw over most of this with the right color, except the expanded - // part, which will leave the outline that we want. - output.Position = original + (mul(LineThickness, normal)); - - return output; -} - -// The pixel shader for the outline. It is pretty simple: draw everything with the -// correct line color. -float4 OutlinePixelShader(VertexToPixel input) : COLOR0 -{ - return LineColor; -} - -// The entire technique for doing toon shading -technique Toon -{ - // The first pass will go through and draw the back-facing triangles with the outline shader, - // which will draw a slightly larger version of the model with the outline color. Later, the - // model will get drawn normally, and draw over the top most of this, leaving only an outline. - pass Pass1 - { - VertexShader = compile vs_2_0 OutlineVertexShader(); - PixelShader = compile ps_2_0 OutlinePixelShader(); - CullMode = CW; - } - - // The second pass will draw the model like normal, but with the cel pixel shader, which will - // color the model with certain colors, giving us the cel/toon effect that we are looking for. - pass Pass2 - { - VertexShader = compile vs_2_0 CelVertexShader(); - PixelShader = compile ps_2_0 CelPixelShader(); - CullMode = CCW; - } -} diff --git a/lib/P3D.ContentPipeline/P3D.ContentPipeline.csproj b/lib/P3D.ContentPipeline/P3D.ContentPipeline.csproj index 5471201ba..a96fd454c 100644 --- a/lib/P3D.ContentPipeline/P3D.ContentPipeline.csproj +++ b/lib/P3D.ContentPipeline/P3D.ContentPipeline.csproj @@ -79,10 +79,7 @@ - - -