public LightManager() { skyboxshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/SkyBoxVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/SkyBoxFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); ambientlightshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/AmbientLightFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); directionallightshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/DirectionalLightFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); pointlightshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/PointLightVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/PointLightFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); spotlightshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/SpotLightVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/Light/SpotLightFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); lightrenderer = new GenericLightRenderer(); }
protected internal override void OnLoad() { base.OnLoad(); renderTexture = new RenderTexture(MMW.RenderResolution); renderTexture.MagFilter = TextureMagFilter.Linear; renderTexture.MinFilter = TextureMinFilter.Linear; renderTexture.ColorFormat0 = MMW.Configuration.DefaultPixelFormat; renderTexture.Load(); ccShader = (GLSLShader)MMW.GetAsset <Shader>("Color Collect"); if (ccShader == null) { ccShader = new ColorCollectShader(); MMW.RegistAsset(ccShader); } loc_con = ccShader.GetUniformLocation("contrast"); loc_sat = ccShader.GetUniformLocation("saturation"); loc_brt = ccShader.GetUniformLocation("brightness"); loc_resolution = ccShader.GetUniformLocation("resolutionInverse"); loc_mvp = ccShader.GetUniformLocation("MVP"); if (GameObject != null) { Camera = GameObject.GetComponent <Camera>(); RenderTexture = Camera.TargetTexture; } orthoMatrix = Matrix4.CreateOrthographicOffCenter(-1, 1, -1, 1, -1, 1); }
public LightScatteringRenderer(int width, int height) { skyboxshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/SkyBoxVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/SunSkyBoxFragment.glsl", ShaderType.FragmentShader)) .Link(); radialblurshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/RadialBlurFragment.glsl", ShaderType.FragmentShader)) .Link(); finalshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/LightScatteringFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); colortexture = new Texture2D(width / 2, height / 2, PixelInternalFormat.R16, PixelFormat.Red, PixelType.UnsignedByte); colortexture.SetFiltering(TextureMinFilter.Linear, TextureMagFilter.Linear); framebuffer = new Framebuffer() .AttachTexture(colortexture, FramebufferAttachment.ColorAttachment0); framebuffer.CheckStatus(); framebuffer.Unbind(); colortexture2 = new Texture2D(width / 4, height / 4, PixelInternalFormat.R16, PixelFormat.Red, PixelType.UnsignedByte); colortexture2.SetFiltering(TextureMinFilter.Linear, TextureMagFilter.Linear); framebuffer2 = new Framebuffer() .AttachTexture(colortexture2, FramebufferAttachment.ColorAttachment0); framebuffer2.CheckStatus(); framebuffer2.Unbind(); this.width = width; this.height = height; }
public RenderStates(GLSLShader shader) { if (shader == null) { SFMLRenderStates = Default.SFMLRenderStates; } else { SFMLRenderStates = new SRenderStates(shader.SFMLShader); } }
public void LoadTestShader_ShouldDrawAllRed() { testRenderImage.BeginDrawing(); GLSLShader currshader = resources.GetShader("RedShader"); currshader.SetUniform("TextureUnit0", testsprite.Texture); currshader.setAsCurrentShader(); testsprite.Draw(); testRenderImage.EndDrawing(); currshader.ResetCurrentShader(); testRenderImage.Blit(0, 0, 1280, 720, Color.White, BlitterSizeMode.Crop); resources.GetSprite("flashlight_mask").Draw(); }
/// <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 void LoadContent() { reductionEffect = _resourceManager.GetShader("reductionEffect"); resolveShadowsEffect = _resourceManager.GetShader("resolveShadowsEffect"); //// BUFFER TYPES ARE VERY IMPORTANT HERE AND IT WILL BREAK IF YOU CHANGE THEM!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //distortRT = new RenderImage("distortRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferGR1616F); //distancesRT = new RenderImage("distancesRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferGR1616F); //shadowMap = new RenderImage("shadowMap" + baseSize, 2, baseSize, ImageBufferFormats.BufferGR1616F); reductionRT = new RenderImage[reductionChainCount]; for (int i = 0; i < reductionChainCount; i++) { reductionRT[i] = new RenderImage("reductionRT" + i + baseSize, 2 << i, baseSize, ImageBufferFormats.BufferGR1616F); } shadowsRT = new RenderImage("shadowsRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferRGB888A8); processedShadowsRT = new RenderImage("processedShadowsRT" + baseSize, baseSize, baseSize, ImageBufferFormats.BufferRGB888A8); }
public DeathPostProcessingEffect(float duration) : base(duration) { _shader = IoCManager.Resolve <IResourceCache>().GetShader("deathshader"); }
/// <summary> /// <para>Loads all Resources from given Zip into the respective Resource Lists and Caches</para> /// </summary> public void LoadResourceZip(string path = null, string pw = null) { string zipPath = path ?? _configurationManager.GetResourcePath(); string password = pw ?? _configurationManager.GetResourcePassword(); if (!File.Exists(zipPath)) { throw new FileNotFoundException("Specified Zip does not exist: " + zipPath); } FileStream zipFileStream = File.OpenRead(zipPath); var zipFile = new ZipFile(zipFileStream); if (!string.IsNullOrWhiteSpace(password)) { zipFile.Password = password; } var directories = from ZipEntry a in zipFile where a.IsDirectory orderby a.Name.ToLowerInvariant() == "textures" descending select a; Dictionary <string, List <ZipEntry> > sorted = new Dictionary <string, List <ZipEntry> >(); foreach (ZipEntry dir in directories) { if (sorted.ContainsKey(dir.Name.ToLowerInvariant())) { continue; //Duplicate folder? shouldnt happen. } List <ZipEntry> folderContents = (from ZipEntry entry in zipFile where entry.Name.ToLowerInvariant().Contains(dir.Name.ToLowerInvariant()) where entry.IsFile select entry).ToList(); sorted.Add(dir.Name.ToLowerInvariant(), folderContents); } sorted = sorted.OrderByDescending(x => x.Key == "textures/").ToDictionary(x => x.Key, x => x.Value); //Textures first. foreach (KeyValuePair <string, List <ZipEntry> > current in sorted) { switch (current.Key) { case ("textures/"): foreach (ZipEntry texture in current.Value) { if (supportedImageExtensions.Contains(Path.GetExtension(texture.Name).ToLowerInvariant())) { Image loadedImg = LoadImageFrom(zipFile, texture); if (loadedImg == null) { continue; } else { _images.Add(texture.Name, loadedImg); } } } break; case ("tai/"): // Tai? foreach (ZipEntry tai in current.Value) { if (Path.GetExtension(tai.Name).ToLowerInvariant() == ".tai") { IEnumerable <CluwneSprite> loadedSprites = LoadSpritesFrom(zipFile, tai); foreach (CluwneSprite currentSprite in loadedSprites.Where(currentSprite => !_sprites.ContainsKey(currentSprite.Name))) { _sprites.Add(currentSprite.Name, currentSprite); } } } break; case ("fonts/"): foreach (ZipEntry font in current.Value) { if (Path.GetExtension(font.Name).ToLowerInvariant() == ".ttf") { Font loadedFont = LoadFontFrom(zipFile, font); if (loadedFont == null) { continue; } string ResourceName = Path.GetFileNameWithoutExtension(font.Name).ToLowerInvariant(); _fonts.Add(ResourceName, loadedFont); } } break; case ("particlesystems/"): foreach (ZipEntry particles in current.Value) { if (Path.GetExtension(particles.Name).ToLowerInvariant() == ".xml") { ParticleSettings particleSettings = LoadParticlesFrom(zipFile, particles); if (particleSettings == null) { continue; } else { _particles.Add(Path.GetFileNameWithoutExtension(particles.Name), particleSettings); } } } break; case ("shaders/"): foreach (ZipEntry shader in current.Value) { if (Path.GetExtension(shader.Name).ToLowerInvariant() == ".vert" || Path.GetExtension(shader.Name).ToLowerInvariant() == ".frag") { GLSLShader loadedShader = LoadShaderFrom(zipFile, shader); if (loadedShader == null) { continue; } else { _shaders.Add(Path.GetFileNameWithoutExtension(shader.Name), loadedShader); } } } break; case ("animations/"): foreach (ZipEntry animation in current.Value) { if (Path.GetExtension(animation.Name).ToLowerInvariant() == ".xml") { AnimationCollection animationCollection = LoadAnimationCollectionFrom(zipFile, animation); if (animationCollection == null) { continue; } else { _animationCollections.Add(animationCollection.Name, animationCollection); } } } break; } } sorted = null; zipFile.Close(); zipFileStream.Close(); zipFileStream.Dispose(); GC.Collect(); }
private void LoadGame(object sender, EventArgs e) { GL.ClearColor(0, 0, 0, 0); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.ProgramPointSize); GL.Enable(EnableCap.CullFace); GL.PointSize(5); worldshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/WorldVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/WorldFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/WorldGeometry.glsl", ShaderType.GeometryShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.VertexShader)) .Link(); ppshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressFragment.glsl", ShaderType.FragmentShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GammaCorrection.glsl", ShaderType.FragmentShader)) .Link(); gaussianblurshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/GaussianBlurFragment.glsl", ShaderType.FragmentShader)) .Link(); bloomshader = new GLSLProgram() .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/PostProgressVertex.glsl", ShaderType.VertexShader)) .AttachShaderAndDelete(GLSLShader.FromFile("./Data/Shader/FX/BloomFragment.glsl", ShaderType.FragmentShader)) .Link(); gDepth = new Texture2D(Width, Height, PixelInternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float); gPosition = new Texture2D(Width, Height, PixelInternalFormat.Rgb32f, PixelFormat.Rgb, PixelType.Float); gNormal = new Texture2D(Width, Height, PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat); gAlbedo = new Texture2D(Width, Height, PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte); gLight = new Texture2D(Width, Height, PixelInternalFormat.Rgb, PixelFormat.Rgb, PixelType.UnsignedByte); gBuffer = new Framebuffer() .AttachTexture(gDepth, FramebufferAttachment.DepthAttachment) .AttachTexture(gPosition, FramebufferAttachment.ColorAttachment0) .AttachTexture(gNormal, FramebufferAttachment.ColorAttachment1) .AttachTexture(gAlbedo, FramebufferAttachment.ColorAttachment2) .AttachTexture(gLight, FramebufferAttachment.ColorAttachment3); GL.DrawBuffers(4, new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3 }); gBuffer.CheckStatus(); gBuffer.Unbind(); lightTexture = new Texture2D(Width, Height, PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat); lightTexture.SetWarpMode(TextureWrapMode.ClampToEdge); lightBuffer = new Framebuffer() .AttachTexture(lightTexture, FramebufferAttachment.ColorAttachment0); lightBuffer.CheckStatus(); lightBuffer.Unbind(); lightManager = new LightManager(); for (int i = 0; i < 2; i++) { blurTexture[i] = new Texture2D((int)(Width / 2f), (int)(Height / 2f), PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat); blurTexture[i].SetFiltering(TextureMinFilter.Linear, TextureMagFilter.Linear); blurFramebuffer[i] = new Framebuffer().AttachTexture(blurTexture[i], FramebufferAttachment.ColorAttachment0); if (!blurFramebuffer[i].CheckStatus()) { Console.WriteLine("Framebuffer error"); } blurFramebuffer[i].Unbind(); } bloomTexture = new Texture2D((int)(Width / 1f), (int)(Height / 1f), PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat); bloomTexture.SetFiltering(TextureMinFilter.Linear, TextureMagFilter.Linear); bloomFramebuffer = new Framebuffer().AttachTexture(bloomTexture, FramebufferAttachment.ColorAttachment0); if (!bloomFramebuffer.CheckStatus()) { Console.WriteLine("Framebuffer error"); } bloomFramebuffer.Unbind(); model = new ModelBatch(); lsr = new LightScatteringRenderer(Width, Height); }