protected override void LoadContent() { ClearColor = Color.Black; shadowMap = new RenderTarget2D(1024, 1024, false, SurfaceFormat.Single, DepthFormat.Depth24Stencil8); blurRT = new RenderTarget2D(1024, 1024, false, SurfaceFormat.Single, DepthFormat.None); blurEffect = ContentManager.Load <Effect>("Shaders//GaussianBlur.fx"); ModelLoaderParameters mlp = new ModelLoaderParameters(); mlp.NormalGeneration = NormalGeneration.Smooth; mlp.SwapWindingOrder = true; mlp.PreferLitMaterials = true; rs = new RasterizerState(); rs.Cull = CullMode.Front; rs.BindRenderState(); // mesh = new Sphere("Sphere", 50, 50, 20); mesh = ContentManager.Load <Mesh>("Models//statue.tebo"); mesh.ComputeTangentBasis(); Material mat = ContentManager.Load <Material>("LitBasicTexture.tem").Clone(); mat.SetParameter("DiffuseMap", ContentManager.Load <Texture2D>("Textures//statue_diff.dds")); mat.SetParameter("NormalMap", ContentManager.Load <Texture2D>("Textures//statue_norm.dds")); mat.SetParameter("MatSpecular", new Vector3(.3f, .3f, .3f)); mesh.SetMaterial(mat); Quad q = new Quad("Floor", 800, 800); q.Rotation = Quaternion.FromAngleAxis(MathHelper.ToRadians(-90), Vector3.UnitX); q.Translation = new Vector3(0, -70, 0); q.Material = ContentManager.Load <Material>("Materials//LitBasicTextureShadow.tem").Clone(); q.Material.SetParameter("DiffuseMap", ContentManager.Load <Texture2D>("Textures//statue_diff.dds")); receiverMat = q.Material; receiverMat.SetParameter("MatSpecular", new Vector3(.3f, .3f, .3f)); // mesh.SetMaterial(receiverMat); InputLayer.RegisterTrigger(new InputTrigger(new KeyPressedCondition(Keys.Enter, false), new InputAction(delegate(GameTime time) { receive = !receive; if (receive) { mesh.SetMaterial(receiverMat); } else { mesh.SetMaterial(mat); } }))); InputLayer.RegisterTrigger(new InputTrigger(new KeyPressedCondition(Keys.C, false), new InputAction(delegate(GameTime time) { cullFront = !cullFront; }))); DataBuffer <Vector2> texCoords = q.MeshData.TextureCoordinates; texCoords.Position = 0; texCoords.Set(new Vector2(0, 0)); texCoords.Set(new Vector2(4, 0)); texCoords.Set(new Vector2(4, 4)); texCoords.Set(new Vector2(0, 4)); q.MeshData.UpdateVertexData <Vector2>(VertexSemantic.TextureCoordinate, texCoords); RootNode.AddChild(q); sl = new SpotLight(new Vector3(100, 200, 10), new Vector3(-100, -200, -10), 5, 15); RootNode.RemoveAllLights(); RootNode.AddLight(sl); RootNode.AddChild(mesh); shadowMat = new Material("ShadowMat"); shadowMat.LoadEffect(ContentManager.Load <Effect>("Shaders//ShadowMapEffect.fx")); shadowMat.SetEngineParameter("LightWVP", Tesla.Core.EngineValue.WorldViewProjection); lightCam = new Camera(); batch = new SpriteBatch(); dss = new DepthStencilState(); dss.DepthFunction = ComparisonFunction.LessEqual; dss.BindRenderState(); float texOffsets = 0.5f + (0.5f / (float)shadowMap.Width); texMat = new Matrix(0.5f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, texOffsets, texOffsets, 0.0f, 1.0f); rtnode = new Node("Node"); rtnode.Translation = sl.Position; Node parent = new Node("Parent"); parent.AddChild(rtnode); RootNode.AddChild(parent); parent.AddController(new Tesla.Scene.Extension.RotateController(Vector3.UnitY, 25)); }
/// <summary> /// Creates the default render states. /// </summary> private static void CreateDefaultRenderStates() { //*********************// //* Rasterizer States *// //*********************// RasterizerState cullNone = new RasterizerState(); cullNone.Cull = CullMode.None; cullNone.VertexWinding = VertexWinding.Clockwise; cullNone.BindRenderState(); RasterizerState.CullNone = cullNone; RasterizerState cullBackCW = new RasterizerState(); cullBackCW.Cull = CullMode.Back; cullBackCW.VertexWinding = VertexWinding.Clockwise; cullBackCW.BindRenderState(); RasterizerState.CullBackClockwiseFront = cullBackCW; RasterizerState cullBackCCW = new RasterizerState(); cullBackCCW.Cull = CullMode.Back; cullBackCCW.VertexWinding = VertexWinding.CounterClockwise; cullBackCCW.BindRenderState(); RasterizerState.CullBackCounterClockwiseFront = cullBackCCW; RasterizerState cullNoneWireframe = new RasterizerState(); cullNoneWireframe.Cull = CullMode.None; cullNoneWireframe.Fill = FillMode.WireFrame; cullNoneWireframe.VertexWinding = VertexWinding.Clockwise; cullNoneWireframe.BindRenderState(); RasterizerState.CullNoneWireframe = cullNoneWireframe; //****************// //* Blend States *// //****************// BlendState opaque = new BlendState(); opaque.SetBlendEnable(0, false); opaque.BindRenderState(); BlendState.Opaque = opaque; BlendState pmAlphaBlend = new BlendState(); pmAlphaBlend.AlphaSourceBlend = Blend.One; pmAlphaBlend.AlphaDestinationBlend = Blend.InverseSourceAlpha; pmAlphaBlend.ColorSourceBlend = Blend.One; pmAlphaBlend.ColorDestinationBlend = Blend.InverseSourceAlpha; pmAlphaBlend.BindRenderState(); BlendState.AlphaBlendPremultiplied = pmAlphaBlend; BlendState npmAlphaBlend = new BlendState(); npmAlphaBlend.AlphaSourceBlend = Blend.SourceAlpha; npmAlphaBlend.AlphaDestinationBlend = Blend.InverseSourceAlpha; npmAlphaBlend.ColorSourceBlend = Blend.SourceAlpha; npmAlphaBlend.ColorDestinationBlend = Blend.InverseSourceAlpha; npmAlphaBlend.BindRenderState(); BlendState.AlphaBlendNonPremultiplied = npmAlphaBlend; BlendState additive = new BlendState(); additive.AlphaSourceBlend = Blend.SourceAlpha; additive.AlphaDestinationBlend = Blend.One; additive.ColorSourceBlend = Blend.SourceAlpha; additive.ColorDestinationBlend = Blend.One; additive.BindRenderState(); BlendState.AdditiveBlend = additive; //***********************// //* DepthStencil States *// //***********************// DepthStencilState none = new DepthStencilState(); none.DepthEnable = false; none.DepthWriteEnable = false; none.BindRenderState(); DepthStencilState.None = none; DepthStencilState depthWriteOff = new DepthStencilState(); depthWriteOff.DepthEnable = true; depthWriteOff.DepthWriteEnable = false; depthWriteOff.BindRenderState(); DepthStencilState.DepthWriteOff = depthWriteOff; DepthStencilState def = new DepthStencilState(); def.DepthEnable = true; def.DepthWriteEnable = true; def.BindRenderState(); DepthStencilState.Default = def; //******************// //* Sampler States *// //******************// SamplerState pw = new SamplerState(); pw.Filter = TextureFilter.Point; pw.AddressU = pw.AddressV = pw.AddressW = TextureAddressMode.Wrap; pw.BindRenderState(); SamplerState.PointWrap = pw; SamplerState pc = new SamplerState(); pc.Filter = TextureFilter.Point; pc.AddressU = pc.AddressV = pc.AddressW = TextureAddressMode.Clamp; pc.BindRenderState(); SamplerState.PointClamp = pc; SamplerState lw = new SamplerState(); lw.Filter = TextureFilter.Linear; lw.AddressU = lw.AddressV = lw.AddressW = TextureAddressMode.Wrap; lw.BindRenderState(); SamplerState.LinearWrap = lw; SamplerState lc = new SamplerState(); lc.Filter = TextureFilter.Linear; lc.AddressU = lc.AddressV = lc.AddressW = TextureAddressMode.Clamp; lc.BindRenderState(); SamplerState.LinearClamp = lc; SamplerState aw = new SamplerState(); aw.Filter = TextureFilter.Anisotropic; aw.AddressU = aw.AddressV = aw.AddressW = TextureAddressMode.Wrap; aw.BindRenderState(); SamplerState.AnisotropicWrap = aw; SamplerState ac = new SamplerState(); ac.Filter = TextureFilter.Anisotropic; ac.AddressU = ac.AddressV = ac.AddressW = TextureAddressMode.Clamp; ac.BindRenderState(); SamplerState.AnisotropicClamp = ac; }