   TrueView Engine
This UFO was rendered using deferred technique. It uses a post process bloom effect to perform realism.As you can see, theres are two directional lighs: indian red and cyan colors.Model uses a standard phong material with following attributes:Specular intensity = 0.8fSpecular exponent = 40.0fReflection scale = 0.15fFresnel reflection scale = 0.01f Fresnel exponent = 0.9fBloom post process attributes:First pass:Threshold: 0.45fIntensity: 100.0fAlpha: 1.0fSecond pass:Threshold: 0.45fIntensity: 100.0fAlpha: 0.75fThis last pass has a blurred post process with 6.0f of blur amount and all passes are processed to render targets using BlendState.Additive.Click here to view the iotd
  wow, it's really shiny ;  hahaaha that's the key ;  good job... but rather put off by this statement.It uses a post process bloom effect to perform realism[/quote]Since it's an iotd about an engine... could you comment on the engine other than that it uses deferred rendering?;  Well.. first of all. Im new here This engine that I'm doing is kind of a Framework for my personal use at my job.That's why I can't put the whole thing  but let me try:It uses XNA 4.0 to interact with DirectX and has several clases to make my development traight formward and easy.For example this is the way how I implement this render with the framework.private void InitializeApplication() {_xna = new XNA(this.Width, this.Height, "Content", false);_world = new Space();_world.Models.Add(_xna.LoadModel("Models/UFO"));_world.Models.Add(_xna.LoadModel("Models/Wheel"));_world.Models.Add(_xna.LoadModel("Models/Cube"));_world.Models[0].Scale = 0.03f;_world.Models[0].Visible = true;_world.Models[1].Scale = 6.1f;_world.Models[1].Visible = false;_world.Models[2].Scale = 2.1f;_world.Models[2].Visible = false;_world.Models[0].Solids[4].Effect = new Plastic(_xna, XNAColor.DarkGreen, null, 0.05f);_world.Models[0].Solids[3].Effect = new Plastic(_xna, XNAColor.Yellow, null, 2.0f);_world.Models[0].Solids[5].Effect = new Plastic(_xna, XNAColor.IndianRed,  _xna.LoadEnvironment("Environments/Kitchen"), 2);_walk = new FirstPerson(_xna.Device, _world, this);_walk.UpdatePhysics += new Interop.UpdatePhysicsHandler(UpdatePhysics);_walk.Viewer.ProcessMainScene = false;_walk.Viewer.RenderMainScene = true;DirectionalShader bottomLight = new DirectionalShader(_xna, new Vector3(0, 1, -0.2f), XNAColor.Cyan, 0.5f, _xna.LoadEnvironment("Environments/Kitchen"));bottomLight.BlendState = BlendState.Additive;DirectionalShader topLight = new DirectionalShader(_xna, new Vector3(0, -1, -0.2f), XNAColor.Yellow, 0.5f, _xna.LoadEnvironment("Environments/Kitchen"));topLight.BlendState = BlendState.Additive;topLight.Shaders.Add(bottomLight);ExtractBloom glossyBloom = new ExtractBloom(_xna, 0.40f, 150f, 1.0f);glossyBloom.BlendState = BlendState.Additive;ExtractBloom bluredBloom = new ExtractBloom(_xna, 0.40f, 150f, 0.85f);bluredBloom.BlendState = BlendState.Additive;GaussianBlur hBlur = new GaussianBlur(_xna, 3.0f / (float)_walk.Viewer.Width, 0.0f, 6.0f);hBlur.BlendState = BlendState.Opaque;GaussianBlur vBlur = new GaussianBlur(_xna, 0.0f, 3.0f / (float)_walk.Viewer.Height, 6.0f);vBlur.BlendState = BlendState.Opaque;hBlur.Shaders.Add(vBlur);bluredBloom.Shaders.Add(hBlur);EdgeDetect antiAlias = new EdgeDetect(_xna, 0.06f);antiAlias.BlendState = BlendState.AlphaBlend;antiAlias.Shaders.Add(new SoftBlur(_xna));_walk.Viewer.MainSceneShader = topLight;_walk.Viewer.Shaders.Add(glossyBloom);_walk.Viewer.Shaders.Add(antiAlias);}The aproach is to keep everything as siple as possible.Under the hood I have a a class that handle all the post process effects and each instance can have other child effects inside. I can deside how effects blend toguether. All post process effects return a Texture2D based on a RenderTarget. Then childs uses that resut in order to create a new post process result and so on.All effects in the same level uses the same parent result and then blend together with their current BlendState. At the end you can combine any kind effects using the first main render.This is how works inside the Shader class (I call shader.cs to the class that handles a post process effect)public Texture2D ApplyShader(Texture2D source, Camera camera) {#region Configure ShaderSetupSizeRatio(source);SetMatrices(camera);  #endregion#region Render Shader into _mainRender_device.SetRenderTarget(_mainRender);_device.Clear(Color.Black);_spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, null, null, null, _fx);_spriteBatch.Draw(source, new Rectangle(0, 0, _resultWidth, _resultHeight), Color.White);_spriteBatch.End();_device.ResetRenderTarget();#endregion#region Extract all Shaders into _resultChildShadersif (_blendShaders) {_resultChildShaders.Clear();foreach (Shader shader in _shaders) {Texture2D texture = shader.ApplyShader(_mainRender, camera);texture.Tag = shader;_resultChildShaders.Add(texture);}}#endregion#region Prepare to Present_device.SetRenderTarget(_resultRender);_device.Clear(Color.Black);#endregion#region Present Main Shaderif (_renderCurrentShader) {_spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque);_spriteBatch.Draw(_mainRender, new Rectangle(0, 0, _resultWidth, _resultHeight), Color.White);_spriteBatch.End();}#endregion#region Present Child Shadersif (_blendShaders) {foreach (Texture2D shaderResult in _resultChildShaders) {Shader shader = (Shader)shaderResult.Tag;_spriteBatch.Begin(SpriteSortMode.Immediate, shader.BlendState);_spriteBatch.Draw(shaderResult, new Rectangle(0, 0, _resultWidth, _resultHeight), Color.White);_spriteBatch.End();}}_device.ResetRenderTarget();#endregionreturn _resultRender;}ResetRenderTarget is the same as  _graphicDevice.SetRenderTarget(null);SetupSizeRatio(source) and SetMatrices(camera) configure the current effect to be applied.This is how the Viewer class render and process all models: By the way. I don't use the game class, I do implement the IGraphicsDeviceService to create my own "Game" class that I called Viewer.#region Render 3D into _mainSceneif (_processMainScene) {_device.SetRenderTarget(_mainSceneRender);_device.Clear(_backgroundColor);_device.OverrideMaterial = null;_currentCamera.Draw();_device.ResetRenderTarget();_device.Textures[0] = _mainSceneRender;}#endregion#region Process G-Bufferif (_processGBuffer) {_device.SetRenderTarget(_colorMapRender);_device.Clear(Color.Black);_device.OverrideMaterial = _device.ColorMapMaterial;_currentCamera.Draw();_device.ResetRenderTarget();_device.Textures[1] = _colorMapRender;_device.SetRenderTarget(_normalMapRender);_device.Clear(Color.Gray);_device.OverrideMaterial = _device.NormalMapMaterial;_currentCamera.Draw();_device.ResetRenderTarget();_device.Textures[2] = _normalMapRender;_device.SetRenderTarget(_depthMapRender);_device.Clear(Color.White);_device.OverrideMaterial = _device.DepthMapMaterial;_currentCamera.Draw();_device.ResetRenderTarget();_device.Textures[3] = _depthMapRender;}#endregionif (_mainSceneShader != null) {_mainSceneRender = (RenderTarget2D)_mainSceneShader.ApplyShader(_mainSceneRender, _currentCamera);}#region Extract all Shaders into _resultScenesif (_blendShaders) {_shaderResults.Clear();foreach (Shader shader in _shaders) {Texture2D result = shader.ApplyShader(_mainSceneRender, _currentCamera);result.Tag = shader;_shaderResults.Add(result);}}#endregion#region Prepare to Present_device.ResetRenderTarget();_device.Clear(_backgroundColor);#endregion#region Present Main Sceneif (_renderMainScene) {_spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);_spriteBatch.Draw(_mainSceneRender, new Rectangle(0, 0, _width, _height), Color.White);_spriteBatch.End();}#endregion#region Present all Shadersif (_blendShaders) {int x = 0;int r = 1;if (_displaySeparatedShaders) {r = _shaderResults.Count;}foreach (Texture2D scene in _shaderResults) {Shader shader = (Shader)scene.Tag;_spriteBatch.Begin(SpriteSortMode.Immediate, shader.BlendState);_spriteBatch.Draw(scene, new Rectangle(x, 0, _width / r, _height), Color.White);_spriteBatch.End();if (_displaySeparatedShaders) {x = x + _width / _shaderResults.Count;}}}#endregion#region Present FPS stateif (_fpsTimer.Enabled) {_spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);_fpsCounter++;_spriteBatch.DrawString(_currentFont, _fpsCurrent + " fps", new Vector2(7, 5), Color.Yellow);_spriteBatch.End();}#endregion_device.Present(_sourceRectangle, _window);When I set the OverrideMaterial property, each model use it when draw is called. That way I can use the GBuffer registers already done to process the final result with the deferred technique.Deferred rendering is done with this HLSL effects:COLOR MAP:float4x4 _world;float4x4 _view;float4x4 _worldInverseTranspose;float4x4 _worldViewProjection;float4x4 _viewInverse;float4 _diffuseColor;texture _diffuseTexture : DIFFUSE;sampler2D DiffuseSampler = sampler_state {    Texture = <_diffuseTexture>;    FILTER = MIN_MAG_MIP_LINEAR;    AddressU = Wrap;    AddressV = Wrap;}; struct VertexData {    float3 Position: POSITION;};struct PixelData {    float4 Position: POSITION;    float2 UV: TEXCOORD2;};PixelData ProcessVertex(VertexData vertex) {PixelData pixel;pixel.Position = mul(float4(vertex.Position.xyz,1), _worldViewProjection);pixel.UV = vertex.UV;pixel.UV = float2(1,0);return pixel;}float4 ProcessPixel(PixelData pixel) : COLOR {return tex2D(DiffuseSampler, pixel.UV) + _diffuseColor;}technique Main {    pass p0 {   VertexShader = compile vs_2_0 ProcessVertex();   PixelShader = compile ps_2_0 ProcessPixel();    }}DEPTH MAP:float4x4 _world;float4x4 _view;float4x4 _worldInverseTranspose;float4x4 _worldViewProjection;float4x4 _viewInverse;float _near = 0;float _far = 512;struct VertexData {    float3 Position: POSITION;float3 Normal: NORMAL;    };struct PixelData {    float4 Position : POSITION;    float2 Depth : TEXCOORD2;};PixelData ProcessVertex(VertexData vertex) {    PixelData pixel;pixel.Position = mul(float4(vertex.Position.xyz,1), _worldViewProjection);pixel.Depth.x = pixel.Position.z;pixel.Depth.y = pixel.Position.w;    return pixel;}half4  ProcessPixel(PixelData pixel) : COLOR {return pixel.Depth.x / pixel.Depth.y;}technique Main {    pass p0 {   VertexShader = compile vs_2_0 ProcessVertex();ZEnable = true;ZWriteEnable = true;ZFunc = LessEqual;AlphaBlendEnable = false;CullMode = None;   PixelShader = compile ps_2_0 ProcessPixel();    }}NORMAL MAP:float4x4 _world;float4x4 _view;float4x4 _worldInverseTranspose;float4x4 _worldViewProjection;float4x4 _viewInverse;struct VertexData {    float3 Position: POSITION;float3 Normal: NORMAL;    };struct PixelData {    float4 Position: POSITION;    float3 Normal: TEXCOORD0;};PixelData ProcessVertex(VertexData vertex) {PixelData pixel;pixel.Position = mul(float4(vertex.Position.xyz,1), _worldViewProjection);pixel.Normal = mul(vertex.Normal, _world);return pixel;}float4 ProcessPixel(PixelData pixel) : COLOR {return float4(0.5f * (normalize(pixel.Normal) + 1.0f), 1);}technique Main {    pass p0 {VertexShader = compile vs_2_0 ProcessVertex();ZENABLE = TRUE;ZWRITEENABLE = TRUE;PixelShader = compile ps_2_0 ProcessPixel();    }}Then using this HLSL I process just directional lights. At this point I just can archive One material for every one (im working on that now )float4x4 _cameraView;float3 _cameraPosition;float4x4 _viewProjectionInverse;float3 _lightSource;float3 _lightColor;float _lampIntensity;texture _environment : ENVIRONMENT;//MATERIAL ATTRIBUTESfloat _specularIntensity = 0.8f; //[0, 1]float _specularExponent = 40; //[0, 128]float _reflection = 0.15f;float _fresnelMin = 0.01f;float _fresnelExponent = 0.9f;//sampler TextureSampler : register(s0);sampler ColorSampler : register(s1);sampler NormalSampler : register(s2);sampler DepthSampler : register(s3);samplerCUBE EnvironmentSampler = sampler_state {    Texture = <_environment>;    MinFilter = Linear;    MipFilter = Linear;    MagFilter = Linear;    AddressU = Clamp;    AddressV = Clamp;    AddressW = Clamp;};float4 PixelShaderFunction(float2 texCoord : TEXCOORD0) : COLOR0 {float4 color = tex2D(ColorSampler, texCoord);float3 normal = 2.0f * tex2D(NormalSampler, texCoord).xyz - 1.0f;    float  depth = tex2D(DepthSampler, texCoord).r;float4 position = mul(float4(texCoord.x * 2.0f - 1.0f, -(texCoord.y * 2.0f - 1.0f), depth, 1.0f), _viewProjectionInverse); position /= position.w;if (depth == 1){return 0;}float3 lightVector = -normalize(_lightSource);float3 reflectionVector = normalize(reflect(-lightVector, normal));float3 directionToCamera = normalize(_cameraPosition - position);    float fresnel = lerp(_reflection, (_reflection * _fresnelMin), pow(abs(dot(normal, lightVector)), 1.0 / _fresnelExponent));    float specular = _specularIntensity * pow( saturate(dot(reflectionVector, directionToCamera)), _specularExponent) * _lampIntensity;float3 diffuse = max(0, dot(normal, lightVector)) * color.rgb * _lightColor * _lampIntensity;float3 reflection = fresnel * texCUBE(EnvironmentSampler, reflectionVector).rgb;return float4(specular + diffuse + reflection, 1);}technique Main {    pass Pass1 {  PixelShader = compile ps_2_0 PixelShaderFunction();    }}forgive my english if you read something wrong 