/// <summary> /// This applys gamma /// </summary> /// <param name="attachment"></param> public static void FinalizeGamma(ColorAttachment attachment) { _gammaShader.Draw(u => { u["Gamma"].SetFloat(Gamma); u["Scene"].SetTexture(attachment); }); }
/// <summary> /// Draws the shader with the color attachment as texture and provides access to the uniforms. /// </summary> /// <param name="renderedTexture"></param> /// <param name="setUniformAction"></param> public void Draw(ColorAttachment renderedTexture, Action <UniformCollection> setUniformAction) { var texAction = DefaultTextureAction(renderedTexture); Draw((a) => { texAction(a); setUniformAction(a); }); }
/// <summary> /// This converts HDR to LDR and applys gamma. /// </summary> /// <param name="attachment"></param> /// <param name="exposure"></param> public static void FinalizeHDR(ColorAttachment attachment, HDRColorCurve colorCurve = HDRColorCurve.ACES, float exposure = 1) { _hdrExposureShader[colorCurve].Draw(u => { u["Gamma"].SetFloat(Gamma); u["Exposure"].SetFloat(exposure); u["Scene"].SetTexture(attachment); }); }
protected override void Drawing(ColorAttachment source, DrawContext context) { Arguments["_Scene"] = (TextureBase)source; Arguments["_MVP"] = Mvp; Arguments["_ViewportSize"] = context.Window.WindowSize; source.ConnectedFramebuffer.CopyTo(tempFramebuffer); tempFramebuffer.Activate(); _shader.Draw(Arguments); tempFramebuffer.CopyTo(source.ConnectedFramebuffer); }
/// <summary> /// Method to draw the actual effect. /// </summary> protected abstract void Drawing(ColorAttachment source, DrawContext context);
public void SaveColorAttachmentAsBmp(string filename) { ColorAttachment.SaveAsBmp(filename); }
/// <summary> /// Draws the shader with the color attachment as texture. /// </summary> /// <param name="renderedTexture"></param> public void Draw(ColorAttachment renderedTexture) { Draw(DefaultTextureAction(renderedTexture)); }
/// <inheritdoc/> protected override void Drawing(ColorAttachment source, DrawContext context) { Framebuffer target = Framebuffer.GetCurrentlyActive(); // Filtering _downsampler[0].Activate(true); shaders[0].Draw(source, col => { col["ThresholdCurve"].SetVector4(_thresholdCurve); }); // Downsampling ColorAttachment last = _downsampler[0]["0"]; for (int i = 1; i < _iterations; i++) { ColorAttachment downsampleSource = last; Framebuffer downsampleTarget = _downsampler[i]; downsampleTarget.Activate(true); shaders[1].Draw(downsampleSource); last = downsampleTarget["0"]; } // Upsampling for (int i = _iterations - 2; i >= 0; i--) { ColorAttachment downsampleSource = _downsampler[i]["0"]; Framebuffer upsampleTarget = _upsample[i]; upsampleTarget.Activate(true); shaders[2].Draw(last, (a) => { if (last != null) { a["baseBuffer"].SetTexture(downsampleSource); } a["sampleSize"].SetFloat(_sampleSize); }); last = upsampleTarget["0"]; } // combine target.Activate(true); shaders[3].Draw(last, (a) => { a["sampleSize"].SetFloat(_sampleSize); a["scene"].SetTexture(_downsampler[0]["1"]); a["bloomColor"].SetColor(_bloomColor); if (AmountMap != null) { a["amountTransform"].SetMatrix3(AmountMapTransform.GetMatrix()); a["amountMap"].SetTexture(AmountMap, a["hasAmountMap"]); a["amountLimit"].SetVector2((Vector2)AmountLimits); } a["HDR"].SetBool(_hdr); }); }