Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* COMPATIBILITY
- - HLSL compilers
- - Cg compilers
- */
- /*
- Hyllian Smart-Blur Shader
- Copyright (C) 2011-2014 Hyllian/Jararaca - sergiogdb@gmail.com
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- // Control the blur changing this param (RGB values). Below the threshold, blur is applied for each color channel.
- // Threshold is the max color differency among the eight pixel neighbors from central pixel.
- const static float3 threshold = float3(0.2, 0.2, 0.2);
- bool eq(float3 c1, float3 c2) {
- return all(abs(c1 - c2) < threshold);
- }
- struct input
- {
- float2 video_size;
- float2 texture_size;
- float2 output_size;
- float frame_count;
- float frame_direction;
- float frame_rotation;
- };
- /*
- A1 B1
- A B C C4
- D0 D E F F4
- G0 G H I
- H5 I5
- f = (C + C4 + F + F4)/4; // and so on... to get four texture colors in only one fetch using linear filtering.
- */
- struct out_vertex {
- float2 texCoord;
- };
- /* VERTEX_SHADER */
- out_vertex main_vertex
- (
- float4 position : POSITION,
- out float4 oPosition : POSITION,
- float2 tex : TEXCOORD0,
- uniform float4x4 modelViewProj,
- uniform input IN
- )
- {
- oPosition = mul(modelViewProj, position);
- out_vertex OUT = {
- tex
- };
- return OUT;
- }
- float4 main_fragment(in out_vertex VAR, uniform sampler2D s_p : TEXUNIT0, uniform input IN) : COLOR
- {
- float2 dx = float2(1.0/IN.texture_size.x, 0.0);
- float2 dy = float2(0.0, 1.0/IN.texture_size.y);
- float2 pix_upper_left = floor(VAR.texCoord*IN.texture_size);
- float2 tc = (pix_upper_left+float2(0.5,0.5))/IN.texture_size;
- pix_upper_left /= IN.texture_size;
- float3 E = tex2D(s_p, tc).xyz;
- float3 f = tex2D(s_p, pix_upper_left+2.0*dx ).xyz;
- float3 b = tex2D(s_p, pix_upper_left -dy).xyz;
- float3 d = tex2D(s_p, pix_upper_left -dx +dy).xyz;
- float3 h = tex2D(s_p, pix_upper_left +dx+2.0*dy).xyz;
- if (eq(E,f) && eq(E,h) && eq(E,b) && eq(E,d)) {
- E = (E+f+b+d+h)/5.0;
- }
- return float4(E, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement