public void TestBasicShaderAutoReload() { BasicShader shader = null; FullScreenQuad quad = null; XNAGame game = new XNAGame(); game.InitializeEvent += delegate { shader = BasicShader.LoadFromEmbeddedFile(game, typeof(GraphicsTest).Assembly, "MHGameWork.TheWizards.Tests.Graphics.Files.TestShader.fx", "..\\..\\Unit Tests\\Graphics\\Files\\TestShader.fx", new EffectPool()); shader.SetTechnique("Technique1"); quad = new FullScreenQuad(game.GraphicsDevice); }; game.DrawEvent += delegate { shader.RenderMultipass(delegate { quad.DrawOld(game.GraphicsDevice); }); }; game.Run(); }
private void initializeDeferredShading(IXNAGame _game, int backBufferWidth, int backBufferHeight) { shadowMapRT = new RenderTarget2D(_game.GraphicsDevice, shadowMapSize, shadowMapSize, 1, SurfaceFormat.Single); shadowMapDS = new DepthStencilBuffer(GraphicsDevice, shadowMapSize, shadowMapSize, GraphicsDevice.DepthStencilBuffer.Format); lightRT = new RenderTarget2D(GraphicsDevice, backBufferWidth, backBufferHeight, 1, SurfaceFormat.HalfVector4, RenderTargetUsage.PreserveContents); deferredFinalRT = new RenderTarget2D(GraphicsDevice, backBufferWidth, backBufferHeight, 1, SurfaceFormat.HalfVector4, RenderTargetUsage.PreserveContents); directionalLightShader = loadShader("DirectionalLight.fx"); directionalLightShader.SetTechnique("Technique0"); finalCombineEffect = loadShader("CombineFinal.fx"); finalCombineEffect.SetTechnique("Technique1"); pointLightShader = loadShader("PointLight.fx"); pointLightShader.SetTechnique("Technique1"); spotLightShader = loadShader("SpotLight.fx"); spotLightShader.SetTechnique("Technique1"); shadowMapShader = loadShader("ShadowMap.fx"); }
/// <summary> /// Constructor /// </summary> public LineDemo() { m_Shader = new BasicShader(); m_ProjectionMatrix = Matrix4.Identity; m_ModelViewMatrix = Matrix4.Identity; }
public void TestBasicShaderCustomInclude() { BasicShader shader = null; FullScreenQuad quad = null; XNAGame game = new XNAGame(); game.InitializeEvent += delegate { shader = new BasicShader(game); shader.AddCustomIncludeHandler("testInclude.fx", delegate { var byteArray = Encoding.ASCII.GetBytes("float getColor(){return 1;}"); return(new MemoryStream(byteArray)); }); shader.InitFromEmbeddedFile(game, typeof(GraphicsTest).Assembly, "MHGameWork.TheWizards.Tests.Graphics.Files.TestShaderInclude.fx", "..\\..\\Unit Tests\\Graphics\\Files\\TestShaderInclude.fx", new EffectPool()); shader.SetTechnique("Technique1"); quad = new FullScreenQuad(game.GraphicsDevice); }; game.DrawEvent += () => shader.RenderMultipass(() => quad.Draw()); game.Run(); }
public SurfaceMaterial(DX11Game game, ShaderResourceView diffuseTexture) { this.game = game; textures[0] = diffuseTexture; textures[1] = null; //normalTexture; textures[2] = null; //specularTexture; baseShader = BasicShader.LoadAutoreload(game, ShaderFiles.DCSurface, delegate { }, createShaderMacros()); baseShader.SetTechnique("DCSurface"); //baseShader.DiffuseTexture = checkerTexture; var desc = new SamplerDescription() { AddressU = TextureAddressMode.Wrap, AddressV = TextureAddressMode.Wrap, AddressW = TextureAddressMode.Wrap, Filter = Filter.Anisotropic, MaximumAnisotropy = 16 }; sampler = SamplerState.FromDescription(game.Device, desc); inputLayout = CreateInputLayout(); }
public void Dispose() { Material = null; DiffuseTexture = null; if (Shader != null) { Shader.Dispose(); } Shader = null; if (PerObjectConstantBuffer != null) { PerObjectConstantBuffer.Dispose(); } PerObjectConstantBuffer = null; if (Parts != null) { foreach (var p in Parts) { p.Dispose(); } } Parts = null; }
void RecompileShader() { var filename = CompiledShaderCache.Current.RootShaderPath + "SSAO\\HorizonSSAO.fx"; shader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo(filename), loadShaderVariables); }
private void loadShaderVariables(BasicShader shader) { m_Effect = shader.Effect; // Obtain the technique m_Technique_HBAO_NLD[0] = m_Effect.GetTechniqueByName("HORIZON_BASED_AO_NLD_LOWQUALITY_Pass"); m_Technique_HBAO_LD[0] = m_Effect.GetTechniqueByName("HORIZON_BASED_AO_LD_LOWQUALITY_Pass"); m_Technique_HBAO_NLD[1] = m_Effect.GetTechniqueByName("HORIZON_BASED_AO_NLD_Pass"); m_Technique_HBAO_LD[1] = m_Effect.GetTechniqueByName("HORIZON_BASED_AO_LD_Pass"); m_Technique_HBAO_NLD[2] = m_Effect.GetTechniqueByName("HORIZON_BASED_AO_NLD_QUALITY_Pass"); m_Technique_HBAO_LD[2] = m_Effect.GetTechniqueByName("HORIZON_BASED_AO_LD_QUALITY_Pass"); // Obtain pointers to the shader variales m_DepthTexVar = m_Effect.GetVariableByName("tLinDepth").AsResource(); m_NormalTexVar = m_Effect.GetVariableByName("tNormal").AsResource(); m_RandTexVar = m_Effect.GetVariableByName("tRandom").AsResource(); m_pNumSteps = m_Effect.GetVariableByName("g_NumSteps").AsScalar(); m_pNumDirs = m_Effect.GetVariableByName("g_NumDir").AsScalar(); m_pRadius = m_Effect.GetVariableByName("g_R").AsScalar(); m_pInvRadius = m_Effect.GetVariableByName("g_inv_R").AsScalar(); m_pSqrRadius = m_Effect.GetVariableByName("g_sqr_R").AsScalar(); m_pAngleBias = m_Effect.GetVariableByName("g_AngleBias").AsScalar(); m_pTanAngleBias = m_Effect.GetVariableByName("g_TanAngleBias").AsScalar(); m_pAttenuation = m_Effect.GetVariableByName("g_Attenuation").AsScalar(); m_pContrast = m_Effect.GetVariableByName("g_Contrast").AsScalar(); m_pFocalLen = m_Effect.GetVariableByName("g_FocalLen").AsVector(); m_pInvFocalLen = m_Effect.GetVariableByName("g_InvFocalLen").AsVector(); m_pInvResolution = m_Effect.GetVariableByName("g_InvResolution").AsVector(); m_pResolution = m_Effect.GetVariableByName("g_Resolution").AsVector(); // Set Defaults updateShaderState(); }
public DirectionalLightRenderer(DX11Game game, GBuffer gBuffer) { this.game = game; this.gBuffer = gBuffer; var device = game.Device; context = device.ImmediateContext; shadowsShader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\DirectionalLight.fx")); shadowsShader.SetTechnique("Technique0"); noShadowsShader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\DirectionalLight.fx"), null, new[] { new ShaderMacro("DISABLE_SHADOWS") }); noShadowsShader.SetTechnique("Technique0"); quad = new FullScreenQuad(device); layout = FullScreenQuad.CreateInputLayout(device, shadowsShader.GetCurrentPass(0)); LightDirection = Vector3.Normalize(new Vector3(1, 2, 1)); Color = new Vector3(1, 1, 0.9f); CSMRenderer = new CSM.CSMRenderer(game); }
public void SetShadowOcclusionShaderVariables(BasicShader shader, ICamera mainCamera) { shader.Effect.GetVariableByName("g_matInvView").AsMatrix().SetMatrix(mainCamera.ViewInverse); shader.Effect.GetVariableByName("g_matLightViewProj").AsMatrix().SetMatrixArray(lightViewProjectionMatrices); shader.Effect.GetVariableByName("g_vClipPlanes").AsVector().Set(lightClipPlanes.Select(o => new Vector4(o, 1, 1)).ToArray()); shader.Effect.GetVariableByName("ShadowMap").AsResource().SetResource(ShadowMapRV); shader.Effect.GetVariableByName("g_vShadowMapSize").AsVector().Set(new Vector2(shadowMap.Description.Width, shadowMap.Description.Height)); }
public void TestBasicShaderIncludeRoot() { BasicShader shader = null; FullScreenQuad quad = null; var game = new DX11Game(); game.InitDirectX(); var fi = new FileInfo("../../Common.Core/Shaders/TestAutoReload.fx"); var include = new FileInfo("../../Common.Core/Shaders/IncludeTest.fx"); using (var fs = new StreamWriter(fi.OpenWrite())) { fs.WriteLine("float4 Color = float4(1,0,0,1);"); } using (var fs = new StreamWriter(include.OpenWrite())) { fs.WriteLine("float4 Color2 = float4(0,0,0,1);"); } shader = BasicShader.LoadAutoreload(game, fi); shader.SetTechnique("TestAutoReload"); quad = new FullScreenQuad(game.Device); var inputLayout = FullScreenQuad.CreateInputLayout(game.Device, shader.GetCurrentPass(0)); var time = 0f; game.GameLoopEvent += delegate { shader.Apply(); quad.Draw(inputLayout); if (time > 2 && time < 3) { using (var fs = new StreamWriter(fi.OpenWrite())) { fs.WriteLine("float4 Color = float4(1,1,0,1);"); time = 5; } } if (time > 6 && time < 7) { using (var fs = new StreamWriter(include.OpenWrite())) { fs.WriteLine("float4 Color2 = float4(-1,0,0,1);"); time = 10; } } time += game.Elapsed; }; game.Run(); }
public Actor(RawModel model, ITexture texture, BasicShader shader) { ComponentScale = new Vector3(1); ComponentTranslation = new Vector3(0); ComponentRotation = new Vector3(0); this.texture = texture; rawModel = model; this.shader = shader; }
public void Dispose() { baseShader.Dispose(); sampler.Dispose(); inputLayout.Dispose(); baseShader = null; sampler = null; inputLayout = null; }
public IShader Clone() { var newShader = new BasicShader() { Effect = Effect.Clone() }; return(newShader); }
/// <summary> /// Creates the renderer /// </summary> public CSMRenderer(DX11Game game) { this.game = game; var device = game.Device; context = device.ImmediateContext; // Load the effect we need shadowMapShader = BasicShader.LoadAutoreload(game, new FileInfo(CompiledShaderCache.Current.RootShaderPath + @"CSM\CSM.fx")); // Create the shadow map, using a 32-bit floating-point surface format shadowMap = new Texture2D(device, new Texture2DDescription { Width = ShadowMapSize * NumSplits, Height = ShadowMapSize, MipLevels = 1, ArraySize = 1, BindFlags = BindFlags.DepthStencil | BindFlags.ShaderResource, Format = global::SlimDX.DXGI.Format.R32_Typeless, SampleDescription = new global::SlimDX.DXGI.SampleDescription(1, 0) }); shadowMapDsv = new DepthStencilView(device, shadowMap, new DepthStencilViewDescription { ArraySize = 1, Dimension = DepthStencilViewDimension.Texture2D, Flags = DepthStencilViewFlags.None, Format = global::SlimDX.DXGI.Format.D32_Float, MipSlice = 0 }); ShadowMapRV = new ShaderResourceView(device, shadowMap, new ShaderResourceViewDescription { ArraySize = 1, Dimension = ShaderResourceViewDimension.Texture2D, MipLevels = 1, MostDetailedMip = 0, Format = global::SlimDX.DXGI.Format.R32_Float }); // Create the full-screen quad fullScreenQuad = new FullScreenQuad(device); // We'll keep an array of EffectTechniques that will let us map a // ShadowFilteringType to a technique for calculating shadow occlusion shadowOcclusionTechniques[0] = "CreateShadowTerm2x2PCF"; shadowOcclusionTechniques[1] = "CreateShadowTerm3x3PCF"; shadowOcclusionTechniques[2] = "CreateShadowTerm5x5PCF"; shadowOcclusionTechniques[3] = "CreateShadowTerm7x7PCF"; shadowMapShader.SetTechnique(shadowOcclusionTechniques[0]); layout = FullScreenQuad.CreateInputLayout(device, shadowMapShader.GetCurrentPass(0)); }
public MeshRenderDataFactory(DX11Game game, BasicShader baseShader, TexturePool texturePool) { this.game = game; this.baseShader = baseShader; this.texturePool = texturePool; checkerTexture = Texture2D.FromFile(game.Device, TWDir.GameData.CreateSubdirectory("Core").FullName + "\\checker.png"); checkerTextureRV = new ShaderResourceView(game.Device, checkerTexture); }
/// <summary> /// Constructor /// </summary> public YogaLayoutDemo() { m_Shader = new BasicShader(); m_Root = new YogaNode() { FlexDirection = YogaFlexDirection.Column, JustifyContent = YogaJustify.Center, AlignItems = YogaAlign.Center }; }
internal override void LoadContent() { _camera = new InGameCamera(); _shader = new BasicShader(); _batch = new SpriteBatch(Controller.GraphicsDevice); _level = new Level(); _level.LoadContent(); _level.SpawnNewFormation(); }
public CombineFinalRenderer(DX11Game game, GBuffer gBuffer) { this.game = game; this.gBuffer = gBuffer; var device = game.Device; context = device.ImmediateContext; shader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\CombineFinal.fx")); shader.SetTechnique("Technique0"); quad = new FullScreenQuad(device); layout = FullScreenQuad.CreateInputLayout(device, shader.GetCurrentPass(0)); var desc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.R16G16B16A16_Float, Width = gBuffer.Width, Height = gBuffer.Height, ArraySize = 1, SampleDescription = new SampleDescription(1, 0), MipLevels = 1 }; lightAccumulationMap = new Texture2D(device, desc); lightAccumulationRTV = new RenderTargetView(device, lightAccumulationMap); LightAccumulationRV = new ShaderResourceView(device, lightAccumulationMap); var bsDesc = new BlendStateDescription(); var b = new RenderTargetBlendDescription(); b.BlendEnable = true; b.BlendOperation = BlendOperation.Add; b.BlendOperationAlpha = BlendOperation.Add; b.DestinationBlend = BlendOption.One; b.DestinationBlendAlpha = BlendOption.One; b.SourceBlend = BlendOption.One; b.SourceBlendAlpha = BlendOption.One; b.RenderTargetWriteMask = ColorWriteMaskFlags.All; bsDesc.RenderTargets[0] = b; blendState = BlendState.FromDescription(device, bsDesc); }
private void reloadShader(DX11Game game) { noShadowsShader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\PointLight.fx"), null, new[] { new ShaderMacro("DISABLE_SHADOWS") }); noShadowsShader.SetTechnique("Technique0"); shadowsShader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\PointLight.fx")); shadowsShader.SetTechnique("Technique0"); }
private void initializeDeferredRendering(IXNAGame _game, int backBufferWidth, int backBufferHeight) { diffuseRT = new RenderTarget2D(_game.GraphicsDevice, backBufferWidth, backBufferHeight, 1, SurfaceFormat.Color); normalRT = new RenderTarget2D(_game.GraphicsDevice, backBufferWidth, backBufferHeight, 1, SurfaceFormat.Color); depthRT = new RenderTarget2D(_game.GraphicsDevice, backBufferWidth, backBufferHeight, 1, SurfaceFormat.Single); clearShader = loadShader("ClearGBuffer.fx"); clearShader.SetTechnique("Technique1"); renderGBufferShader = loadShader("RenderGBuffer.fx"); renderGBufferShader.SetTechnique("Technique1"); }
private void RenderBasePass() { if (PostConstructor) { DefaultTexture = ProxyTextureLoader.LoadSingleTexture(System.Environment.CurrentDirectory + "\\..\\..\\Textures\\default.jpg"); DefaultShader = new BasicShader(System.Environment.CurrentDirectory + "/../../Shaders/basicVS.glsl", "../../Shaders/basicFS.glsl"); PostConstructor = false; } if (actor != null) { actor.Render(EditorCamera.ViewMatrix, projectionMatrix); } skybox.Render(EditorCamera.ViewMatrix, projectionMatrix); }
public FogEffect(DX11Game game) { this.game = game; var device = game.Device; context = device.ImmediateContext; shader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Deferred\\Fog.fx")); shader.SetTechnique("Technique0"); quad = new FullScreenQuad(device); layout = FullScreenQuad.CreateInputLayout(device, shader.GetCurrentPass(0)); }
private void RenderBasePass() { if (PostConstructor) { CollisionBoxModel = new RawModel(ProxyModelLoader.LoadModel(CollisionBoxPath)); DefaultTexture = ProxyTextureLoader.LoadSingleTexture(ProjectFolders.TextureAtlasPath + "\\default.jpg"); DefaultShader = new BasicShader(ProjectFolders.ShadersPath + "\\basicVS.glsl", ProjectFolders.ShadersPath + "\\basicFS.glsl"); PostConstructor = false; } if (actor != null && !bComponentHierarchyIsDirty) { actor.Render(EditorCamera.ViewMatrix, projectionMatrix); } skybox.Render(EditorCamera.ViewMatrix, projectionMatrix); }
public override void Initialize() { CreateSelectionSate(GeometrySelectionMode.Object); _renderEngine = GetComponent <RenderEngineComponent>(); _lineGeometry = new LineMeshRender(Game.Content); VertexRenderer = new VertexInstanceMesh(GraphicsDevice, Game.Content); _wireframeEffect = new BasicShader(GraphicsDevice); _wireframeEffect.DiffuseColor = Vector3.Zero; _selectedFacesEffect = new BasicShader(GraphicsDevice); _selectedFacesEffect.DiffuseColor = new Vector3(1, 0, 0); _selectedFacesEffect.SpecularColor = new Vector3(1, 0, 0); _selectedFacesEffect.EnableDefaultLighting(); base.Initialize(); }
public void buildEffect(IXNAGame _game, TextureCube envMap) { string errorMessage; if (mEffect != null) { mEffect.Dispose(); } mEffect = BasicShader.LoadFromFXFile(_game, new GameFile(mInfo.fxFilename)); /*if ( errorMessage != null && errorMessage != "" ) * { * Cursor.Show(); * MessageBox.Show( errorMessage, "Error Building Effect" ); * }*/ mTechHandle = mEffect.GetTechnique("WaterTech"); mWorldHandle = mEffect.GetParameter("gWorld"); mWorldInvHandle = mEffect.GetParameter("gWorldInv"); mWVPHandle = mEffect.GetParameter("gWVP"); mEyePosHandle = mEffect.GetParameter("gEyePosW"); mSunDirHandle = mEffect.GetParameter("gSunDir"); mSunColorHandle = mEffect.GetParameter("gSunColor"); mWaveMap0Handle = mEffect.GetParameter("gWaveMap0"); mWaveMap1Handle = mEffect.GetParameter("gWaveMap1"); mWaveNMapOffset0Handle = mEffect.GetParameter("gWaveNMapOffset0"); mWaveNMapOffset1Handle = mEffect.GetParameter("gWaveNMapOffset1"); mReflectMapHandle = mEffect.GetParameter("gReflectMap"); mRefractMapHandle = mEffect.GetParameter("gRefractMap"); mWorldHandle.SetValue(mInfo.toWorld); Matrix invWorld = Matrix.Invert(mInfo.toWorld); mWorldInvHandle.SetValue(invWorld); mEffect.effect.CurrentTechnique = mTechHandle; mWaveMap0Handle.SetValue(mWaveMap0); mWaveMap1Handle.SetValue(mWaveMap1); float[] sunDir = new float[] { mInfo.sunDirection.X, mInfo.sunDirection.Y, mInfo.sunDirection.Z }; mSunDirHandle.SetValue(sunDir); }
public void InitializeRender() { shader = BasicShader.LoadAutoreload(game, new System.IO.FileInfo( CompiledShaderCache.Current.RootShaderPath + "Particles\\BillBoardShader.fx"), null); setShader(); vertexStride = ParticleVertex.SizeInBytes; var desc = new BufferDescription { BindFlags = BindFlags.VertexBuffer, CpuAccessFlags = CpuAccessFlags.Write, OptionFlags = ResourceOptionFlags.None, SizeInBytes = maxParticles * 6 * ParticleVertex.SizeInBytes, StructureByteStride = ParticleVertex.SizeInBytes, Usage = ResourceUsage.Dynamic }; vertexBuffer = new Buffer(game.Device, desc);//game.GraphicsDevice, typeof(ParticleVertex), maxParticles * 6, BufferUsage.WriteOnly); layout = new InputLayout(game.Device, ParticleVertex.VertexElements, shader.GetCurrentPass(0).Description.Signature); //decl = declarationPool.GetVertexDeclaration<ParticleVertex>(); }
public void Dispose() { _wireframeEffect.Effect.Dispose(); _wireframeEffect = null; _selectedFacesEffect.Effect.Dispose(); _selectedFacesEffect = null; VertexRenderer.Dispose(); VertexRenderer = null; _lineGeometry.Dispose(); _lineGeometry = null; if (SelectionChanged != null) { foreach (var d in SelectionChanged.GetInvocationList()) { SelectionChanged -= (d as SelectionChangedDelegate); } } _currentState?.Clear(); _currentState = null; }
private void LoadShader(EffectPool pool) { // // Load the shader and set the material properties // if (shader != null) { shader.Dispose(); } System.IO.Stream strm = EmbeddedFile.GetStreamFullPath( "MHGameWork.TheWizards.Rendering.Files.DefaultModelShader.fx", game.EngineFiles.DebugFilesDirectory + "/DefaultModelShader.fx"); shader = BasicShader.LoadFromFXFile(game, strm, pool); //Shader = BasicShader.LoadFromFXFile( game, new GameFile( shaderFilename ), pool ); LoadParameters(); LoadTechniques(); SetTechniqueType(TechniqueType.Colored); }
public void TestFullscreenQuad() { BasicShader shader = null; FullScreenQuad quad = null; var game = new DX11Game(); game.InitDirectX(); var device = game.Device; var bytecode = ShaderBytecode.CompileFromFile("../../Common.Core/Shaders/FullScreenQuad.fx", "fx_5_0", ShaderFlags.None, EffectFlags.None); var effect = new Effect(game.Device, bytecode); var technique = effect.GetTechniqueByName("TestQuadTextured"); var pass = technique.GetPassByIndex(0); quad = new FullScreenQuad(game.Device); var diffuseShaderVariable = effect.GetVariableByName("txDiffuse").AsResource(); var texturePath = Wallpaper001_png; var diffuseTexture = Texture2D.FromFile(device, texturePath); var diffuseTextureRv = new ShaderResourceView(device, diffuseTexture); diffuseShaderVariable.SetResource(diffuseTextureRv); var inputLayout = FullScreenQuad.CreateInputLayout(device, pass); game.GameLoopEvent += delegate { pass.Apply(game.Device.ImmediateContext); quad.Draw(inputLayout); }; game.Run(); }