Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* COMPATIBILITY
- - HLSL compilers
- - Cg compilers
- */
- /*
- Hyllian's Unblend 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.
- */
- float c_df(float3 c1, float3 c2)
- {
- float3 df = abs(c1 - c2);
- return df.r + df.g + df.b;
- // return 2*df.r + 3*df.g + df.b;
- }
- float3 bestfit(float3 ca, float3 cb, float3 cref)
- {
- // return lerp(ca, cb, step(c_df(cref, cb), c_df(cref, ca)));
- return lerp(min(ca, cb), max(ca, cb), step((ca+cb)*0.5, cref));
- }
- struct orig
- {
- float2 tex_coord;
- uniform float2 texture_size;
- uniform sampler2D texture;
- };
- struct input
- {
- float2 video_size;
- float2 texture_size;
- float2 output_size;
- float frame_count;
- float frame_direction;
- float frame_rotation;
- };
- struct out_vertex {
- float4 position : POSITION;
- float4 color : COLOR;
- float2 texCoord : TEXCOORD0;
- float2 orig_tex;
- };
- /* VERTEX_SHADER */
- void main_vertex
- (
- float4 position : POSITION,
- float4 color : COLOR,
- float2 texCoord : TEXCOORD0,
- uniform float4x4 modelViewProj,
- orig ORIG,
- out out_vertex co
- )
- {
- co.position = mul(modelViewProj, position);
- co.color = color;
- co.texCoord = texCoord;
- co.orig_tex = ORIG.tex_coord;
- }
- /* FRAGMENT SHADER */
- float4 main_fragment(in out_vertex co, uniform sampler2D decal : TEXUNIT0, orig ORIG, uniform input IN) : COLOR
- {
- float2 dx = float2(1.0, 0.0)/IN.texture_size;
- float2 dy = float2(0.0, 1.0)/IN.texture_size;
- float2 tc = (floor(co.texCoord*IN.texture_size-float2(0.5,0.5))+float2(0.5,0.5))/IN.texture_size;
- float3 A = tex2D(ORIG.texture, tc ).xyz;
- float3 B = tex2D(ORIG.texture, tc +dx ).xyz;
- float3 C = tex2D(ORIG.texture, tc +dy).xyz;
- float3 D = tex2D(ORIG.texture, tc +dx+dy).xyz;
- float3 color = tex2D(decal, co.texCoord).xyz;
- color = bestfit(bestfit(A, B, color), bestfit(C, D, color), color);
- return float4(color, 1.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement