<commit_before>/// <reference path="../Prefix.d.ts" />
/// <reference path="../core/RenderBuffers.ts" />
/// <reference path="../core/RendererCore.ts" />
/// <reference path="../core/GLFramebuffer.ts" />
/// <reference path="../utils/Geometry.ts" />
/// <reference path="BlurFilter.ts" />
/// <reference path="SimpleOps.ts" />
/// <reference path="ResampleFilter.ts" />
module Hyper.Renderer
{
	export interface BloomFilterParameters
	{
		amount: number;
		saturation: number;
	}
	export class BloomFilterRenderer
	{
		params: BloomFilterParameters;
		
		private blurFlt: GaussianBlurFilterRenderer;
		private resampler: ResampleFilterRenderer;
		private adder: BufferAdder;
		
		constructor(public renderer: RendererCore)
		{
			this.params = {
				amount: 0.5,
				saturation: 1
			};
			
			this.resampler = new ResampleFilterRenderer(renderer);
			this.blurFlt = new GaussianBlurFilterRenderer(renderer);
			this.adder = new BufferAdder(renderer);
		}
		
		dispose(): void
		{
		}
		
		setupFilter<T extends LogRGBTextureRenderBufferInfo | LinearRGBTextureRenderBufferInfo>
		(input: T, ops: RenderOperation[]): T
		{
			
			// convert input to linear RGB.
			// hope that GPU supports sRGB buffer... (or we'll lose much precision)
			let ds0: LinearRGBTextureRenderBufferInfo;
			
			let prescaling: number = 1 / 128;
			if (!this.renderer.supportsSRGB) {
				prescaling = 1 / 16;
			}
			if (input instanceof LinearRGBTextureRenderBufferInfo) {
				prescaling = 1;
			}
			
			if (input instanceof LogRGBTextureRenderBufferInfo) {
				ds0 = new LinearRGBTextureRenderBufferInfo("Bloom 1/2", 
						(input.width + 1) >> 1, (input.height + 1) >> 1,
						input.format);
				ops.push({
					inputs: {
						input: input
					},
					outputs: {
						output: ds0
					},
					bindings: [],
					optionalOutputs: [],
					name: `Resample and Convert To Linear RGB`,
					factory: (cfg) => new BloomDownsampleRenderer(this,
						<TextureRenderBuffer> cfg.inputs['input'],
						<TextureRenderBuffer> cfg.outputs['output'],
						prescaling)
				});
			} else {
				// already linear
				ds0 = this.resampler.setupLinearResampler(input, {
					outWidth: (input.width + 1) >> 1,
					outHeight: (input.height + 1) >> 1
				}, ops);
				ds0.name = "Bloom 1/2";
			}
			
			const levels: LinearRGBTextureRenderBufferInfo[] = [];
			let prev = ds0;
			for (let i = 0; i < 6; ++i) { 
				let size = 4 << i;
				if (input.width < size * 4 || input.height < size * 4) {
					break;
				}
				const ds = this.resampler.setupLinearResampler(prev, {
					outWidth: (input.width + size - 1) >> (i + 2),
					outHeight: (input.height + size - 1) >> (i + 2)
				}, ops);
				ds.name = `Bloom 1/${size}`;
				
				if (i < 1) {
					prev = ds;
					continue;
				}
				const lp = this.blurFlt.setupFilter(ds, 1, ops);
				lp.name = `Bloom 1/${size} LPFed`;
				levels.push(lp);
				prev = lp;
			}
			
			// blend all levels (they're linear color so can be blended with BufferAdded)
			for (let i = levels.length - 2; i >= 0; --i) {
				let lum = 1.5;
				prev = this.adder.setupFilter(levels[i], prev, 
					new THREE.Vector4(lum, lum, lum, lum),
					ops);
			}
			
			// combine
			const outp = input instanceof LinearRGBTextureRenderBufferInfo ?
				new LinearRGBTextureRenderBufferInfo("Bloom Added", input.width, input.height,
					input.format) : 
				new LogRGBTextureRenderBufferInfo("Bloom Added", input.width, input.height,
					input.format);
			<commit_msg>Bloom filter: more gaussian blur radius to reduce linear-filtering artifact<commit_after>/// <reference path="../Prefix.d.ts" />
/// <reference path="../core/RenderBuffers.ts" />
/// <reference path="../core/RendererCore.ts" />
/// <reference path="../core/GLFramebuffer.ts" />
/// <reference path="../utils/Geometry.ts" />
/// <reference path="BlurFilter.ts" />
/// <reference path="SimpleOps.ts" />
/// <reference path="ResampleFilter.ts" />
module Hyper.Renderer
{
	export interface BloomFilterParameters
	{
		amount: number;
		saturation: number;
	}
	export class BloomFilterRenderer
	{
		params: BloomFilterParameters;
		
		private blurFlt: GaussianBlurFilterRenderer;
		private resampler: ResampleFilterRenderer;
		private adder: BufferAdder;
		
		constructor(public renderer: RendererCore)
		{
			this.params = {
				amount: 0.5,
				saturation: 1
			};
			
			this.resampler = new ResampleFilterRenderer(renderer);
			this.blurFlt = new GaussianBlurFilterRenderer(renderer);
			this.adder = new BufferAdder(renderer);
		}
		
		dispose(): void
		{
		}
		
		setupFilter<T extends LogRGBTextureRenderBufferInfo | LinearRGBTextureRenderBufferInfo>
		(input: T, ops: RenderOperation[]): T
		{
			
			// convert input to linear RGB.
			// hope that GPU supports sRGB buffer... (or we'll lose much precision)
			let ds0: LinearRGBTextureRenderBufferInfo;
			
			let prescaling: number = 1 / 128;
			if (!this.renderer.supportsSRGB) {
				prescaling = 1 / 16;
			}
			if (input instanceof LinearRGBTextureRenderBufferInfo) {
				prescaling = 1;
			}
			
			if (input instanceof LogRGBTextureRenderBufferInfo) {
				ds0 = new LinearRGBTextureRenderBufferInfo("Bloom 1/2", 
						(input.width + 1) >> 1, (input.height + 1) >> 1,
						input.format);
				ops.push({
					inputs: {
						input: input
					},
					outputs: {
						output: ds0
					},
					bindings: [],
					optionalOutputs: [],
					name: `Resample and Convert To Linear RGB`,
					factory: (cfg) => new BloomDownsampleRenderer(this,
						<TextureRenderBuffer> cfg.inputs['input'],
						<TextureRenderBuffer> cfg.outputs['output'],
						prescaling)
				});
			} else {
				// already linear
				ds0 = this.resampler.setupLinearResampler(input, {
					outWidth: (input.width + 1) >> 1,
					outHeight: (input.height + 1) >> 1
				}, ops);
				ds0.name = "Bloom 1/2";
			}
			
			const levels: LinearRGBTextureRenderBufferInfo[] = [];
			let prev = ds0;
			for (let i = 0; i < 6; ++i) { 
				let size = 4 << i;
				if (input.width < size * 4 || input.height < size * 4) {
					break;
				}
				const ds = this.resampler.setupLinearResampler(prev, {
					outWidth: (input.width + size - 1) >> (i + 2),
					outHeight: (input.height + size - 1) >> (i + 2)
				}, ops);
				ds.name = `Bloom 1/${size}`;
				
				if (i < 1) {
					prev = ds;
					continue;
				}
				const lp = this.blurFlt.setupFilter(ds, 2, ops);
				lp.name = `Bloom 1/${size} LPFed`;
				levels.push(lp);
				prev = lp;
			}
			
			// blend all levels (they're linear color so can be blended with BufferAdded)
			for (let i = levels.length - 2; i >= 0; --i) {
				let lum = 1.5;
				prev = this.adder.setupFilter(levels[i], prev, 
					new THREE.Vector4(lum, lum, lum, lum),
					ops);
			}
			
			// combine
			const outp = input instanceof LinearRGBTextureRenderBufferInfo ?
				new LinearRGBTextureRenderBufferInfo("Bloom Added", input.width, input.height,
					input.format) : 
				new LogRGBTextureRenderBufferInfo("Bloom Added", input.width, input.height,
					input.format);
			
{'fraction_non_alphanumeric': 0.13970166379804935, 'fraction_numerical': 0.013482501434308663, 'mean_word_length': 2.7671528903295517, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2213037', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2248, 'n_words': 553}