Unchanged:
Force REF:
Posted 19 April 2012 - 04:01 AM
Posted 19 April 2012 - 04:53 AM
Project page: < XNA FINAL Engine >
Posted 19 April 2012 - 07:56 PM
Project page: < XNA FINAL Engine >
Posted 19 April 2012 - 08:17 PM
colorRT = new RenderTarget2D(Engine.Game.GraphicsDevice, backbufferWidth, backbufferHeight, false, SurfaceFormat.Color, DepthFormat.Depth24); normalRT = new RenderTarget2D(Engine.Game.GraphicsDevice, backbufferWidth, backbufferHeight, false, SurfaceFormat.Color, DepthFormat.None); depthRT = new RenderTarget2D(Engine.Game.GraphicsDevice, backbufferWidth, backbufferHeight, false, SurfaceFormat.Single, DepthFormat.None); lightRT = new RenderTarget2D(Engine.Game.GraphicsDevice, backbufferWidth, backbufferHeight, false, SurfaceFormat.Color, DepthFormat.None); finalRT = new RenderTarget2D(Engine.Game.GraphicsDevice, backbufferWidth, backbufferHeight, false, SurfaceFormat.Color, DepthFormat.None);
output.Depth = output.Position.zw;and in the pixel shader I have
output.Depth = input.Depth.x / input.Depth.y
Posted 19 April 2012 - 08:32 PM
Project page: < XNA FINAL Engine >
Posted 19 April 2012 - 09:50 PM
Edited by Telanor, 29 April 2012 - 03:17 PM.
Posted 20 April 2012 - 06:27 AM
private static void Graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
{
Device.PresentationParameters.MultiSampleCount = 0;
}
Project page: < XNA FINAL Engine >
Posted 20 April 2012 - 04:20 PM
public Craft()
{
Game = this;
Graphics = new GraphicsDeviceManager(this)
{
PreferredBackBufferWidth = 1280,
PreferredBackBufferHeight = 720,
SynchronizeWithVerticalRetrace = false,
PreferMultiSampling = false,
IsFullScreen = false
};
Graphics.PreparingDeviceSettings += graphics_PreparingDeviceSettings;
Content.RootDirectory = "Content";
IsFixedTimeStep = false;
//this.Window.AllowUserResizing = true;
//this.IsMouseVisible = true;
}
void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
{
foreach(GraphicsAdapter adapter in GraphicsAdapter.Adapters)
{
if(adapter.Description.Contains("PerfHUD"))
{
e.GraphicsDeviceInformation.Adapter = adapter;
GraphicsAdapter.UseReferenceDevice = true; // this is the modified line from usage in previous xna version
break;
}
}
e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 0;
}
class DeferredRenderer
{
private void DrawLights()
{
Engine.Graphics.GraphicsDevice.SetRenderTarget(lightRT);
Engine.Graphics.GraphicsDevice.Clear(Color.Transparent);
Engine.Graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend;
Engine.Graphics.GraphicsDevice.DepthStencilState = DepthStencilState.None;
DirectionalLight.Draw();
PointLight.Draw();
Engine.Graphics.GraphicsDevice.BlendState = BlendState.Opaque;
Engine.Graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
Engine.Graphics.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
Engine.Graphics.GraphicsDevice.SetRenderTarget(null);
}
}
class DirectionalLight
{
private void DrawDirectionalLight()
{
directionalLightEffect.Parameters["ColorMap"].SetValue(DeferredRenderer.ColorRT);
directionalLightEffect.Parameters["NormalMap"].SetValue(DeferredRenderer.NormalRT);
directionalLightEffect.Parameters["DepthMap"].SetValue(DeferredRenderer.DepthRT);
directionalLightEffect.Parameters["LightDirection"].SetValue(LightDirection);
directionalLightEffect.Parameters["DiffuseLightColor"].SetValue(DiffuseColor);
directionalLightEffect.Parameters["AmbientLightColor"].SetValue(AmbientColor);
directionalLightEffect.Parameters["AmbientIntensity"].SetValue(AmbientIntensity);
directionalLightEffect.Parameters["DiffuseIntensity"].SetValue(DiffuseIntensity);
directionalLightEffect.Parameters["SpecularPower"].SetValue(SpecularPower);
directionalLightEffect.Parameters["SpecularIntensity"].SetValue(SpecularIntensity);
directionalLightEffect.Parameters["CameraPosition"].SetValue(Camera.Position);
directionalLightEffect.Parameters["InvertViewProjection"].SetValue(Matrix.Invert(Camera.View * Camera.Projection));
directionalLightEffect.Techniques[0].Passes[0].Apply();
DeferredRenderer.FullScreenQuad.Draw();
}
public static void Draw()
{
foreach(DirectionalLight light in lights)
{
light.DrawDirectionalLight();
}
}
}
Posted 20 April 2012 - 04:30 PM
Project page: < XNA FINAL Engine >
Posted 20 April 2012 - 06:05 PM
Posted 20 April 2012 - 06:26 PM
Posted 29 April 2012 - 12:05 AM
static readonly RasterizerState WireFramedRaster = new RasterizerState { CullMode = CullMode.None, FillMode = FillMode.WireFrame };
static readonly RasterizerState NormalRaster = new RasterizerState { CullMode = CullMode.CullCounterClockwiseFace, FillMode = FillMode.Solid };
...
Engine.Graphics.GraphicsDevice.RasterizerState = !wireFramed ? NormalRaster : WireFramedRaster;
Posted 29 April 2012 - 07:51 AM
Edited by jischneider, 29 April 2012 - 08:01 AM.
Project page: < XNA FINAL Engine >
Posted 05 May 2012 - 04:04 PM
//Used to compute the world-position
float4x4 InvertViewProjection;
//Position of the camera, for specular light
float3 CameraPosition;
//Light Properties
float3 LightDirection;
//Color Properties
float4 DiffuseLightColor;
float4 AmbientLightColor;
float AmbientIntensity;
float DiffuseIntensity;
//Specular Properties
float SpecularPower;
float SpecularIntensity;
//Textures
float2 HalfPixel;
// diffuse color, and specularIntensity in the alpha channel
texture ColorMap;
// normals, and specularPower in the alpha channel
texture NormalMap;
//depth
texture DepthMap;
sampler colorSampler = sampler_state
{
Texture = (ColorMap);
MagFilter = Linear;
MinFilter = Linear;
Mipfilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
sampler depthSampler = sampler_state
{
Texture = (DepthMap);
MagFilter = Point;
MinFilter = Point;
Mipfilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
sampler normalSampler = sampler_state
{
Texture = (NormalMap);
MagFilter = Point;
MinFilter = Point;
Mipfilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
struct VertexShaderInput
{
float3 Position : POSITION0;
float2 TexCoord : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : POSITION0;
float2 TexCoord : TEXCOORD0;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
output.Position = float4(input.Position, 1);
//align texture coordinates
output.TexCoord = input.TexCoord - HalfPixel;
return output;
}
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
//get normal data from the normalMap
float4 normalData = tex2D(normalSampler,input.TexCoord);
//tranform normal back into [-1,1] range
float3 normal = 2.0f * normalData.xyz - 1.0f;
//get specular power, and get it into [0,255] range]
float specularPower = saturate(normalData.a * SpecularPower) * 255;
//get specular intensity from the colorMap
float specularIntensity = saturate(tex2D(colorSampler, input.TexCoord).a * SpecularIntensity);
//read depth
float depthVal = tex2D(depthSampler,input.TexCoord).r;
//Only the skybox has a depth this high, so stop processing and return white
if(depthVal > 0.999f)
return float4(1, 1, 1, 0);
//compute screen-space position
float4 position;
position.x = input.TexCoord.x * 2.0f - 1.0f;
position.y = -(input.TexCoord.x * 2.0f - 1.0f);
position.z = depthVal;
position.w = 1.0f;
//transform to world space
position = mul(position, InvertViewProjection);
position /= position.w;
//surface-to-light vector
float3 lightVector = -normalize(LightDirection);
//compute diffuse light
float NdL = saturate(dot(normal, lightVector));
float4 diffuseLight = (NdL * DiffuseLightColor * DiffuseIntensity) + (AmbientLightColor * AmbientIntensity);
//reflexion vector
float3 reflectionVector = normalize(reflect(-lightVector, normal));
//camera-to-surface vector
float3 directionToCamera = normalize(CameraPosition - position);
float specularLight = specularIntensity * pow(saturate(dot(reflectionVector, directionToCamera)), specularPower);
return float4(diffuseLight.rgb, specularLight);
}
technique Technique0
{
pass Pass0
{
VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
Posted 05 May 2012 - 04:21 PM
Edited by jischneider, 05 May 2012 - 04:25 PM.
Project page: < XNA FINAL Engine >
Posted 05 May 2012 - 04:46 PM
//Used to compute the world-position
float4x4 InvertViewProjection;
//Position of the camera, for specular light
float3 CameraPosition;
//Light Properties
float3 LightDirection;
//Color Properties
float4 DiffuseLightColor;
float4 AmbientLightColor;
float AmbientIntensity;
float DiffuseIntensity;
//Specular Properties
float SpecularPower;
float SpecularIntensity;
//Textures
float2 HalfPixel;
// diffuse color, and specularIntensity in the alpha channel
texture ColorMap;
// normals, and specularPower in the alpha channel
texture NormalMap;
//depth
texture DepthMap;
sampler colorSampler = sampler_state
{
Texture = (ColorMap);
MagFilter = Linear;
MinFilter = Linear;
Mipfilter = Linear;
AddressU = Clamp;
AddressV = Clamp;
};
sampler depthSampler = sampler_state
{
Texture = (DepthMap);
MagFilter = Point;
MinFilter = Point;
Mipfilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
sampler normalSampler = sampler_state
{
Texture = (NormalMap);
MagFilter = Point;
MinFilter = Point;
Mipfilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
struct VertexShaderInput
{
float3 Position : POSITION0;
float2 TexCoord : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : POSITION0;
float2 TexCoord : TEXCOORD0;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
output.Position = float4(input.Position, 1);
output.Position.xy += HalfPixel;
output.TexCoord = input.TexCoord;
return output;
}
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
//get normal data from the normalMap
float4 normalData = tex2D(normalSampler,input.TexCoord);
//tranform normal back into [-1,1] range
float3 normal = 2.0f * normalData.xyz - 1.0f;
//get specular power, and get it into [0,255] range]
float specularPower = saturate(normalData.a * SpecularPower) * 255;
//get specular intensity from the colorMap
float specularIntensity = saturate(tex2D(colorSampler, input.TexCoord).a * SpecularIntensity);
//read depth
float depthVal = tex2D(depthSampler,input.TexCoord).r;
//Only the skybox has a depth this high, so stop processing and return white
if(depthVal > 0.999f)
return float4(1, 1, 1, 0);
//compute screen-space position
float4 position;
position.x = input.TexCoord.x * 2.0f - 1.0f;
position.y = -(input.TexCoord.y * 2.0f - 1.0f);
position.z = depthVal;
position.w = 1.0f;
//transform to world space
position = mul(position, InvertViewProjection);
position /= position.w;
//surface-to-light vector
float3 lightVector = -normalize(LightDirection);
//compute diffuse light
float NdL = saturate(dot(normal, lightVector));
float4 diffuseLight = (NdL * DiffuseLightColor * DiffuseIntensity) + (AmbientLightColor * AmbientIntensity);
//reflexion vector
float3 reflectionVector = normalize(reflect(-lightVector, normal));
//camera-to-surface vector
float3 directionToCamera = normalize(CameraPosition - position);
float specularLight = specularIntensity * pow(saturate(dot(reflectionVector, directionToCamera)), specularPower);
return float4(diffuseLight.rgb, specularLight);
}
technique Technique0
{
pass Pass0
{
VertexShader = compile vs_2_0 VertexShaderFunction();
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
Posted 05 May 2012 - 04:51 PM
Project page: < XNA FINAL Engine >