Browse Source

TilemapEffect

Nikos Kastellanos 6 years ago
parent
commit
d7780f3b09

+ 12 - 0
Aether.Extras.PORTABLE.sln

@@ -17,6 +17,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimationImporters.PORTABLE
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Atlas.PORTABLE", "Atlas\Aether.Atlas.PORTABLE.csproj", "{E5907795-BC19-4CAA-9909-9F7145E1BB0D}"
 EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Aether.Shaders", "Aether.Shaders", "{0193DE8C-8B7A-43F6-A30B-E65EC387B2C4}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Shaders.Tilemap.PORTABLE", "Shaders\Tilemap\Aether.Shaders.Tilemap.PORTABLE.csproj", "{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -47,6 +51,10 @@ Global
 		{E5907795-BC19-4CAA-9909-9F7145E1BB0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{E5907795-BC19-4CAA-9909-9F7145E1BB0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{E5907795-BC19-4CAA-9909-9F7145E1BB0D}.Release|Any CPU.Build.0 = Release|Any CPU
+		{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -55,5 +63,9 @@ Global
 		{C3218A39-5491-44BF-B820-754832E318DB} = {717F89BC-8423-4E7C-A834-460CFD62B1E3}
 		{0A079394-D331-433A-94DF-AA25B6522279} = {717F89BC-8423-4E7C-A834-460CFD62B1E3}
 		{962D579A-91F7-4FAB-940A-423E04B8465E} = {717F89BC-8423-4E7C-A834-460CFD62B1E3}
+		{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0} = {0193DE8C-8B7A-43F6-A30B-E65EC387B2C4}
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {CC734668-3E0E-4826-90C3-55064F0473DB}
 	EndGlobalSection
 EndGlobal

+ 7 - 0
Aether.Extras.WINDOWS.MG.sln

@@ -29,6 +29,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Atlas.WINDOWS.MG", "
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Shaders.InfiniteGrid.WINDOWS.MG", "Shaders\InfiniteGrid\Aether.Shaders.InfiniteGrid.WINDOWS.MG.csproj", "{08296A2E-BECF-4DB9-A518-8A613D07B80E}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Shaders.Tilemap.WINDOWS.MG", "Shaders\Tilemap\Aether.Shaders.Tilemap.WINDOWS.MG.csproj", "{6721CD07-0880-4154-85AF-EBE6043EF178}"
+EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SLMCImporter.WINDOWS.MG", "Content.Pipeline\SLMCImporter\SLMCImporter.WINDOWS.MG.csproj", "{C9FA924B-DA91-4641-8B7D-CBC09E5560AE}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VoxelImporters.WINDOWS.MG", "Content.Pipeline\VoxelImporters\VoxelImporters.WINDOWS.MG.csproj", "{AA15CF95-0AF2-4346-9465-CB6EDBE22ED9}"
@@ -83,6 +85,10 @@ Global
 		{08296A2E-BECF-4DB9-A518-8A613D07B80E}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{08296A2E-BECF-4DB9-A518-8A613D07B80E}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{08296A2E-BECF-4DB9-A518-8A613D07B80E}.Release|Any CPU.Build.0 = Release|Any CPU
+		{6721CD07-0880-4154-85AF-EBE6043EF178}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{6721CD07-0880-4154-85AF-EBE6043EF178}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{6721CD07-0880-4154-85AF-EBE6043EF178}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{6721CD07-0880-4154-85AF-EBE6043EF178}.Release|Any CPU.Build.0 = Release|Any CPU
 		{C9FA924B-DA91-4641-8B7D-CBC09E5560AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{C9FA924B-DA91-4641-8B7D-CBC09E5560AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{C9FA924B-DA91-4641-8B7D-CBC09E5560AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -104,6 +110,7 @@ Global
 		{96105100-20DB-4187-9BCA-0A20AC9F1298} = {13D47E11-4A7C-49C8-942E-2543E9C0098A}
 		{E710FBEA-8C75-405D-B6B4-CFC82CB48FB5} = {A921886B-C6F7-4FF8-8668-EC20004C464A}
 		{08296A2E-BECF-4DB9-A518-8A613D07B80E} = {13D47E11-4A7C-49C8-942E-2543E9C0098A}
+		{6721CD07-0880-4154-85AF-EBE6043EF178} = {13D47E11-4A7C-49C8-942E-2543E9C0098A}
 		{C9FA924B-DA91-4641-8B7D-CBC09E5560AE} = {A921886B-C6F7-4FF8-8668-EC20004C464A}
 		{AA15CF95-0AF2-4346-9465-CB6EDBE22ED9} = {A921886B-C6F7-4FF8-8668-EC20004C464A}
 	EndGlobalSection

+ 7 - 0
Aether.Extras.WINDOWS.XNA.sln

@@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Atlas.WINDOWS.XNA",
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Shaders.InfiniteGrid.WINDOWS.XNA", "Shaders\InfiniteGrid\Aether.Shaders.InfiniteGrid.WINDOWS.XNA.csproj", "{908EC8FF-B0ED-478A-B486-702E578AF64A}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aether.Shaders.Tilemap.WINDOWS.XNA", "Shaders\Tilemap\Aether.Shaders.Tilemap.WINDOWS.XNA.csproj", "{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}"
+EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SLMCImporter.WINDOWS.XNA", "Content.Pipeline\SLMCImporter\SLMCImporter.WINDOWS.XNA.csproj", "{497B1130-EB63-4057-BC40-F60D6FFA50CA}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VoxelImporters.WINDOWS.XNA", "Content.Pipeline\VoxelImporters\VoxelImporters.WINDOWS.XNA.csproj", "{0690782F-0000-0000-0000-000000000000}"
@@ -69,6 +71,10 @@ Global
 		{908EC8FF-B0ED-478A-B486-702E578AF64A}.Debug|x86.Build.0 = Debug|x86
 		{908EC8FF-B0ED-478A-B486-702E578AF64A}.Release|x86.ActiveCfg = Release|x86
 		{908EC8FF-B0ED-478A-B486-702E578AF64A}.Release|x86.Build.0 = Release|x86
+		{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}.Debug|x86.ActiveCfg = Debug|x86
+		{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}.Debug|x86.Build.0 = Debug|x86
+		{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}.Release|x86.ActiveCfg = Release|x86
+		{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}.Release|x86.Build.0 = Release|x86
 		{497B1130-EB63-4057-BC40-F60D6FFA50CA}.Debug|x86.ActiveCfg = Debug|x86
 		{497B1130-EB63-4057-BC40-F60D6FFA50CA}.Debug|x86.Build.0 = Debug|x86
 		{497B1130-EB63-4057-BC40-F60D6FFA50CA}.Release|x86.ActiveCfg = Release|x86
@@ -90,5 +96,6 @@ Global
 		{89E0198E-7298-411A-B5C1-61F2754A3F80} = {EFC7A27C-C20B-4BE7-8B3A-2B109991D704}
 		{B82B862D-C728-4A10-8A56-65D688E022C8} = {EFC7A27C-C20B-4BE7-8B3A-2B109991D704}
 		{908EC8FF-B0ED-478A-B486-702E578AF64A} = {EFC7A27C-C20B-4BE7-8B3A-2B109991D704}
+		{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6} = {EFC7A27C-C20B-4BE7-8B3A-2B109991D704}
 	EndGlobalSection
 EndGlobal

+ 49 - 0
Shaders/Tilemap/Aether.Shaders.Tilemap.PORTABLE.csproj

@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ProjectGuid>{CA1564C9-D4A6-4454-A6B6-7B4E907DF8C0}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <RootNamespace>tainicom.Aether.Shaders</RootNamespace>
+    <AssemblyName>Aether.Shaders.Tilemap</AssemblyName>
+    <TargetFrameworkProfile>Profile328</TargetFrameworkProfile>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <MinimumVisualStudioVersion>10.0</MinimumVisualStudioVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\bin\Debug\Portable\</OutputPath>
+    <DefineConstants>DEBUG;PORTABLE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ConsolePause>false</ConsolePause>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>none</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\bin\Release\Portable\</OutputPath>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <ConsolePause>false</ConsolePause>
+    <DefineConstants>PORTABLE</DefineConstants>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="TilemapEffect.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.PORTABLE.cs" />
+  </ItemGroup>
+  <ItemGroup>
+  </ItemGroup>
+  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
+  <ItemGroup>
+    <PackageReference Include="MonoGame.Framework.Portable.9000" Version="3.8.9008">
+      <PrivateAssets>all</PrivateAssets>
+      <ExcludeAssets>runtime</ExcludeAssets>
+    </PackageReference>
+  </ItemGroup>
+</Project>

+ 60 - 0
Shaders/Tilemap/Aether.Shaders.Tilemap.WINDOWS.MG.csproj

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{6721CD07-0880-4154-85AF-EBE6043EF178}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>tainicom.Aether.Shaders</RootNamespace>
+    <AssemblyName>Aether.Shaders.Tilemap</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\..\bin\Debug\Windows\</OutputPath>
+    <DefineConstants>TRACE;DEBUG;WINDOWS MG</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>none</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\bin\Release\Windows\</OutputPath>
+    <DefineConstants>TRACE;WINDOWS MG</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="TilemapEffect.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="Resources\TilemapEffect.dx11.mgfxo.8" />
+    <EmbeddedResource Include="Resources\TilemapEffect.dx11.mgfxo.9" />
+  </ItemGroup>
+  <ItemGroup>
+    <PackageReference Include="MonoGame.Framework.Portable.9000" Version="3.8.9008">
+      <PrivateAssets>all</PrivateAssets>
+      <ExcludeAssets>runtime</ExcludeAssets>
+    </PackageReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 61 - 0
Shaders/Tilemap/Aether.Shaders.Tilemap.WINDOWS.XNA.csproj

@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
+  <PropertyGroup>
+    <ProjectGuid>{AB2B4C7E-0FCA-4CFE-8837-E3E3374249F6}</ProjectGuid>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>tainicom.Aether.Shaders</RootNamespace>
+    <AssemblyName>Aether.Shaders.Tilemap</AssemblyName>
+    <XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
+    <XnaPlatform>Windows</XnaPlatform>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\..\bin\Debug\Windows.XNA\</OutputPath>
+    <DefineConstants>TRACE;DEBUG;WINDOWS XNA</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <DebugType>none</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\bin\Release\Windows.XNA\</OutputPath>
+    <DefineConstants>TRACE;WINDOWS XNA</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <PlatformTarget>x86</PlatformTarget>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
+    <Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
+    <Reference Include="Microsoft.Xna.Framework.Content.Pipeline, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
+    <Reference Include="System" />
+    <Reference Include="System.Core">
+      <RequiredTargetFramework>4.0</RequiredTargetFramework>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="TilemapEffect.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="Resources\TilemapEffect.xna.WinReach" />
+  </ItemGroup>
+  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+  <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.ContentPipelineExtensions.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+     Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 24 - 0
Shaders/Tilemap/Properties/AssemblyInfo.PORTABLE.cs

@@ -0,0 +1,24 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+[assembly: AssemblyTitle("Aether.Shaders.TileMap")]
+[assembly: AssemblyProduct("Aether.Shaders.TileMap")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyCopyright("Copyright ©  Kastellanos Nikolaos 2019-2021")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+
+[assembly: AssemblyVersion ("1.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
+

+ 37 - 0
Shaders/Tilemap/Properties/AssemblyInfo.cs

@@ -0,0 +1,37 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+[assembly: AssemblyTitle("Aether.Shaders.TileMap")]
+[assembly: AssemblyProduct("Aether.Shaders.TileMap")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyCopyright("Copyright ©  Kastellanos Nikolaos 2019-2021")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type. Only Windows
+// assemblies support COM.
+[assembly: ComVisible(false)]
+
+// On Windows, the following GUID is for the ID of the typelib if this
+// project is exposed to COM. On other platforms, it unique identifies the
+// title storage container when deploying this assembly to the device.
+[assembly: Guid("316AAED0-BF7E-4096-BF14-CAEC9D974C04")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
+

BIN
Shaders/Tilemap/Resources/TilemapEffect.dx11.mgfxo.8


BIN
Shaders/Tilemap/Resources/TilemapEffect.dx11.mgfxo.9


BIN
Shaders/Tilemap/Resources/TilemapEffect.ogl.mgfxo.8


BIN
Shaders/Tilemap/Resources/TilemapEffect.ogl.mgfxo.9


BIN
Shaders/Tilemap/Resources/TilemapEffect.xna.WinReach


+ 25 - 0
Shaders/Tilemap/Shaders/BuildShaders.bat

@@ -0,0 +1,25 @@
+@echo off
+setlocal
+
+cd %~dp0
+
+SET MGFX="C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools\2mgfx.exe"
+SET XNAFX="..\..\Tools\CompileEffect\CompileEffect.exe"
+
+@echo Build dx11
+@for /f %%f IN ('dir /b *.fx') do (
+    call %MGFX% %%~nf.fx ..\Resources\%%~nf.dx11.mgfxo /Profile:DirectX_11
+)
+
+@echo Build ogl
+@for /f %%f IN ('dir /b *.fx') do (
+    call %MGFX% %%~nf.fx ..\Resources\%%~nf.ogl.mgfxo
+)
+
+@echo Build dx9/xna Reach
+@for /f %%f IN ('dir /b *.fx') do (
+    call %XNAFX% Windows Reach %%~nf.fx ..\Resources\%%~nf.xna.WinReach
+)
+
+endlocal
+@pause

+ 58 - 0
Shaders/Tilemap/Shaders/Common.fxh

@@ -0,0 +1,58 @@
+//-----------------------------------------------------------------------------
+// Common.fxh
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+
+
+float ComputeFogFactor(float4 position)
+{
+    return saturate(dot(position, FogVector));
+}
+
+
+void ApplyFog(inout float4 color, float fogFactor)
+{
+    color.rgb = lerp(color.rgb, FogColor * color.a, fogFactor);
+}
+
+
+void AddSpecular(inout float4 color, float3 specular)
+{
+    color.rgb += specular * color.a;
+}
+
+
+struct CommonVSOutput
+{
+    float4 Pos_ps;
+    float4 Diffuse;
+    float3 Specular;
+    float  FogFactor;
+};
+
+
+CommonVSOutput ComputeCommonVSOutput(float4 position)
+{
+    CommonVSOutput vout;
+    
+    vout.Pos_ps = mul(position, WorldViewProj);
+    vout.Diffuse = DiffuseColor;
+    vout.Specular = 0;
+    vout.FogFactor = ComputeFogFactor(position);
+    
+    return vout;
+}
+
+
+#define SetCommonVSOutputParams \
+    vout.PositionPS = cout.Pos_ps; \
+    vout.Diffuse = cout.Diffuse; \
+    vout.Specular = float4(cout.Specular, cout.FogFactor);
+
+
+#define SetCommonVSOutputParamsNoFog \
+    vout.PositionPS = cout.Pos_ps; \
+    vout.Diffuse = cout.Diffuse;
+

+ 62 - 0
Shaders/Tilemap/Shaders/Macros.fxh

@@ -0,0 +1,62 @@
+//-----------------------------------------------------------------------------
+// Macros.fxh
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+
+#ifdef SM4
+
+
+// Macros for targetting shader model 4.0 (DX11)
+
+#define TECHNIQUE(name, vsname, psname ) \
+	technique name { pass { VertexShader = compile vs_4_0_level_9_1 vsname (); PixelShader = compile ps_4_0_level_9_1 psname(); } }
+
+#define BEGIN_CONSTANTS     cbuffer Parameters : register(b0) {
+#define MATRIX_CONSTANTS
+#define END_CONSTANTS       };
+
+#define _vs(r)
+#define _ps(r)
+#define _cb(r)
+
+#define DECLARE_TEXTURE(Name, index) \
+    Texture2D<float4> Name : register(t##index); \
+    sampler Name##Sampler : register(s##index)
+
+#define DECLARE_CUBEMAP(Name, index) \
+    TextureCube<float4> Name : register(t##index); \
+    sampler Name##Sampler : register(s##index)
+
+#define SAMPLE_TEXTURE(Name, texCoord)  Name.Sample(Name##Sampler, texCoord)
+#define SAMPLE_CUBEMAP(Name, texCoord)  Name.Sample(Name##Sampler, texCoord)
+
+
+#else
+
+
+// Macros for targetting shader model 2.0 (DX9)
+
+#define TECHNIQUE(name, vsname, psname ) \
+	technique name { pass { VertexShader = compile vs_2_0 vsname (); PixelShader = compile ps_2_0 psname(); } }
+
+#define BEGIN_CONSTANTS
+#define MATRIX_CONSTANTS
+#define END_CONSTANTS
+
+#define _vs(r)  : register(vs, r)
+#define _ps(r)  : register(ps, r)
+#define _cb(r)
+
+#define DECLARE_TEXTURE(Name, index) \
+    sampler2D Name##Sampler : register(s##index);
+
+#define DECLARE_CUBEMAP(Name, index) \
+    samplerCUBE Name : register(s##index);
+
+#define SAMPLE_TEXTURE(Name, texCoord)  tex2D(Name##Sampler, texCoord)
+#define SAMPLE_CUBEMAP(Name, texCoord)  texCUBE(Name##Sampler, texCoord)
+
+
+#endif

+ 161 - 0
Shaders/Tilemap/Shaders/Structures.fxh

@@ -0,0 +1,161 @@
+//-----------------------------------------------------------------------------
+// Structurs.fxh
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+
+
+// Vertex shader input structures.
+
+struct VSInput
+{
+    float4 Position : POSITION;
+};
+
+struct VSInputVc
+{
+    float4 Position : POSITION;
+    float4 Color    : COLOR;
+};
+
+struct VSInputTx
+{
+    float4 Position : POSITION;
+    float2 TexCoord : TEXCOORD;
+};
+
+struct VSInputTxVc
+{
+    float4 Position : POSITION;
+    float2 TexCoord : TEXCOORD;
+    float4 Color    : COLOR;
+};
+
+struct VSInputNm
+{
+    float4 Position : POSITION;
+    float3 Normal   : NORMAL;
+};
+
+struct VSInputNmVc
+{
+    float4 Position : POSITION;
+    float3 Normal   : NORMAL;
+    float4 Color    : COLOR;
+};
+
+struct VSInputNmTx
+{
+    float4 Position : POSITION;
+    float3 Normal   : NORMAL;
+    float2 TexCoord : TEXCOORD;
+};
+
+struct VSInputNmTxVc
+{
+    float4 Position : POSITION;
+    float3 Normal   : NORMAL;
+    float2 TexCoord : TEXCOORD;
+    float4 Color    : COLOR;
+};
+
+struct VSInputTx2
+{
+    float4 Position  : POSITION0;
+    float2 TexCoord  : TEXCOORD0;
+    float2 TexCoord2 : TEXCOORD1;
+};
+
+struct VSInputTx2Vc
+{
+    float4 Position  : POSITION0;
+    float2 TexCoord  : TEXCOORD0;
+    float2 TexCoord2 : TEXCOORD1;
+    float4 Color     : COLOR;
+};
+
+struct VSInputNmTxWeights
+{
+    float4 Position : POSITION0;
+    float3 Normal   : NORMAL0;
+    float2 TexCoord : TEXCOORD0;
+    uint4  Indices  : BLENDINDICES0;
+    float4 Weights  : BLENDWEIGHT0;
+};
+
+
+
+// Vertex shader output structures.
+
+struct VSOutput
+{
+    float4 PositionPS : SV_Position;
+    float4 Diffuse    : COLOR0;
+    float4 Specular   : COLOR1;
+};
+
+struct VSOutputNoFog
+{
+    float4 PositionPS : SV_Position;
+    float4 Diffuse    : COLOR0;
+};
+
+struct VSOutputTx
+{
+    float4 PositionPS : SV_Position;
+    float4 Diffuse    : COLOR0;
+    float4 Specular   : COLOR1;
+    float2 TexCoord   : TEXCOORD0;
+};
+
+struct VSOutputTxNoFog
+{
+    float4 PositionPS : SV_Position;
+    float4 Diffuse    : COLOR0;
+    float2 TexCoord   : TEXCOORD0;
+};
+
+struct VSOutputPixelLighting
+{
+    float4 PositionPS : SV_Position;
+    float4 PositionWS : TEXCOORD0;
+    float3 NormalWS   : TEXCOORD1;
+    float4 Diffuse    : COLOR0;
+};
+
+struct VSOutputPixelLightingTx
+{
+    float4 PositionPS : SV_Position;
+    float2 TexCoord   : TEXCOORD0;
+    float4 PositionWS : TEXCOORD1;
+    float3 NormalWS   : TEXCOORD2;
+    float4 Diffuse    : COLOR0;
+};
+
+struct VSOutputTx2
+{
+    float4 PositionPS : SV_Position;
+    float4 Diffuse    : COLOR0;
+    float4 Specular   : COLOR1;
+    float2 TexCoord   : TEXCOORD0;
+    float2 TexCoord2  : TEXCOORD1;
+};
+
+struct VSOutputTx2NoFog
+{
+    float4 PositionPS : SV_Position;
+    float4 Diffuse    : COLOR0;
+    float2 TexCoord   : TEXCOORD0;
+    float2 TexCoord2  : TEXCOORD1;
+};
+
+struct VSOutputTxEnvMap
+{
+    float4 PositionPS : SV_Position;
+    float4 Diffuse    : COLOR0;
+    float4 Specular   : COLOR1;
+    float2 TexCoord   : TEXCOORD0;
+    float3 EnvCoord   : TEXCOORD1;
+};
+

+ 158 - 0
Shaders/Tilemap/Shaders/TilemapEffect.fx

@@ -0,0 +1,158 @@
+#include "Macros.fxh"
+
+
+#ifdef SM4
+DECLARE_TEXTURE(Texture, 0);
+DECLARE_TEXTURE(TextureAtlas, 1);
+#else
+texture Texture;
+sampler TextureSampler : register(s0) = sampler_state
+{
+	Texture = (Texture);
+	MAGFILTER = POINT;
+	MINFILTER = POINT;
+	MIPFILTER = POINT;
+	AddressU = Wrap;
+	AddressV = Wrap;
+};
+texture TextureAtlas;
+sampler TextureAtlasSampler : register(s1) = sampler_state
+{
+    Texture = (TextureAtlas);
+	MAGFILTER = POINT; //LINEAR;
+	MINFILTER = POINT; //LINEAR;
+	MIPFILTER = POINT; //LINEAR;
+	AddressU = Wrap;
+	AddressV = Wrap;
+};
+#endif
+
+
+BEGIN_CONSTANTS
+
+    float4 DiffuseColor     _vs(c0) _cb(c0);
+    float3 FogColor         _ps(c0) _cb(c1);
+    float4 FogVector        _vs(c5) _cb(c2);
+    float2 MapSize;
+	float2 InvAtlasSize;
+
+MATRIX_CONSTANTS
+
+    float4x4 WorldViewProj  _vs(c1) _cb(c0);
+
+END_CONSTANTS
+
+
+#include "Structures.fxh"
+#include "Common.fxh"
+
+
+// Vertex shader: basic.
+VSOutputTx VSTilemapFog(VSInputTx vin)
+{
+    VSOutputTx vout;
+    
+    CommonVSOutput cout = ComputeCommonVSOutput(vin.Position);
+    SetCommonVSOutputParams;
+    
+    vout.TexCoord = vin.TexCoord;
+
+    return vout;
+}
+
+
+// Vertex shader: no fog.
+VSOutputTxNoFog VSTilemap(VSInputTx vin)
+{
+    VSOutputTxNoFog vout;
+    
+    CommonVSOutput cout = ComputeCommonVSOutput(vin.Position);
+    SetCommonVSOutputParamsNoFog;
+    
+    vout.TexCoord = vin.TexCoord;
+
+    return vout;
+}
+
+
+// Vertex shader: vertex color.
+VSOutputTx VSTilemapVcFog(VSInputTxVc vin)
+{
+    VSOutputTx vout;
+    
+    CommonVSOutput cout = ComputeCommonVSOutput(vin.Position);
+    SetCommonVSOutputParams;
+    
+    vout.TexCoord = vin.TexCoord;
+    vout.Diffuse *= vin.Color;
+    
+    return vout;
+}
+
+
+// Vertex shader: vertex color, no fog.
+VSOutputTxNoFog VSTilemapVc(VSInputTxVc vin)
+{
+    VSOutputTxNoFog vout;
+    
+    CommonVSOutput cout = ComputeCommonVSOutput(vin.Position);
+    SetCommonVSOutputParamsNoFog;
+    
+    vout.TexCoord = vin.TexCoord;
+    vout.Diffuse *= vin.Color;
+    
+    return vout;
+}
+
+
+// Pixel shader: basic.
+float4 PSTilemapFog(VSOutputTx pin) : SV_Target0
+{
+    float2 txCoord = pin.TexCoord * MapSize;
+    float2 txCoordi = floor(txCoord);
+    float2 tx2Coord = (txCoord - txCoordi);
+
+    float4 mapColor = SAMPLE_TEXTURE(Texture, txCoordi/MapSize);
+    float2 tileCoord = mapColor.xy * 255;
+    float alpha = mapColor.a;
+	
+    tx2Coord = (tx2Coord + tileCoord) * InvAtlasSize;
+
+    float4 color = SAMPLE_TEXTURE(TextureAtlas, tx2Coord);
+    color *= alpha;
+    color *= pin.Diffuse;
+    
+    ApplyFog(color, pin.Specular.w);
+    
+    return color;
+}
+
+
+// Pixel shader: no fog.
+float4 PSTilemap(VSOutputTxNoFog pin) : SV_Target0
+{
+    float2 txCoord = pin.TexCoord * MapSize;
+    float2 txCoordi = floor(txCoord);
+    float2 tx2Coord = (txCoord - txCoordi);
+
+    float4 mapColor = SAMPLE_TEXTURE(Texture, txCoordi/MapSize);
+	float2 tileCoord = mapColor.xy * 255;
+	float alpha = mapColor.a;
+	
+    tx2Coord = (tx2Coord + tileCoord) * InvAtlasSize;
+
+    float4 color = SAMPLE_TEXTURE(TextureAtlas, tx2Coord);
+	color *= alpha;
+    color *= pin.Diffuse;
+
+    return color;
+}
+
+
+// NOTE: The order of the techniques here are
+// defined to match the indexing in DualTextureEffect.cs.
+
+TECHNIQUE( TilemapEffectFog,             VSTilemapFog,   PSTilemapFog );
+TECHNIQUE( TilemapEffect,                VSTilemap,      PSTilemap );
+TECHNIQUE( TilemapEffect_VertexColorFog, VSTilemapVcFog, PSTilemapFog );
+TECHNIQUE( TilemapEffect_VertexColor,    VSTilemapVc,    PSTilemap );

+ 489 - 0
Shaders/Tilemap/TilemapEffect.cs

@@ -0,0 +1,489 @@
+#region License
+//   Copyright 2019-2021 Kastellanos Nikolaos
+//
+//   Licensed under the Apache License, Version 2.0 (the "License");
+//   you may not use this file except in compliance with the License.
+//   You may obtain a copy of the License at
+//
+//       http://www.apache.org/licenses/LICENSE-2.0
+//
+//   Unless required by applicable law or agreed to in writing, software
+//   distributed under the License is distributed on an "AS IS" BASIS,
+//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//   See the License for the specific language governing permissions and
+//   limitations under the License.
+#endregion
+
+using System;
+using System.IO;
+using System.Reflection;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace tainicom.Aether.Shaders
+{
+    public class TilemapEffect : Effect, IEffectMatrices
+    {
+        #region Effect Parameters
+        
+        EffectParameter textureParam;
+        EffectParameter textureAtlasParam;
+
+        EffectParameter mapSizeParam;
+        EffectParameter invAtlasSizeParam;
+        
+        EffectParameter diffuseColorParam;
+        EffectParameter fogColorParam;
+        EffectParameter fogVectorParam;
+
+        // IEffectMatrices
+        EffectParameter worldViewProjParam;
+
+        #endregion
+
+        #region Fields
+        
+        bool fogEnabled;
+        bool vertexColorEnabled;
+
+        Matrix world = Matrix.Identity;
+        Matrix view = Matrix.Identity;
+        Matrix projection = Matrix.Identity;
+
+        Matrix worldView;
+
+        Vector3 diffuseColor = Vector3.One;
+
+        float alpha = 1;
+
+        float fogStart = 0;
+        float fogEnd = 1;
+                
+        Vector2 atlasSize;
+
+        EffectDirtyFlags dirtyFlags = EffectDirtyFlags.All;
+
+#if ((MG && WINDOWS) || W8_1 || W10)
+        static readonly String resourceName = "tainicom.Aether.Shaders.Resources.TilemapEffect.dx11.mgfxo";
+#else
+        static readonly String resourceName = "tainicom.Aether.Shaders.Resources.TilemapEffect.xna.WinReach";
+#endif
+
+        internal static byte[] LoadEffectResource(string name)
+        {
+            using (var stream = LoadEffectResourceStream(name))
+            using (var ms = new MemoryStream())
+            {
+                stream.CopyTo(ms);
+                return ms.ToArray();
+            }
+        }
+
+        internal static Stream LoadEffectResourceStream(string name)
+        {
+            // Detect MG version
+            var version = "";
+#if !XNA && !PORTABLE
+            version = ".9";
+            var mgVersion = GetAssembly(typeof(Effect)).GetName().Version;
+            if (mgVersion.Major == 3)
+            {
+                if (mgVersion.Minor == 4)
+                    version = ".6";
+                if (mgVersion.Minor == 5)
+                    version = ".7";
+                if (mgVersion.Minor == 6)
+                    version = ".8";
+                if (mgVersion.Minor == 7)
+                    version = ".8";
+                if (mgVersion.Minor == 8)
+                    version = ".9";
+            }
+            name = name + version;
+#endif
+
+            Stream stream = GetAssembly(typeof(TilemapEffect)).GetManifestResourceStream(name);
+            return stream;
+        }
+
+        private static Assembly GetAssembly(Type type)
+        {            
+            #if W8_1 || W10 
+            return type.GetTypeInfo().Assembly;
+            #else
+            return type.Assembly;
+            #endif
+        }
+
+        #endregion
+        
+        #region Public Properties
+
+        public Matrix Projection
+        {
+            get { return projection; }
+            set
+            {
+                projection = value;
+                dirtyFlags |= EffectDirtyFlags.WorldViewProj;
+            }
+        }
+
+        public Matrix View
+        {
+            get { return view; }
+            set
+            {
+                view = value;
+                dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.Fog;
+            }
+        }
+
+        public Matrix World
+        {
+            get { return world; }
+            set
+            {
+                world = value;
+                dirtyFlags |= EffectDirtyFlags.WorldViewProj | EffectDirtyFlags.Fog;
+            }
+        }
+                
+        /// <summary>
+        /// Gets or sets the Tilemap texture.
+        /// </summary>
+        public Texture2D Texture
+        {
+            get { return textureParam.GetValueTexture2D(); }
+            set { textureParam.SetValue(value); }
+        }
+
+
+        /// <summary>
+        /// Gets or sets the Atlas texture.
+        /// </summary>
+        public Texture2D TextureAtlas
+        {
+            get { return textureAtlasParam.GetValueTexture2D(); }
+            set { textureAtlasParam.SetValue(value); }
+        }
+
+
+        /// <summary>
+        /// Gets or sets the Map size.
+        /// </summary>
+        public Vector2 MapSize
+        {
+            get { return mapSizeParam.GetValueVector2(); }
+            set { mapSizeParam.SetValue(value); }
+        }
+
+        /// <summary>
+        /// Gets or sets the Atlas size.
+        /// </summary>
+        public Vector2 AtlasSize
+        {
+            get { return atlasSize; }
+            set 
+            { 
+                atlasSize = value;
+                value.X = 1f/value.X;
+                value.Y = 1f/value.Y;
+                invAtlasSizeParam.SetValue(value);
+            }
+        }
+
+        /// <summary>
+        /// Gets or sets the material diffuse color (range 0 to 1).
+        /// </summary>
+        public Vector3 DiffuseColor
+        {
+            get { return diffuseColor; }
+
+            set
+            {
+                diffuseColor = value;
+                dirtyFlags |= EffectDirtyFlags.MaterialColor;
+            }
+        }
+
+
+        /// <summary>
+        /// Gets or sets the material alpha.
+        /// </summary>
+        public float Alpha
+        {
+            get { return alpha; }
+
+            set
+            {
+                alpha = value;
+                dirtyFlags |= EffectDirtyFlags.MaterialColor;
+            }
+        }
+
+
+        /// <summary>
+        /// Gets or sets the fog enable flag.
+        /// </summary>
+        public bool FogEnabled
+        {
+            get { return fogEnabled; }
+
+            set
+            {
+                if (fogEnabled != value)
+                {
+                    fogEnabled = value;
+                    dirtyFlags |= EffectDirtyFlags.ShaderIndex | EffectDirtyFlags.FogEnable;
+                }
+            }
+        }
+
+
+        /// <summary>
+        /// Gets or sets the fog start distance.
+        /// </summary>
+        public float FogStart
+        {
+            get { return fogStart; }
+
+            set
+            {
+                fogStart = value;
+                dirtyFlags |= EffectDirtyFlags.Fog;
+            }
+        }
+
+
+        /// <summary>
+        /// Gets or sets the fog end distance.
+        /// </summary>
+        public float FogEnd
+        {
+            get { return fogEnd; }
+
+            set
+            {
+                fogEnd = value;
+                dirtyFlags |= EffectDirtyFlags.Fog;
+            }
+        }
+
+
+        /// <summary>
+        /// Gets or sets the fog color.
+        /// </summary>
+        public Vector3 FogColor
+        {
+            get { return fogColorParam.GetValueVector3(); }
+            set { fogColorParam.SetValue(value); }
+        }
+
+
+        /// <summary>
+        /// Gets or sets whether vertex color is enabled.
+        /// </summary>
+        public bool VertexColorEnabled
+        {
+            get { return vertexColorEnabled; }
+
+            set
+            {
+                if (vertexColorEnabled != value)
+                {
+                    vertexColorEnabled = value;
+                    dirtyFlags |= EffectDirtyFlags.ShaderIndex;
+                }
+            }
+        }
+
+        #endregion
+
+        #region Methods
+
+         public TilemapEffect(GraphicsDevice graphicsDevice)
+            : base(graphicsDevice, 
+#if NETFX_CORE || WP8
+            LoadEffectResourceStream(resourceName), true
+#else
+            LoadEffectResource(resourceName)
+#endif
+           )
+        {    
+            CacheEffectParameters(null);
+        }
+
+        public TilemapEffect(GraphicsDevice graphicsDevice, byte[] Bytecode): base(graphicsDevice, Bytecode)
+        {   
+            CacheEffectParameters(null);
+        }
+
+        protected TilemapEffect(TilemapEffect cloneSource)
+            : base(cloneSource)
+        {
+            CacheEffectParameters(cloneSource);
+            
+            fogEnabled = cloneSource.fogEnabled;
+            vertexColorEnabled = cloneSource.vertexColorEnabled;
+
+            world = cloneSource.world;
+            view = cloneSource.view;
+            projection = cloneSource.projection;
+
+            diffuseColor = cloneSource.diffuseColor;
+
+            alpha = cloneSource.alpha;
+
+            fogStart = cloneSource.fogStart;
+            fogEnd = cloneSource.fogEnd;
+
+            atlasSize = cloneSource.atlasSize;
+        }
+        
+        public override Effect Clone()
+        {
+            return new TilemapEffect(this);
+        }
+
+        void CacheEffectParameters(TilemapEffect cloneSource)
+        {   
+            textureParam = Parameters["Texture"];
+            textureAtlasParam = Parameters["TextureAtlas"];
+            mapSizeParam = Parameters["MapSize"];
+            invAtlasSizeParam = Parameters["InvAtlasSize"];
+            diffuseColorParam = Parameters["DiffuseColor"];
+            fogColorParam = Parameters["FogColor"];
+            fogVectorParam = Parameters["FogVector"];
+            // IEffectMatrices
+            worldViewProjParam = Parameters["WorldViewProj"];
+        }
+
+
+        /// <summary>
+        /// Lazily computes derived parameter values immediately before applying the effect.
+        /// </summary>
+        protected override void OnApply()
+        {
+            // Recompute the world+view+projection matrix or fog vector?
+            dirtyFlags = SetWorldViewProjAndFog(dirtyFlags, ref world, ref view, ref projection, ref worldView, fogEnabled, fogStart, fogEnd, worldViewProjParam, fogVectorParam);
+
+            // Recompute the diffuse/alpha material color parameter?
+            if ((dirtyFlags & EffectDirtyFlags.MaterialColor) != 0)
+            {
+                diffuseColorParam.SetValue(new Vector4(diffuseColor * alpha, alpha));
+
+                dirtyFlags &= ~EffectDirtyFlags.MaterialColor;
+            }
+
+            // Recompute the shader index?
+            if ((dirtyFlags & EffectDirtyFlags.ShaderIndex) != 0)
+            {
+                int shaderIndex = 0;
+
+                if (!fogEnabled)
+                    shaderIndex += 1;
+
+                if (vertexColorEnabled)
+                    shaderIndex += 2;
+
+                dirtyFlags &= ~EffectDirtyFlags.ShaderIndex;
+
+                CurrentTechnique = Techniques[shaderIndex];
+            }
+        }
+
+
+        /// <summary>
+        /// Lazily recomputes the world+view+projection matrix and
+        /// fog vector based on the current effect parameter settings.
+        /// </summary>
+        static EffectDirtyFlags SetWorldViewProjAndFog(EffectDirtyFlags dirtyFlags,
+                                                                ref Matrix world, ref Matrix view, ref Matrix projection, ref Matrix worldView,
+                                                                bool fogEnabled, float fogStart, float fogEnd,
+                                                                EffectParameter worldViewProjParam, EffectParameter fogVectorParam)
+        {
+            // Recompute the world+view+projection matrix?
+            if ((dirtyFlags & EffectDirtyFlags.WorldViewProj) != 0)
+            {
+                Matrix worldViewProj;
+
+                Matrix.Multiply(ref world, ref view, out worldView);
+                Matrix.Multiply(ref worldView, ref projection, out worldViewProj);
+
+                worldViewProjParam.SetValue(worldViewProj);
+
+                dirtyFlags &= ~EffectDirtyFlags.WorldViewProj;
+            }
+
+            if (fogEnabled)
+            {
+                // Recompute the fog vector?
+                if ((dirtyFlags & (EffectDirtyFlags.Fog | EffectDirtyFlags.FogEnable)) != 0)
+                {
+                    SetFogVector(ref worldView, fogStart, fogEnd, fogVectorParam);
+
+                    dirtyFlags &= ~(EffectDirtyFlags.Fog | EffectDirtyFlags.FogEnable);
+                }
+            }
+            else
+            {
+                // When fog is disabled, make sure the fog vector is reset to zero.
+                if ((dirtyFlags & EffectDirtyFlags.FogEnable) != 0)
+                {
+                    fogVectorParam.SetValue(Vector4.Zero);
+
+                    dirtyFlags &= ~EffectDirtyFlags.FogEnable;
+                }
+            }
+
+            return dirtyFlags;
+        }
+        
+        /// <summary>
+        /// Sets a vector which can be dotted with the object space vertex position to compute fog amount.
+        /// </summary>
+        static void SetFogVector(ref Matrix worldView, float fogStart, float fogEnd, EffectParameter fogVectorParam)
+        {
+            if (fogStart == fogEnd)
+            {
+                // Degenerate case: force everything to 100% fogged if start and end are the same.
+                fogVectorParam.SetValue(new Vector4(0, 0, 0, 1));
+            }
+            else
+            {
+                // We want to transform vertex positions into view space, take the resulting
+                // Z value, then scale and offset according to the fog start/end distances.
+                // Because we only care about the Z component, the shader can do all this
+                // with a single dot product, using only the Z row of the world+view matrix.
+
+                float scale = 1f / (fogStart - fogEnd);
+
+                Vector4 fogVector = new Vector4();
+
+                fogVector.X = worldView.M13 * scale;
+                fogVector.Y = worldView.M23 * scale;
+                fogVector.Z = worldView.M33 * scale;
+                fogVector.W = (worldView.M43 + fogStart) * scale;
+
+                fogVectorParam.SetValue(fogVector);
+            }
+        }
+        
+        #endregion
+
+
+        enum EffectDirtyFlags
+        {
+            WorldViewProj = 1,
+            //World = 2,
+            //EyePosition = 4,
+            MaterialColor = 8,
+            Fog = 16,
+            FogEnable = 32,
+            //AlphaTest = 64,
+            ShaderIndex = 128,
+            All = -1
+        }
+    }
+}