Updated Krypton

This commit is contained in:
Simon Holmberg
2012-09-30 11:17:59 +02:00
parent 7bcbe94e5f
commit 93466568f4
28 changed files with 3377 additions and 287 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

+313
View File
@@ -0,0 +1,313 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Krypton;
using Krypton.Lights;
namespace KryptonTestbed
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class KryptonDemoGame : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
KryptonEngine krypton;
private Texture2D mLightTexture;
private int mNumLights = 25;
private int mNumHorzontalHulls = 20;
private int mNumVerticalHulls = 20;
private float mVerticalUnits = 50;
private Light2D mLight2D;
Random mRandom = new Random();
public KryptonDemoGame()
{
// Setup the graphics device manager with some default settings
this.graphics = new GraphicsDeviceManager(this);
this.graphics.PreferredBackBufferWidth = 1280;
this.graphics.PreferredBackBufferHeight = 720;
// Allow the window to be resized (to demonstrate render target recreation)
this.Window.AllowUserResizing = true;
// Setup the content manager with some default settings
this.Content.RootDirectory = "Content";
// Create Krypton
this.krypton = new KryptonEngine(this, "KryptonEffect");
// As a side note, you may want Krypton to be used as a GameComponent.
// To do this, you would simply add the following line of code and remove the Initialize and Draw function of krypton below:
// this.Components.Add(this.krypton);
}
protected override void Initialize()
{
// Make sure to initialize krpyton, unless it has been added to the Game's list of Components
this.krypton.Initialize();
base.Initialize();
}
protected override void LoadContent()
{
// Create a new simple point light texture to use for the lights
this.mLightTexture = LightTextureBuilder.CreatePointLight(this.GraphicsDevice, 512);
// Create some lights and hulls
this.CreateLights(mLightTexture, this.mNumLights);
this.CreateHulls(this.mNumHorzontalHulls, this.mNumVerticalHulls);
// Create a light we can control
this.mLight2D = new Light2D()
{
Texture = this.mLightTexture,
X = 0,
Y = 0,
Range = 25,
Color = Color.Multiply(Color.CornflowerBlue, 2.0f),
ShadowType = ShadowType.Occluded
};
this.krypton.Lights.Add(this.mLight2D);
}
private void CreateLights(Texture2D texture, int count)
{
// Make some random lights!
for (int i = 0; i < count; i++)
{
byte r = (byte)(this.mRandom.Next(255 - 64) + 64);
byte g = (byte)(this.mRandom.Next(255 - 64) + 64);
byte b = (byte)(this.mRandom.Next(255 - 64) + 64);
Light2D light = new Light2D()
{
Texture = texture,
Range = (float)(this.mRandom.NextDouble() * 5 + 5),
Color = new Color(r,g,b),
//Intensity = (float)(this.mRandom.NextDouble() * 0.25 + 0.75),
Intensity = 1f,
Angle = MathHelper.TwoPi * (float)this.mRandom.NextDouble(),
X = (float)(this.mRandom.NextDouble() * 50 - 25),
Y = (float)(this.mRandom.NextDouble() * 50 - 25),
};
// Here we set the light's field of view
if (i % 2 == 0)
{
light.Fov = MathHelper.PiOver2 * (float)(this.mRandom.NextDouble() * 0.75 + 0.25);
}
this.krypton.Lights.Add(light);
}
}
private void CreateHulls(int x, int y)
{
float w = 50;
float h = 50;
// Make lines of lines of hulls!
for (int j = 0; j < y; j++)
{
// Make lines of hulls!
for (int i = 0; i < x; i++)
{
var posX = (((i + 0.5f) * w) / x) - w / 2 + (j % 2 == 0 ? w / x / 2 : 0);
var posY = (((j + 0.5f) * h) / y) - h / 2; // +(i % 2 == 0 ? h / y / 4 : 0);
var hull = ShadowHull.CreateRectangle(Vector2.One*1f);
hull.Position.X = posX;
hull.Position.Y = posY;
hull.Scale.X = (float)(this.mRandom.NextDouble() * 0.75f + 0.25f);
hull.Scale.Y = (float)(this.mRandom.NextDouble() * 0.75f + 0.25f);
krypton.Hulls.Add(hull);
}
}
}
protected override void UnloadContent()
{
// Not sure if anything actually NEEDS to go here, as the game exits immediately upon unloading content. Please advise if you think this is bad :)
}
protected override void Update(GameTime gameTime)
{
// Make sure the user doesn't want to quit (but why would they?)
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape))
this.Exit();
// make it much simpler to deal with the time :)
var t = (float)gameTime.ElapsedGameTime.TotalSeconds;
var speed = 5;
// Allow for randomization of lights and hulls, to demonstrait that each hull and light is individually rendered
if (Keyboard.GetState().IsKeyDown(Keys.R))
{
// randomize lights
foreach (Light2D light in this.krypton.Lights)
{
light.Position += Vector2.UnitY * (float)(this.mRandom.NextDouble() * 2 - 1) * t * speed;
light.Position += Vector2.UnitX * (float)(this.mRandom.NextDouble() * 2 - 1) * t * speed;
light.Angle -= MathHelper.TwoPi * (float)(this.mRandom.NextDouble() * 2 - 1) * t * speed;
}
// randomize hulls
foreach (var hull in this.krypton.Hulls)
{
hull.Position += Vector2.UnitY * (float)(this.mRandom.NextDouble() * 2 - 1) * t * speed;
hull.Position += Vector2.UnitX * (float)(this.mRandom.NextDouble() * 2 - 1) * t * speed;
hull.Angle -= MathHelper.TwoPi * (float)(this.mRandom.NextDouble() * 2 - 1) * t * speed;
}
}
var keyboard = Keyboard.GetState();
// Light Position Controls
if (keyboard.IsKeyDown(Keys.Up))
this.mLight2D.Y += t * speed;
if (keyboard.IsKeyDown(Keys.Down))
this.mLight2D.Y -= t * speed;
if (keyboard.IsKeyDown(Keys.Right))
this.mLight2D.X += t * speed;
if (keyboard.IsKeyDown(Keys.Left))
this.mLight2D.X -= t * speed;
// Shadow Type Controls
if (keyboard.IsKeyDown(Keys.D1))
this.mLight2D.ShadowType = ShadowType.Solid;
if (keyboard.IsKeyDown(Keys.D2))
this.mLight2D.ShadowType = ShadowType.Illuminated;
if (keyboard.IsKeyDown(Keys.D3))
this.mLight2D.ShadowType = ShadowType.Occluded;
// Shadow Opacity Controls
if (keyboard.IsKeyDown(Keys.O))
this.krypton.Hulls.ForEach(x => x.Opacity = MathHelper.Clamp(x.Opacity - t, 0, 1));
if (keyboard.IsKeyDown(Keys.P))
this.krypton.Hulls.ForEach(x => x.Opacity = MathHelper.Clamp(x.Opacity + t, 0, 1));
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
// Create a world view projection matrix to use with krypton
Matrix world = Matrix.Identity;
Matrix view = Matrix.CreateTranslation(new Vector3(0, 0, 0) * -1f);
Matrix projection = Matrix.CreateOrthographic(this.mVerticalUnits * this.GraphicsDevice.Viewport.AspectRatio, this.mVerticalUnits, 0, 1);
Matrix wvp = world * view * projection;
// Assign the matrix and pre-render the lightmap.
// Make sure not to change the position of any lights or shadow hulls after this call, as it won't take effect till the next frame!
this.krypton.Matrix = wvp;
this.krypton.LightMapPrepare();
// Make sure we clear the backbuffer *after* Krypton is done pre-rendering
this.GraphicsDevice.Clear(Color.White);
// ----- DRAW STUFF HERE ----- //
// By drawing here, you ensure that your scene is properly lit by krypton.
// Drawing after KryptonEngine.Draw will cause you objects to be drawn on top of the lightmap (can be useful, fyi)
// ----- DRAW STUFF HERE ----- //
// Draw hulls
this.DebugDrawHulls(true);
// Draw krypton (This can be omited if krypton is in the Component list. It will simply draw krypton when base.Draw is called
this.krypton.Draw(gameTime);
if (Keyboard.GetState().IsKeyDown(Keys.H))
{
// Draw hulls
this.DebugDrawHulls(false);
}
if (Keyboard.GetState().IsKeyDown(Keys.L))
{
// Draw hulls
this.DebugDrawLights();
}
base.Draw(gameTime);
}
private void DebugDrawHulls(bool drawSolid)
{
this.krypton.RenderHelper.Effect.CurrentTechnique = this.krypton.RenderHelper.Effect.Techniques["DebugDraw"];
this.GraphicsDevice.RasterizerState = new RasterizerState()
{
CullMode = CullMode.None,
FillMode = drawSolid ? FillMode.Solid : FillMode.WireFrame,
};
// Clear the helpers vertices
this.krypton.RenderHelper.ShadowHullVertices.Clear();
this.krypton.RenderHelper.ShadowHullIndicies.Clear();
foreach (var hull in krypton.Hulls)
{
this.krypton.RenderHelper.BufferAddShadowHull(hull);
}
foreach (var effectPass in krypton.RenderHelper.Effect.CurrentTechnique.Passes)
{
effectPass.Apply();
this.krypton.RenderHelper.BufferDraw();
}
}
private void DebugDrawLights()
{
this.krypton.RenderHelper.Effect.CurrentTechnique = this.krypton.RenderHelper.Effect.Techniques["DebugDraw"];
this.GraphicsDevice.RasterizerState = new RasterizerState()
{
CullMode = CullMode.None,
FillMode = FillMode.WireFrame,
};
// Clear the helpers vertices
this.krypton.RenderHelper.ShadowHullVertices.Clear();
this.krypton.RenderHelper.ShadowHullIndicies.Clear();
foreach (Light2D light in krypton.Lights)
{
this.krypton.RenderHelper.BufferAddBoundOutline(light.Bounds);
}
foreach (var effectPass in krypton.RenderHelper.Effect.CurrentTechnique.Passes)
{
effectPass.Apply();
this.krypton.RenderHelper.BufferDraw();
}
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

+149
View File
@@ -0,0 +1,149 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{E9787BEE-7290-4C74-B919-79DC70AABE87}</ProjectGuid>
<ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KryptonTestbed</RootNamespace>
<AssemblyName>KryptonTestbed</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
<XnaPlatform>Windows</XnaPlatform>
<XnaProfile>HiDef</XnaProfile>
<XnaCrossPlatformGroupID>04e8736f-6d19-442f-95e4-08f9b783d054</XnaCrossPlatformGroupID>
<XnaOutputType>Game</XnaOutputType>
<ApplicationIcon>Game.ico</ApplicationIcon>
<Thumbnail>GameThumbnail.png</Thumbnail>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\x86\Debug</OutputPath>
<DefineConstants>DEBUG;TRACE;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>false</XnaCompressContent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\x86\Release</OutputPath>
<DefineConstants>TRACE;WINDOWS</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
<UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>x86</PlatformTarget>
<XnaCompressContent>true</XnaCompressContent>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Avatar, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Xna.Framework.Game, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.GamerServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Xna.Framework.Graphics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Input.Touch, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Xna.Framework.Net, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Xna.Framework.Storage, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Xna.Framework.Video, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Xna.Framework.Xact, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="mscorlib">
<Private>False</Private>
</Reference>
<Reference Include="System">
<Private>False</Private>
</Reference>
<Reference Include="System.Xml">
<Private>False</Private>
</Reference>
<Reference Include="System.Core">
<Private>False</Private>
</Reference>
<Reference Include="System.Xml.Linq">
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Program.cs" />
<Compile Include="GameKryptonDemo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Game.ico" />
<Content Include="GameThumbnail.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Krypton\Krypton.csproj">
<Project>{B1BFCB2A-C001-4DAC-BA7D-B68BF28757F3}</Project>
<Name>Krypton</Name>
</ProjectReference>
<ProjectReference Include="..\KryptonTestbedContent\KryptonTestbedContent.contentproj">
<Name>KryptonTestbedContent</Name>
<XnaReferenceType>Content</XnaReferenceType>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.0,Profile=Client">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4 Client Profile %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Xna.Framework.4.0">
<Visible>False</Visible>
<ProductName>Microsoft XNA Framework Redistributable 4.0</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\Microsoft.Xna.GameStudio.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>
+21
View File
@@ -0,0 +1,21 @@
using System;
namespace KryptonTestbed
{
#if WINDOWS || XBOX
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
using (KryptonDemoGame game = new KryptonDemoGame())
{
game.Run();
}
}
}
#endif
}
@@ -0,0 +1,34 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("KryptonTestbed")]
[assembly: AssemblyProduct("KryptonTestbed")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
[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("44537967-0d21-441c-bf8b-9c788e77ff51")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
@@ -0,0 +1,438 @@
// ------------------------------------------------------------------------------------------------ //
// ----- Copyright 2011 Christopher Harris --------------------- http://krypton.codeplex.com/ ----- //
// ----------------------------------------------------------------- mailto:xixonia@gmail.com ----- //
// ------------------------------------------------------------------------------------------------ //
// ------------------------------------------------------------------------------------------------ //
// ----- Parameters ------------------------------------------------------------------------------- //
float4x4 Matrix;
texture Texture0;
texture Texture1;
float2 LightPosition;
float LightIntensityFactor = 1;
float ShadowStrech = 1000000;
float2 TexelBias;
float4 AmbientColor;
float Bluriness = 0.5f;
float BlurFactorU = 0;
float BlurFactorV = 0;
// ------------------------------------------------------------------------------------------------ //
// ----- Samplers --------------------------------------------------------------------------------- //
sampler2D tex0 = sampler_state
{
Texture = <Texture0>;
AddressU = Clamp;
AddressV = Clamp;
};
sampler2D tex1 = sampler_state
{
Texture = <Texture1>;
AddressU = Clamp;
AddressV = Clamp;
};
// ------------------------------------------------------------------------------------------------ //
// ----- Structures ------------------------------------------------------------------------------- //
struct ShadowHullVertex
{
float4 Position : POSITION0;
float2 Normal : NORMAL0;
float4 Color : COLOR0;
};
struct VertexPositionColor
{
float4 Position : POSITION0;
float4 Color : COLOR0;
};
struct VertexPositionColorTexture
{
float4 Position : POSITION0;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
};
struct VertexPositionTexture
{
float4 Position : POSITION0;
float2 TexCoord : TEXCOORD0;
};
struct Color2
{
float4 Color0 : COLOR0;
float4 Color1 : COLOR1;
};
// ------------------------------------------------------------------------------------------------ //
// ----- Vertex Shaders --------------------------------------------------------------------------- //
VertexPositionTexture VS_TextureNoTransform(VertexPositionTexture input)
{
return input;
};
VertexPositionColorTexture VS_ColorTexture(VertexPositionColorTexture input)
{
input.Position = mul(input.Position, Matrix);
return input;
};
VertexPositionColor VS_Hull(ShadowHullVertex input)
{
VertexPositionColor output;
output.Position = mul(input.Position, Matrix);
output.Color = input.Color;
return output;
};
VertexPositionColor VS_Hull_RadialStretch(ShadowHullVertex input)
{
float2 direction = normalize(LightPosition.xy - input.Position.xy);
if(dot(input.Normal.xy, direction) < 0)
{
// Stretch backfacing vertices
input.Position.xy -= direction * ShadowStrech;
}
VertexPositionColor output;
output.Position = mul(input.Position, Matrix);
output.Color = input.Color;
return output;
};
// ------------------------------------------------------------------------------------------------ //
// ----- Pixel Shaders ---------------------------------------------------------------------------- //
// ------------------------------------------------------------------------------------------------ //
// ----- Techniques ------------------------------------------------------------------------------- //
float4 PS_Texture(in float2 texCoord : TEXCOORD0) : COLOR0
{
return tex2D(tex0, texCoord + TexelBias);
};
float4 PS_ColorTexture(in float4 color : COLOR0, in float2 texCoord : TEXCOORD0) : COLOR0
{
return tex2D(tex0, texCoord) * color;
};
float4 PS_LightTexture(VertexPositionColorTexture input) : COLOR0
{
return pow(abs(tex2D(tex0, input.TexCoord)) * input.Color, LightIntensityFactor);
};
float4 PS_Color(in float4 color : COLOR0) : COLOR0
{
return color;
};
float4 PS_White() : COLOR0
{
return float4(1, 1, 1, 1);
};
float4 PS_Black() : COLOR0
{
return float4(0, 0, 0, 1);
};
float4 PS_Debug() : COLOR0
{
return float4(1, 0, 0, 1);
};
float4 PS_BlurH(in float2 texCoord : TEXCOORD0) : COLOR0
{
float blurFactor = Bluriness * BlurFactorU / 4.0f;
return
tex2D(tex0, float2(texCoord.x - blurFactor * 4, texCoord.y) + TexelBias) * 0.05f +
tex2D(tex0, float2(texCoord.x - blurFactor * 3, texCoord.y) + TexelBias) * 0.09f +
tex2D(tex0, float2(texCoord.x - blurFactor * 2, texCoord.y) + TexelBias) * 0.12f +
tex2D(tex0, float2(texCoord.x - blurFactor, texCoord.y) + TexelBias) * 0.15f +
tex2D(tex0, float2(texCoord.x, texCoord.y) + TexelBias) * 0.18f +
tex2D(tex0, float2(texCoord.x + blurFactor, texCoord.y) + TexelBias) * 0.15f +
tex2D(tex0, float2(texCoord.x + blurFactor * 2, texCoord.y) + TexelBias) * 0.12f +
tex2D(tex0, float2(texCoord.x + blurFactor * 3, texCoord.y) + TexelBias) * 0.09f +
tex2D(tex0, float2(texCoord.x + blurFactor * 4, texCoord.y) + TexelBias) * 0.05f;
}
float4 PS_BlurV(in float2 texCoord : TEXCOORD0) : COLOR0
{
float blurFactor = Bluriness * BlurFactorV / 4.0f;
return
tex2D(tex0, float2(texCoord.x, texCoord.y - blurFactor * 4) + TexelBias) * 0.05f +
tex2D(tex0, float2(texCoord.x, texCoord.y - blurFactor * 3) + TexelBias) * 0.09f +
tex2D(tex0, float2(texCoord.x, texCoord.y - blurFactor * 2) + TexelBias) * 0.12f +
tex2D(tex0, float2(texCoord.x, texCoord.y - blurFactor) + TexelBias) * 0.15f +
tex2D(tex0, float2(texCoord.x, texCoord.y) + TexelBias) * 0.18f +
tex2D(tex0, float2(texCoord.x, texCoord.y + blurFactor) + TexelBias) * 0.15f +
tex2D(tex0, float2(texCoord.x, texCoord.y + blurFactor * 2) + TexelBias) * 0.12f +
tex2D(tex0, float2(texCoord.x, texCoord.y + blurFactor * 3) + TexelBias) * 0.09f +
tex2D(tex0, float2(texCoord.x, texCoord.y + blurFactor * 4) + TexelBias) * 0.05f;
}
// ------------------------------------------------------------------------------------------------
// ----- Technique: TextureToTarget ---------------------------------------------------------------
technique TextureToTarget_Add
{
pass Pass1
{
StencilEnable = False;
BlendOp = Add;
SrcBlend = One;
DestBlend = One;
AlphaBlendEnable = True;
CullMode = CCW;
VertexShader = compile vs_2_0 VS_TextureNoTransform();
PixelShader = compile ps_2_0 PS_Texture();
}
};
technique TextureToTarget_Multiply
{
pass Pass1
{
StencilEnable = False;
BlendOp = Add;
SrcBlend = Zero;
DestBlend = SrcColor;
AlphaBlendEnable = True;
CullMode = CCW;
VertexShader = compile vs_2_0 VS_TextureNoTransform();
PixelShader = compile ps_2_0 PS_Texture();
}
};
technique LightTexture
{
pass Pass1
{
StencilEnable = False;
BlendOp = Add;
DestBlend = Zero;
SrcBlend = SrcAlpha;
AlphaBlendEnable = True;
VertexShader = compile vs_2_0 VS_ColorTexture();
PixelShader = compile ps_2_0 PS_LightTexture();
}
};
// ------------------------------------------------------------------------------------------------
// ----- Technique: PointLight_Shadow -------------------------------------------------------------
technique PointLight_Shadow_Solid
{
pass Shadow
{
StencilEnable = False;
ScissorTestEnable = True;
AlphaBlendEnable = True;
BlendOp = Add;
SrcBlend = DestColor;
DestBlend = Zero;
ColorWriteEnable = Alpha;
VertexShader = compile vs_2_0 VS_Hull_RadialStretch();
PixelShader = compile ps_2_0 PS_Color();
}
};
technique PointLight_Shadow_Illuminated
{
pass Shadow
{
StencilEnable = False;
ScissorTestEnable = True;
AlphaBlendEnable = True;
BlendOp = Add;
SrcBlend = DestAlpha;
DestBlend = Zero;
ColorWriteEnable = Alpha;
VertexShader = compile vs_2_0 VS_Hull_RadialStretch();
PixelShader = compile ps_2_0 PS_Color();
}
pass Hull
{
StencilEnable = False;
ScissorTestEnable = True;
AlphaBlendEnable = True;
BlendOp = Add;
SrcBlend = One;
DestBlend = Zero;
ColorWriteEnable = Alpha;
VertexShader = compile vs_2_0 VS_Hull();
PixelShader = compile ps_2_0 PS_White();
}
};
technique PointLight_Shadow_Occluded
{
pass Shadow
{
StencilEnable = True;
StencilFunc = Always;
StencilPass = IncrSat;
StencilFail = Keep;
ScissorTestEnable = True;
AlphaBlendEnable = True;
BlendOp = Add;
SrcBlend = DestAlpha;
DestBlend = Zero;
ColorWriteEnable = Alpha;
VertexShader = compile vs_2_0 VS_Hull_RadialStretch();
PixelShader = compile ps_2_0 PS_Color();
}
pass Hull
{
StencilEnable = True;
StencilFunc = Equal;
StencilRef = 1;
StencilPass = Keep;
ScissorTestEnable = True;
AlphaBlendEnable = True;
BlendOp = Add;
SrcBlend = One;
DestBlend = Zero;
ColorWriteEnable = Alpha;
VertexShader = compile vs_2_0 VS_Hull();
PixelShader = compile ps_2_0 PS_White();
}
};
technique PointLight_Light
{
pass Light
{
StencilEnable = False;
ScissorTestEnable = False;
AlphaBlendEnable = True;
BlendOp = Add;
SrcBlend = DestAlpha;
DestBlend = One;
ColorWriteEnable = Red | Green | Blue;
VertexShader = compile vs_2_0 VS_ColorTexture();
PixelShader = compile ps_2_0 PS_LightTexture();
}
};
technique ClearTarget_Alpha
{
pass Pass1
{
StencilEnable = False;
AlphaBlendEnable = True;
BlendOp = Add;
SrcBlend = One;
DestBlend = One;
ScissorTestEnable = True;
ColorWriteEnable = Red | Green | Blue | Alpha;
VertexShader = compile vs_2_0 VS_TextureNoTransform();
PixelShader = compile ps_2_0 PS_Black();
}
};
// ------------------------------------------------------------------------------------------------
// ----- Technique: Blur --------------------------------------------------------------------------
technique Blur
{
pass HorizontalBlur
{
ScissorTestEnable = False;
StencilEnable = False;
AlphaBlendEnable = False;
CullMode = CCW;
VertexShader = compile vs_2_0 VS_TextureNoTransform();
PixelShader = compile ps_2_0 PS_BlurH();
}
pass VerticalBlur
{
ScissorTestEnable = False;
StencilEnable = False;
AlphaBlendEnable = False;
CullMode = CCW;
VertexShader = compile vs_2_0 VS_TextureNoTransform();
PixelShader = compile ps_2_0 PS_BlurV();
}
}
// ------------------------------------------------------------------------------------------------
// ----- Technique: DebugDraw ---------------------------------------------------------------------
technique DebugDraw
{
pass Solid
{
StencilEnable = False;
AlphaBlendEnable = False;
VertexShader = compile vs_2_0 VS_Hull();
PixelShader = compile ps_2_0 PS_Debug();
}
};
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<ProjectGuid>{EA878F1A-4714-4377-8E6A-4947ACFF386A}</ProjectGuid>
<ProjectTypeGuids>{96E2B04D-8817-42c6-938A-82C39BA4D311};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
<OutputPath>bin\$(Platform)\$(Configuration)</OutputPath>
<ContentRootDirectory>Content</ContentRootDirectory>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup>
<RootNamespace>KryptonTestbedContent</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="KryptonEffect.fx">
<Name>KryptonEffect</Name>
<Importer>EffectImporter</Importer>
<Processor>EffectProcessor</Processor>
</Compile>
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.AudioImporters, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.EffectImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=MSIL" />
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.FBXImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.TextureImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.VideoImporters, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
<Reference Include="Microsoft.Xna.Framework.Content.Pipeline.XImporter, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553, processorArchitecture=x86" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.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>