From b197a865a4a1dd3bc721f36e00a07e61b40a6783 Mon Sep 17 00:00:00 2001 From: Exeldro Date: Sat, 11 Nov 2023 15:49:14 +0100 Subject: [PATCH] improve shaders --- data/examples/Add.shader | 2 +- data/examples/burn.shader | 2 +- data/examples/gaussian-example.effect | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/data/examples/Add.shader b/data/examples/Add.shader index 27bc1f079..176189026 100644 --- a/data/examples/Add.shader +++ b/data/examples/Add.shader @@ -4,5 +4,5 @@ float4 mainImage(VertData v_in) : TARGET { float4 other = other_image.Sample(textureSampler, v_in.uv); float4 base = image.Sample(textureSampler, v_in.uv); - return base + other; + return clamp(base + other, 0.0, 1.0); } diff --git a/data/examples/burn.shader b/data/examples/burn.shader index 4406ed6fb..3f7e5a246 100644 --- a/data/examples/burn.shader +++ b/data/examples/burn.shader @@ -22,7 +22,7 @@ float2 fade(float2 t) { } float dot(float2 a,float2 b){ - return a.x*b.x+a.y+b.y; + return a.x*b.x+a.y*b.y; } // Classic Perlin noise diff --git a/data/examples/gaussian-example.effect b/data/examples/gaussian-example.effect index b2ce1a2b0..36d61ef51 100644 --- a/data/examples/gaussian-example.effect +++ b/data/examples/gaussian-example.effect @@ -12,7 +12,7 @@ uniform float2 uv_pixel_interval; '-------------------------*/ -texture2d initial_image; +uniform texture2d initial_image; sampler_state initial_sampler { Filter = Linear; @@ -22,7 +22,7 @@ sampler_state initial_sampler texture2d = initial_image; }; -texture2d before_image; +uniform texture2d before_image; sampler_state before_sampler { Filter = Linear; AddressU = Border; @@ -31,7 +31,7 @@ sampler_state before_sampler { texture2d = before_image; }; -texture2d after_image; +uniform texture2d after_image; sampler_state after_sampler { Filter = Linear; AddressU = Border; @@ -98,8 +98,8 @@ float4 gaussian(VertData v_in, float angle) ColorData setColorData(VertData v_in): SV_TARGET0 { - string RenderTarget0 = "initial_image"; - ColorData cd = (ColorData)0; + //string RenderTarget0 = "initial_image"; + ColorData cd;// = (ColorData)0; cd.initial_color = image.Sample(textureSampler, v_in.uv); cd.before_color = float4(0.0,0.0,1.0,1.0); cd.after_color = float4(1.0,0.0,0.0,1.0); @@ -108,7 +108,7 @@ ColorData setColorData(VertData v_in): SV_TARGET0 float4 blurImageH(VertData v_in) : SV_TARGET1 { - string RenderTarget1 = "before_image"; + //string RenderTarget1 = "before_image"; //ColorData cd = (ColorData)0; //cd.initial_color = image.Sample(textureSampler, v_in.uv); //cd.before_color = float4(0.0,0.0,1.0,1.0);//gaussian(v_in, 0); @@ -117,7 +117,7 @@ float4 blurImageH(VertData v_in) : SV_TARGET1 float4 blurImageV(VertData v_in) : SV_TARGET2 { - string RenderTarget2 = "after_image"; + //string RenderTarget2 = "after_image"; //ColorData cd = (ColorData)0; //cd.after_color = float4(1.0,0.0,0.0,1.0); //gaussian(v_in, 90); return float4(1.0,0.0,0.0,1.0); @@ -126,7 +126,7 @@ float4 blurImageV(VertData v_in) : SV_TARGET2 float4 mainImage(VertData v_in) : SV_TARGET0 { float4 color; - ColorData cd = (ColorData)0; + ColorData cd;// = (ColorData)0; //cd.initial_color = initial_image.Sample(initial_sampler, v_in.uv); //cd.before_color = before_image.Sample(before_sampler, v_in.uv); @@ -142,12 +142,12 @@ float4 mainImage(VertData v_in) : SV_TARGET0 float4 gray = grayscale(color); float4 gray_text = grayscale(text_color); float d = distance(gray.rgb, gray_text.rgb); - if (d <= dot(max_distance, uv_pixel_interval * max_distance)){ + if (d <= dot(max_distance, uv_pixel_interval.x * max_distance)){ float d_c = pow(d*2, exp) / pow(2, exp); d_c = sin(d_c * PI / 2); d = pow(1.0 - sin(d * PI/4), exp); - color.rgb = d; + color.rgb = float3(d,d,d); } return color;