public void Dispose() { try { if (ProgramID != 0) { GL.DetachShader(ProgramID, VertexShader.ShaderID); GL.DetachShader(ProgramID, FragmentShader.ShaderID); GL.DeleteProgram(ProgramID); GL.UseProgram(0); VertexShader.Dispose(); FragmentShader.Dispose(); this.ProgramID = 0; } } catch (Exception err) { System.Windows.Forms.MessageBox.Show("Error dispsing Shader program: " + err.Message); ErrorCode code = GL.GetError(); if (code.ToString() != "NoError") { System.Diagnostics.Debug.WriteLine("Shader Error : " + code.ToString()); } } }
public override void Dispose() { base.Dispose(); if (Id > 0) { GL.DeleteProgram(Id); Id = 0; } VertexShader?.Dispose(); FragmentShader?.Dispose(); GeometryShader?.Dispose(); VertexShader = null; FragmentShader = null; GeometryShader = null; if (namePtr != IntPtr.Zero) { Marshal.FreeHGlobal(namePtr); namePtr = IntPtr.Zero; } Name = null; }
public void Dispose() { InputLayout.Dispose(); VertexShader.Dispose(); GeometryShader?.Dispose(); FragmentShader.Dispose(); GL.DeleteProgram(ProgramID); }
public void Dispose() { InputLayout.Dispose(); VertexShader.Dispose(); FragmentShader.Dispose(); GL.DeleteProgram(ProgramID); Utilities.CheckLastGLES3Error(); }
public void Dispose() { InputLayout.Dispose(); VertexShader.Dispose(); TessellationControlShader?.Dispose(); TessellationEvaluationShader?.Dispose(); GeometryShader?.Dispose(); FragmentShader.Dispose(); GL.DeleteProgram(ProgramID); }
public static ShaderProgram CreateSpriteShaderProgram(RenderContext renderContext, string label = "Sprite ShaderProgram") { VertexShader vertexShader = new VertexShader(renderContext, @"#version 330 core layout (location = 0) in vec2 aPos; layout (location = 1) in vec2 aTexCoord; layout (location = 2) in vec4 aColor; out vec2 TexCoord; out vec4 Color; uniform mat4 projection; uniform mat4 transform; void main() { gl_Position = projection * transform * vec4(aPos, 0.0, 1.0); TexCoord = aTexCoord; Color = aColor; }"); FragmentShader fragmentShader = new FragmentShader(renderContext, @"#version 330 core out vec4 FragColor; in vec2 TexCoord; in vec4 Color; uniform sampler2D texture0; void main() { FragColor = texture(texture0, TexCoord) * Color; }"); ShaderProgram shaderProgram = new ShaderProgram(renderContext); shaderProgram.AttachShader(vertexShader); shaderProgram.AttachShader(fragmentShader); shaderProgram.Link(); shaderProgram.DetachShader(vertexShader); shaderProgram.DetachShader(fragmentShader); vertexShader.Dispose(); fragmentShader.Dispose(); shaderProgram.Label = label; return(shaderProgram); }
protected override void Dispose(bool disposeManagedResources) { base.Dispose(disposeManagedResources); if (VertexShader != null && FragmentShader != null) { VertexShader.Dispose(); VertexShader = null; FragmentShader.Dispose(); FragmentShader = null; } }
public static ShaderProgram CreateAtlasFlippingProgram(RenderContext renderContext) { VertexShader vertexShader = new VertexShader(renderContext, @"#version 330 core layout (location = 0) in vec2 aPos; layout (location = 1) in vec2 aTexCoord; out vec2 TexCoord; uniform mat4 projection; void main() { gl_Position = projection * vec4(aPos, 1.0, 1.0); TexCoord = aTexCoord; }"); FragmentShader fragmentShader = new FragmentShader(renderContext, @"#version 330 core out vec4 FragColor; in vec2 TexCoord; uniform sampler2D texture0; void main() { vec4 samp = vec4(1.0, 1.0, 1.0, texture(texture0, TexCoord).a); FragColor = samp; }"); ShaderProgram shaderProgram = new ShaderProgram(renderContext); shaderProgram.AttachShader(vertexShader); shaderProgram.AttachShader(fragmentShader); shaderProgram.Link(); shaderProgram.DetachShader(vertexShader); shaderProgram.DetachShader(fragmentShader); vertexShader.Dispose(); fragmentShader.Dispose(); shaderProgram.Label = "Font Import ShaderProgram"; return(shaderProgram); }
/// <summary> /// <para>Loads Shader from given Zip-File and Entry.</para> /// </summary> private GLSLShader LoadShaderFrom(ZipFile zipFile, ZipEntry shaderEntry) { string ResourceName = Path.GetFileNameWithoutExtension(shaderEntry.Name).ToLowerInvariant(); var byteBuffer = new byte[zipBufferSize]; Stream zipStream = zipFile.GetInputStream(shaderEntry); GLSLShader loadedShader; //Will throw exception if missing or wrong password. Handle this. if (shaderEntry.Name.Contains(".frag")) { FragmentShader = new MemoryStream(); StreamUtils.Copy(zipStream, FragmentShader, byteBuffer); FragmentShader.Position = 0; } if (shaderEntry.Name.Contains(".vert")) { VertexShader = new MemoryStream(); StreamUtils.Copy(zipStream, VertexShader, byteBuffer); VertexShader.Position = 0; } if (VertexShader != null && FragmentShader != null) { loadedShader = new GLSLShader(VertexShader, FragmentShader); loadedShader.ResourceName = ResourceName; VertexShader.Dispose(); FragmentShader.Dispose(); VertexShader = null; FragmentShader = null; } else { loadedShader = null; } zipStream.Close(); zipStream.Dispose(); return(loadedShader); }
public static ShaderProgram CreateLineShaderProgram(RenderContext renderContext, string label = "Line ShaderProgram") { VertexShader vertexShader = new VertexShader(renderContext, @"#version 330 core layout (location = 0) in vec2 aPos; layout (location = 1) in vec4 aColor; out vec4 Color; uniform mat4 projection; void main() { gl_Position = projection * vec4(aPos, 1.0, 1.0); Color = aColor; }"); FragmentShader fragmentShader = new FragmentShader(renderContext, @"#version 330 core out vec4 FragColor; in vec4 Color; void main() { FragColor = Color; }"); ShaderProgram shaderProgram = new ShaderProgram(renderContext); shaderProgram.AttachShader(vertexShader); shaderProgram.AttachShader(fragmentShader); shaderProgram.Link(); shaderProgram.DetachShader(vertexShader); shaderProgram.DetachShader(fragmentShader); vertexShader.Dispose(); fragmentShader.Dispose(); shaderProgram.Label = label; return(shaderProgram); }
protected virtual void Dispose(bool disposing) { if (ProgramId != 0) { GL.DetachShader(ProgramId, VertexShader.ShaderID); GL.DetachShader(ProgramId, FragmentShader.ShaderID); GL.DeleteProgram(ProgramId); if (DisposeChildren) { VertexShader.Dispose(); FragmentShader.Dispose(); } ProgramId = 0; } }
protected override void Dispose(bool isDisposing) { if (!GraphicsDevice.IsDisposed) { if (VertexShader != null) { GL.DetachShader(ProgramID, VertexShader.ID); VertexShader.Dispose(); } if (FragmentShader != null) { GL.DetachShader(ProgramID, FragmentShader.ID); FragmentShader.Dispose(); } GL.DeleteProgram(ProgramID); } }
public static ShaderProgram CreateShaderProgram(RenderContext renderContext) { VertexShader vertexShader = CreateVertexShader(renderContext); FragmentShader fragmentShader = CreateFragmentShader(renderContext); ShaderProgram shaderProgram = new ShaderProgram(renderContext); shaderProgram.AttachShader(vertexShader); shaderProgram.AttachShader(fragmentShader); shaderProgram.Link(); shaderProgram.DetachShader(vertexShader); shaderProgram.DetachShader(fragmentShader); vertexShader.Dispose(); fragmentShader.Dispose(); shaderProgram.Label = "IMGUI ShaderProgram"; return(shaderProgram); }
public void Dispose() { if (ProgramID != 0) { // Make sure this program isn't being used if (GLShortcut.CurrentProgram == ProgramID) { Gl.UseProgram(0); } Gl.DetachShader(ProgramID, VertexShader.ShaderID); Gl.DetachShader(ProgramID, FragmentShader.ShaderID); Gl.DeleteProgram(ProgramID); if (DisposeChildren) { VertexShader.Dispose(); FragmentShader.Dispose(); } this.ProgramID = 0; } }
public void Dispose() { // TODO: Move this to GL_Cleanup if (ProgramID != 0) { // Make sure this program isn't being used if (GL.CurrentProgram == ProgramID) { GL.UseProgram(0); } GL.DetachShader(ProgramID, VertexShader.ShaderID); GL.DetachShader(ProgramID, FragmentShader.ShaderID); GL.DeleteProgram(ProgramID); if (DisposeChildren) { VertexShader.Dispose(); FragmentShader.Dispose(); } this.ProgramID = 0; } }
private static unsafe void MasterThreadStart() { string instDir = Environment.GetCommandLineArgs().Length > 1 ? Environment.GetCommandLineArgs()[1] : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles, Environment.SpecialFolderOption.None), @"Egodystonic\Escape Lizards\Inst\"); string dataDir = Environment.GetCommandLineArgs().Length > 2 ? Environment.GetCommandLineArgs()[2] : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create), @"Egodystonic\Escape Lizards\Data"); Monitor.Enter(staticMutationLock); LosgapSystem.ApplicationName = "SEL Editor"; LosgapSystem.InstallationDirectory = new DirectoryInfo(instDir); LosgapSystem.MutableDataDirectory = new DirectoryInfo(dataDir); if (!LosgapSystem.IsModuleAdded(typeof(RenderingModule))) { LosgapSystem.AddModule(typeof(RenderingModule)); } if (!LosgapSystem.IsModuleAdded(typeof(InputModule))) { LosgapSystem.AddModule(typeof(InputModule)); } if (!LosgapSystem.IsModuleAdded(typeof(EntityModule))) { LosgapSystem.AddModule(typeof(EntityModule)); } LosgapSystem.MaxThreadCount = 1U; RenderingModule.VSyncEnabled = true; // Just a nice default for an editor I think #region Create window + shaders AssetLocator.MainWindow = new Window("SEL Editor Main Window", (uint)(1920f * 0.75f), (uint)(1080f * 0.75f), WindowFullscreenState.NotFullscreen); AssetLocator.MainWindow.ClearViewports().ForEach(vp => vp.Dispose()); AssetLocator.MainWindow.AddViewport(ViewportAnchoring.Centered, Vector2.ZERO, Vector2.ONE, Config.DisplayWindowNearPlane, Config.DisplayWindowFarPlane); AssetLocator.GameLayer = Scene.CreateLayer("Main Layer"); AssetLocator.SkyLayer = Scene.CreateLayer("Sky Layer"); AssetLocator.HudLayer = Scene.CreateLayer("HUD Layer"); ConstantBuffer <GeomPassProjViewMatrices> vsCameraBuffer = BufferFactory.NewConstantBuffer <GeomPassProjViewMatrices>().WithUsage(ResourceUsage.DiscardWrite); AssetLocator.MainGeometryVertexShader = new VertexShader( Path.Combine(AssetLocator.ShadersDir, "DLGeometryVS.cso"), new VertexInputBinding(0U, "INSTANCE_TRANSFORM"), new ConstantBufferBinding(0U, "CameraTransform", vsCameraBuffer), new VertexInputBinding(1U, "TEXCOORD"), new VertexInputBinding(2U, "POSITION"), new VertexInputBinding(3U, "NORMAL"), new VertexInputBinding(4U, "TANGENT") ); AssetLocator.SkyVertexShader = new VertexShader( Path.Combine(AssetLocator.ShadersDir, "DLGeometryVSSky.cso"), new VertexInputBinding(0U, "INSTANCE_TRANSFORM"), new ConstantBufferBinding(0U, "CameraTransform", vsCameraBuffer), new VertexInputBinding(1U, "TEXCOORD"), new VertexInputBinding(2U, "POSITION"), new VertexInputBinding(3U, "NORMAL"), new VertexInputBinding(4U, "TANGENT") ); ConstantBuffer <Vector4> matPropsBuffer = BufferFactory.NewConstantBuffer <Vector4>().WithUsage(ResourceUsage.DiscardWrite); TextureSampler defaultDiffuseSampler = new TextureSampler( TextureFilterType.Anisotropic, TextureWrapMode.Wrap, AnisotropicFilteringLevel.FourTimes ); TextureSampler shadowSampler = new TextureSampler( TextureFilterType.MinMagMipLinear, TextureWrapMode.Clamp, AnisotropicFilteringLevel.FourTimes ); AssetLocator.GeometryFragmentShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "DLGeometryFS.cso"), new ResourceViewBinding(0U, "DiffuseMap"), new ResourceViewBinding(1U, "NormalMap"), new ResourceViewBinding(2U, "SpecularMap"), new ResourceViewBinding(3U, "EmissiveMap"), new ResourceViewBinding(4U, "ShadowMap"), new TextureSamplerBinding(0U, "DiffuseSampler"), new TextureSamplerBinding(1U, "ShadowSampler"), new ConstantBufferBinding(0U, "MaterialProperties", matPropsBuffer) ); AssetLocator.GeometryFragmentShader.GetBindingByIdentifier("DiffuseSampler").Bind(defaultDiffuseSampler); AssetLocator.GeometryFragmentShader.GetBindingByIdentifier("ShadowSampler").Bind(shadowSampler); AssetLocator.SkyGeometryFragmentShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "DLGeometryFSSky.cso"), new ResourceViewBinding(0U, "DiffuseMap"), new TextureSamplerBinding(0U, "DiffuseSampler"), new ConstantBufferBinding(0U, "MaterialProperties", matPropsBuffer) ); AssetLocator.SkyGeometryFragmentShader.GetBindingByIdentifier("DiffuseSampler").Bind(defaultDiffuseSampler); ConstantBuffer <Vector4> lightVSScalarsBuffer = BufferFactory.NewConstantBuffer <Vector4>().WithUsage(ResourceUsage.DiscardWrite); VertexShader lightVS = new VertexShader( Path.Combine(AssetLocator.ShadersDir, "DLLightingVS.cso"), new VertexInputBinding(0U, "POSITION"), new VertexInputBinding(1U, "TEXCOORD"), new ConstantBufferBinding(0U, "Scalars", lightVSScalarsBuffer) ); ConstantBuffer <Vector4> fsCameraBuffer = BufferFactory.NewConstantBuffer <Vector4>().WithUsage(ResourceUsage.DiscardWrite); ConstantBuffer <Vector4> lightMetaBuffer = BufferFactory.NewConstantBuffer <Vector4>().WithUsage(ResourceUsage.DiscardWrite); FragmentShader lightFS = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "DLLightingFS.cso"), new ResourceViewBinding(0U, "NormalGB"), new ResourceViewBinding(1U, "DiffuseGB"), new ResourceViewBinding(2U, "SpecularGB"), new ResourceViewBinding(3U, "PositionGB"), new ResourceViewBinding(5U, "EmissiveGB"), new ConstantBufferBinding(0U, "CameraProperties", fsCameraBuffer), new ConstantBufferBinding(1U, "LightMeta", lightMetaBuffer), new ResourceViewBinding(4U, "LightBuffer"), new TextureSamplerBinding(0U, "NormalSampler") ); FragmentShader dlFinalizationFS = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "DLFinalFS.cso"), new ResourceViewBinding(1U, "DiffuseGB") ); TextureSampler normalSampler = new TextureSampler( TextureFilterType.Anisotropic, TextureWrapMode.Wrap, AnisotropicFilteringLevel.FourTimes ); Buffer <LightProperties> lightBuffer = BufferFactory.NewBuffer <LightProperties>() .WithLength(DLLightPass.MAX_DYNAMIC_LIGHTS) .WithUsage(ResourceUsage.DiscardWrite) .WithPermittedBindings(GPUBindings.ReadableShaderResource); ShaderBufferResourceView lightBufferView = lightBuffer.CreateView(); ((TextureSamplerBinding)lightFS.GetBindingByIdentifier("NormalSampler")).Bind(normalSampler); ((ResourceViewBinding)lightFS.GetBindingByIdentifier("LightBuffer")).Bind(lightBufferView); FragmentShader outliningShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "Outliner.cso"), new ResourceViewBinding(0U, "NormalGB"), new ResourceViewBinding(1U, "GeomDepthBuffer") ); FragmentShader bloomHShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "BloomH.cso"), new ResourceViewBinding(0U, "PreBloomImage") ); FragmentShader bloomVShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "BloomV.cso"), new ResourceViewBinding(0U, "PreBloomImage") ); FragmentShader glowShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "Glow.cso"), new ResourceViewBinding(0U, "GlowSrc") ); FragmentShader copyShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "Copy.cso"), new ResourceViewBinding(0U, "SourceTex"), new TextureSamplerBinding(0U, "SourceSampler") ); FragmentShader copyReverseShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "CopyReverse.cso"), new ResourceViewBinding(0U, "SourceTex"), new TextureSamplerBinding(0U, "SourceSampler") ); FragmentShader blurShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "Blur.cso"), new ResourceViewBinding(0U, "UnblurredScene") ); ConstantBuffer <Vector4> dofLensPropsBuffer = BufferFactory.NewConstantBuffer <Vector4>() .WithUsage(ResourceUsage.DiscardWrite) .WithInitialData(new Vector4( Config.DisplayWindowNearPlane, Config.DisplayWindowFarPlane, 1000f, 12000f )); FragmentShader dofShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "DoF.cso"), new ResourceViewBinding(0U, "UnblurredScene"), new ResourceViewBinding(1U, "BlurredScene"), new ResourceViewBinding(2U, "SceneDepth"), new TextureSamplerBinding(0U, "SourceSampler"), new ConstantBufferBinding(0U, "LensProperties", dofLensPropsBuffer) ); VertexShader shadowVS = new VertexShader( Path.Combine(AssetLocator.ShadersDir, "ShadowVS.cso"), new VertexInputBinding(0U, "INSTANCE_TRANSFORM"), new ConstantBufferBinding(0U, "CameraTransform", vsCameraBuffer), new VertexInputBinding(1U, "POSITION") ); FragmentShader shadowFS = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "ShadowFS.cso") ); VertexShader unlitVSSky = new VertexShader( Path.Combine(AssetLocator.ShadersDir, "UnlitVSSky.cso"), new VertexInputBinding(0U, "INSTANCE_TRANSFORM"), new ConstantBufferBinding(0U, "CameraTransform", vsCameraBuffer), new VertexInputBinding(1U, "TEXCOORD"), new VertexInputBinding(2U, "POSITION") ); AssetLocator.SkyFragmentShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "UnlitFS.cso"), new TextureSamplerBinding(0U, "DiffuseSampler"), new ResourceViewBinding(0U, "DiffuseMap") ); TextureSampler skyDiffuseSampler = new TextureSampler( TextureFilterType.Anisotropic, TextureWrapMode.Wrap, AnisotropicFilteringLevel.FourTimes ); ((TextureSamplerBinding)AssetLocator.SkyFragmentShader.GetBindingByIdentifier("DiffuseSampler")).Bind(skyDiffuseSampler); ConstantBuffer <Vector4> viewportPropertiesBuffer = BufferFactory.NewConstantBuffer <Vector4>().WithUsage(ResourceUsage.DiscardWrite); VertexShader hudVS = new VertexShader( Path.Combine(AssetLocator.ShadersDir, "HUDVS.cso"), new VertexInputBinding(0U, "INSTANCE_TRANSFORM"), new ConstantBufferBinding(1U, "CameraTransform", vsCameraBuffer), new ConstantBufferBinding(0U, "ViewportProperties", viewportPropertiesBuffer), new VertexInputBinding(1U, "TEXCOORD"), new VertexInputBinding(2U, "POSITION") ); ConstantBuffer <Vector4> hudFSColorBuffer = BufferFactory.NewConstantBuffer <Vector4>().WithUsage(ResourceUsage.DiscardWrite); AssetLocator.HUDFragmentShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "HUDFS.cso"), new ResourceViewBinding(0U, "DiffuseMap"), new TextureSamplerBinding(0U, "DiffuseSampler"), new ConstantBufferBinding(0U, "TextureProperties", hudFSColorBuffer) ); TextureSampler hudFSSampler = new TextureSampler( TextureFilterType.None, TextureWrapMode.Border, AnisotropicFilteringLevel.None, new TexelFormat.RGB32Float() { R = 1f, G = 0f, B = 0f } ); ((TextureSamplerBinding)AssetLocator.HUDFragmentShader.GetBindingByIdentifier("DiffuseSampler")).Bind(hudFSSampler); ConstantBuffer <Vector4> hudFSTextColorBuffer = BufferFactory.NewConstantBuffer <Vector4>().WithUsage(ResourceUsage.DiscardWrite); AssetLocator.HUDTextFragmentShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "HUDFSText.cso"), new ResourceViewBinding(0U, "DiffuseMap"), new TextureSamplerBinding(0U, "DiffuseSampler"), new ConstantBufferBinding(0U, "TextProperties", hudFSTextColorBuffer) ); TextureSampler hudTextSampler = new TextureSampler( TextureFilterType.None, TextureWrapMode.Border, AnisotropicFilteringLevel.None, new TexelFormat.RGB32Float() { R = 1f, G = 0f, B = 0f } ); ((TextureSamplerBinding)AssetLocator.HUDTextFragmentShader.GetBindingByIdentifier("DiffuseSampler")).Bind(hudTextSampler); var simpleFSSampler = new TextureSampler( Config.DefaultSamplingFilterType, TextureWrapMode.Wrap, Config.DefaultSamplingAnisoLevel ); var simpleFSMatPropsBuffer = BufferFactory.NewConstantBuffer <Vector4>().WithUsage(ResourceUsage.DiscardWrite).Create(); AssetLocator.AlphaFragmentShader = new FragmentShader( Path.Combine(AssetLocator.ShadersDir, "SimpleFS.cso"), new TextureSamplerBinding(0U, "DiffuseSampler"), new ResourceViewBinding(0U, "DiffuseMap"), new ConstantBufferBinding(0U, "MaterialProperties", simpleFSMatPropsBuffer) ); ((TextureSamplerBinding)AssetLocator.AlphaFragmentShader.GetBindingByIdentifier("DiffuseSampler")).Bind(simpleFSSampler); #endregion #region Create passes var shadowPass = new ShadowPass("Shadow Pass"); shadowPass.AddLayer(AssetLocator.GameLayer); shadowPass.ShadowVS = shadowVS; shadowPass.ShadowFS = shadowFS; shadowPass.Output = AssetLocator.MainWindow; AssetLocator.MainGeometryPass = new DLGeometryPass("Geometry Pass"); AssetLocator.MainGeometryPass.ClearOutputBeforePass = false; AssetLocator.MainGeometryPass.AddLayer(AssetLocator.GameLayer); AssetLocator.MainGeometryPass.AddLayer(AssetLocator.SkyLayer); AssetLocator.MainGeometryPass.DepthStencilState = new DepthStencilState(); AssetLocator.MainGeometryPass.Output = AssetLocator.MainWindow; AssetLocator.MainGeometryPass.BlendState = new BlendState(BlendOperation.None); AssetLocator.MainGeometryPass.RasterizerState = new RasterizerState(false, TriangleCullMode.BackfaceCulling, false); AssetLocator.MainGeometryPass.ShadowPass = shadowPass; AssetLocator.MainGeometryPass.GeomFSWithShadowSupport = AssetLocator.GeometryFragmentShader; AssetLocator.LightPass = new DLLightPass("Light Pass"); AssetLocator.LightPass.DLLightVertexShader = lightVS; AssetLocator.LightPass.DLLightFragmentShader = lightFS; AssetLocator.LightPass.DLLightFinalizationShader = dlFinalizationFS; AssetLocator.LightPass.BloomHShader = bloomHShader; AssetLocator.LightPass.BloomVShader = bloomVShader; AssetLocator.LightPass.CopyReverseShader = copyReverseShader; AssetLocator.LightPass.CopyShader = copyShader; AssetLocator.LightPass.OutliningShader = outliningShader; AssetLocator.LightPass.BlurShader = blurShader; AssetLocator.LightPass.DoFShader = dofShader; AssetLocator.LightPass.GeometryPass = AssetLocator.MainGeometryPass; AssetLocator.LightPass.PresentAfterPass = false; AssetLocator.LightPass.SetLensProperties(0f, float.MaxValue); HUDPass hudPass = new HUDPass("HUD") { DepthStencilState = new DepthStencilState(false), Input = new Camera(), Output = AssetLocator.MainWindow, PresentAfterPass = true, RasterizerState = new RasterizerState(false, TriangleCullMode.NoCulling, false), VertexShader = hudVS, BlendState = new BlendState(BlendOperation.Additive), GlowShader = glowShader, GlowVS = lightVS, ScaleUpShader = copyReverseShader, ScaleDownShader = copyShader }; hudPass.AddLayer(AssetLocator.HudLayer); ConstantBufferBinding vpPropsBinding = (ConstantBufferBinding)hudVS.GetBindingByIdentifier("ViewportProperties"); hudPass.PrePass += pass => { Vector4 vpSizePx = ((SceneViewport)AssetLocator.MainWindow).SizePixels / 2f; vpPropsBinding.SetValue((byte *)(&vpSizePx)); }; AssetLocator.MainCamera = AssetLocator.MainGeometryPass.Input = new IlluminatingCamera(GameplayConstants.EGG_ILLUMINATION_RADIUS, Vector3.ONE); AssetLocator.ShadowcasterCamera = shadowPass.LightCam = new Camera(); AssetLocator.ShadowcasterCamera.OrthographicDimensions = new Vector3(1000f, 1000f, PhysicsManager.ONE_METRE_SCALED * 100f); RenderingModule.AddRenderPass(shadowPass); RenderingModule.AddRenderPass(AssetLocator.MainGeometryPass); RenderingModule.AddRenderPass(AssetLocator.LightPass); RenderingModule.AddRenderPass(hudPass); #endregion #region HUD AssetLocator.MainFont = Font.Load(Path.Combine(AssetLocator.FontsDir, "mainFont.fnt"), AssetLocator.HUDTextFragmentShader, null, null); AssetLocator.TitleFont = Font.Load(Path.Combine(AssetLocator.FontsDir, "titleFont.fnt"), AssetLocator.HUDTextFragmentShader, null, null); #endregion #region Game Objects GeometryCacheBuilder <DefaultVertex> gameObjectGCB = new GeometryCacheBuilder <DefaultVertex>(); FragmentShader fs = AssetLocator.GeometryFragmentShader; // Load model streams var startFlagModelStream = AssetLoader.LoadModel(Path.Combine(AssetLocator.ModelsDir, "Spawn.obj")); var dynamicLightModelStream = AssetLoader.LoadModel(Path.Combine(AssetLocator.ModelsDir, "Lightbulb.obj")); var introCameraModelStream = AssetLoader.LoadModel(Path.Combine(AssetLocator.ModelsDir, "camera.obj")); var finishingBellModelStream = AssetLoader.LoadModel(Path.Combine(AssetLocator.ModelsDir, "FinishBellBottom.obj")); var vultureEggModelStream = AssetLoader.LoadModel(Path.Combine(AssetLocator.ModelsDir, "Playerball.obj")); var shadowcasterModelStream = AssetLoader.LoadModel(Path.Combine(AssetLocator.ModelsDir, "ScaleArrow.obj")); var coinModelStream = AssetLoader.LoadModel(Path.Combine(AssetLocator.ModelsDir, "LizardCoin.obj")); var finishingBellVerts = finishingBellModelStream.GetVertices <DefaultVertex>(typeof(DefaultVertex).GetConstructor(new[] { typeof(Vector3), typeof(Vector3), typeof(Vector3), typeof(Vector2) })).ToList(); var finishingBellIndices = finishingBellModelStream.GetIndices().ToList(); var vultureEggVerts = vultureEggModelStream.GetVertices <DefaultVertex>(typeof(DefaultVertex).GetConstructor(new[] { typeof(Vector3), typeof(Vector3), typeof(Vector3), typeof(Vector2) })).ToList(); var vultureEggIndices = vultureEggModelStream.GetIndices().ToList(); var coinModelVertices = coinModelStream.GetVertices <DefaultVertex>(typeof(DefaultVertex).GetConstructor(new[] { typeof(Vector3), typeof(Vector3), typeof(Vector3), typeof(Vector2) })); // Load models AssetLocator.StartFlagModel = gameObjectGCB.AddModel( "Game Object: Start Flag", startFlagModelStream.GetVertices <DefaultVertex>(typeof(DefaultVertex).GetConstructor(new[] { typeof(Vector3), typeof(Vector3), typeof(Vector3), typeof(Vector2) })).ToList(), startFlagModelStream.GetIndices().ToList() ); AssetLocator.DynamicLightModel = gameObjectGCB.AddModel( "Game Object: Dynamic Light", dynamicLightModelStream.GetVertices <DefaultVertex>(typeof(DefaultVertex).GetConstructor(new[] { typeof(Vector3), typeof(Vector3), typeof(Vector3), typeof(Vector2) })).ToList(), dynamicLightModelStream.GetIndices().ToList() ); AssetLocator.IntroCameraModel = gameObjectGCB.AddModel( "Game Object: Intro Camera Attracter", introCameraModelStream.GetVertices <DefaultVertex>(typeof(DefaultVertex).GetConstructor(new[] { typeof(Vector3), typeof(Vector3), typeof(Vector3), typeof(Vector2) })).ToList(), introCameraModelStream.GetIndices().ToList() ); AssetLocator.FinishingBellModel = gameObjectGCB.AddModel( "Game Object: Finishing Bell", finishingBellVerts, finishingBellIndices ); AssetLocator.VultureEggModel = gameObjectGCB.AddModel( "Game Object: Vulture Egg", vultureEggVerts, vultureEggIndices ); AssetLocator.ShadowcasterModel = gameObjectGCB.AddModel( "Game Object: Shadowcaster", shadowcasterModelStream.GetVerticesWithoutTangents <DefaultVertex>(typeof(DefaultVertex).GetConstructor(new[] { typeof(Vector3), typeof(Vector3), typeof(Vector2) })).ToList(), shadowcasterModelStream.GetIndices().ToList() ); AssetLocator.LizardCoinModel = gameObjectGCB.AddModel( "Game Object: Lizard Coin", coinModelVertices, coinModelStream.GetIndices() ); // Set materials AssetLocator.StartFlagMaterial = new Material("Game Object Mat: Start Flag", fs); AssetLocator.StartFlagMaterial.SetMaterialResource( (ResourceViewBinding)fs.GetBindingByIdentifier("DiffuseMap"), AssetLocator.LoadTexture("Spawn_bake.jpg").CreateView() ); AssetLocator.StartFlagMaterial.SetMaterialConstantValue( (ConstantBufferBinding)fs.GetBindingByIdentifier("MaterialProperties"), new Vector4(0f, 0f, 0f, 1f) ); AssetLocator.DynamicLightMaterial = new Material("Game Object Mat: Dynamic Light", fs); AssetLocator.DynamicLightMaterial.SetMaterialResource( (ResourceViewBinding)fs.GetBindingByIdentifier("DiffuseMap"), AssetLocator.LoadTexture("Bulb_bake.jpg").CreateView() ); AssetLocator.DynamicLightMaterial.SetMaterialConstantValue( (ConstantBufferBinding)fs.GetBindingByIdentifier("MaterialProperties"), new Vector4(0f, 0f, 0f, 1f) ); AssetLocator.IntroCameraMaterial = new Material("Game Object Mat: Intro Camera", fs); AssetLocator.IntroCameraMaterial.SetMaterialResource( (ResourceViewBinding)fs.GetBindingByIdentifier("DiffuseMap"), AssetLocator.LoadTexture("Camera_colo.png").CreateView() ); AssetLocator.IntroCameraMaterial.SetMaterialConstantValue( (ConstantBufferBinding)fs.GetBindingByIdentifier("MaterialProperties"), new Vector4(0f, 0f, 0f, 1f) ); AssetLocator.FinishingBellMaterial = new Material("Game Object Mat: Finishing Bell", fs); AssetLocator.FinishingBellMaterial.SetMaterialResource( (ResourceViewBinding)fs.GetBindingByIdentifier("DiffuseMap"), AssetLocator.LoadTexture("FinishBellBottom_bake.png").CreateView() ); AssetLocator.FinishingBellMaterial.SetMaterialConstantValue( (ConstantBufferBinding)fs.GetBindingByIdentifier("MaterialProperties"), new Vector4(1f, 1f, 0.8f, 1f) ); AssetLocator.VultureEggMaterial = new Material("Game Object Mat: Vulture Egg", fs); AssetLocator.VultureEggMaterial.SetMaterialResource( (ResourceViewBinding)fs.GetBindingByIdentifier("DiffuseMap"), AssetLocator.LoadTexture("VEggTexture.png").CreateView() ); AssetLocator.VultureEggMaterial.SetMaterialConstantValue( (ConstantBufferBinding)fs.GetBindingByIdentifier("MaterialProperties"), new Vector4(1f, 1f, 0.8f, 1f) ); AssetLocator.ShadowcasterMaterial = new Material("Game Object Mat: Shadowcaster", fs); AssetLocator.ShadowcasterMaterial.SetMaterialResource( (ResourceViewBinding)fs.GetBindingByIdentifier("DiffuseMap"), AssetLocator.LoadTexture("Default_s.bmp").CreateView() ); AssetLocator.ShadowcasterMaterial.SetMaterialConstantValue( (ConstantBufferBinding)fs.GetBindingByIdentifier("MaterialProperties"), new Vector4(0f, 0f, 0f, 1f) ); AssetLocator.LizardCoinMaterial = new Material("Game Object Mat: Lizard Coin", AssetLocator.GeometryFragmentShader); AssetLocator.LizardCoinMaterial.SetMaterialResource( (ResourceViewBinding)AssetLocator.GeometryFragmentShader.GetBindingByIdentifier("DiffuseMap"), AssetLocator.LoadTexture("LizardCoin.png", true).CreateView() ); AssetLocator.LizardCoinMaterial.SetMaterialResource( (ResourceViewBinding)AssetLocator.GeometryFragmentShader.GetBindingByIdentifier("SpecularMap"), AssetLocator.LoadTexture("LizardCoin_s.png", true).CreateView() ); AssetLocator.LizardCoinMaterial.SetMaterialResource( (ResourceViewBinding)AssetLocator.GeometryFragmentShader.GetBindingByIdentifier("NormalMap"), AssetLocator.LoadTexture("LizardCoin_n.png", true).CreateView() ); AssetLocator.LizardCoinMaterial.SetMaterialResource( (ResourceViewBinding)AssetLocator.GeometryFragmentShader.GetBindingByIdentifier("EmissiveMap"), AssetLocator.LoadTexture("LizardCoin_e.png", true).CreateView() ); AssetLocator.LizardCoinMaterial.SetMaterialConstantValue( (ConstantBufferBinding)AssetLocator.GeometryFragmentShader.GetBindingByIdentifier("MaterialProperties"), Vector4.ONE ); AssetLocator.FinishingBellPhysicsShape = PhysicsManager.CreateConcaveHullShape( finishingBellVerts.Select(df => df.Position), finishingBellIndices.Select(i => (int)i), new CollisionShapeOptionsDesc(), AssetLocator.CreateACDFilePath("finishingBell") ); AssetLocator.VultureEggPhysicsShape = PhysicsManager.CreateConcaveHullShape( vultureEggVerts.Select(df => df.Position), vultureEggIndices.Select(i => (int)i), new CollisionShapeOptionsDesc(), AssetLocator.CreateACDFilePath("vultureEgg") ); AssetLocator.LizardCoinShape = PhysicsManager.CreateConvexHullShape( coinModelVertices.Select(v => v.Position), new CollisionShapeOptionsDesc(Vector3.ONE) ); // Build gameObjectCache = gameObjectGCB.Build(); AssetLocator.MainGeometryPass.SetVSForCache(gameObjectCache, AssetLocator.MainGeometryVertexShader); #endregion #region Misc AssetLocator.UnitSphereShape = PhysicsManager.CreateSimpleSphereShape(1f, new CollisionShapeOptionsDesc(Vector3.ONE)); AssetLocator.DefaultNormalMapView = AssetLocator.LoadTexture("Default_n.bmp").CreateView(); AssetLocator.DefaultSpecularMapView = AssetLocator.LoadTexture("Default_s.bmp").CreateView(); AssetLocator.DefaultEmissiveMapView = AssetLocator.LoadTexture("Default_e.bmp").CreateView(); #endregion AssetLocator.MainWindow.WindowClosed += w => LosgapSystem.Exit(); Monitor.Pulse(staticMutationLock); Monitor.Exit(staticMutationLock); LosgapSystem.Start(); #region Disposal AssetLocator.UnitSphereShape.Dispose(); gameObjectCache.Dispose(); AssetLocator.IntroCameraMaterial.Dispose(); AssetLocator.DynamicLightMaterial.Dispose(); AssetLocator.StartFlagMaterial.Dispose(); AssetLocator.MainFont.Dispose(); hudPass.DepthStencilState.Dispose(); hudPass.Input.Dispose(); hudPass.RasterizerState.Dispose(); hudPass.BlendState.Dispose(); hudPass.Dispose(); AssetLocator.LightPass.Dispose(); AssetLocator.MainGeometryPass.DepthStencilState.Dispose(); AssetLocator.MainGeometryPass.RasterizerState.Dispose(); AssetLocator.MainGeometryPass.Dispose(); AssetLocator.MainCamera.Dispose(); hudTextSampler.Dispose(); AssetLocator.HUDFragmentShader.Dispose(); hudVS.Dispose(); shadowVS.Dispose(); shadowFS.Dispose(); viewportPropertiesBuffer.Dispose(); skyDiffuseSampler.Dispose(); AssetLocator.SkyFragmentShader.Dispose(); unlitVSSky.Dispose(); normalSampler.Dispose(); dofShader.Dispose(); blurShader.Dispose(); copyReverseShader.Dispose(); copyShader.Dispose(); glowShader.Dispose(); bloomHShader.Dispose(); bloomVShader.Dispose(); outliningShader.Dispose(); dlFinalizationFS.Dispose(); lightFS.Dispose(); lightBufferView.Dispose(); lightBuffer.Dispose(); lightMetaBuffer.Dispose(); fsCameraBuffer.Dispose(); lightVS.Dispose(); AssetLocator.GeometryFragmentShader.Dispose(); shadowSampler.Dispose(); defaultDiffuseSampler.Dispose(); matPropsBuffer.Dispose(); AssetLocator.MainGeometryVertexShader.Dispose(); AssetLocator.SkyVertexShader.Dispose(); vsCameraBuffer.Dispose(); AssetLocator.HudLayer.Dispose(); AssetLocator.SkyLayer.Dispose(); AssetLocator.GameLayer.Dispose(); GC.KeepAlive(AssetLocator.MainWindow); #endregion }