-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4xSoft-SmartRes.fx
117 lines (89 loc) · 3.45 KB
/
4xSoft-SmartRes.fx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
4xSoft "SmartRes" shader
Copyright (C) 2007-2019 guest(r) - [email protected]
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.
*/
string name : NAME = "soft";
float2 ps1 : TEXELSIZE;
float2 ir : sourcescale;
float4x4 World : WORLD;
float4x4 View : VIEW;
float4x4 Projection : PROJECTION;
float4x4 Worldview : WORLDVIEW; // world * view
float4x4 ViewProjection : VIEWPROJECTION; // view * projection
float4x4 WorldViewProjection : WORLDVIEWPROJECTION; // world * view * projection
string combineTechique : COMBINETECHNIQUE = "soft";
texture SourceTexture : SOURCETEXTURE;
sampler decal = sampler_state
{
Texture = (SourceTexture);
MinFilter = LINEAR;
MagFilter = LINEAR;
};
struct out_vertex {
float4 position : POSITION;
float4 color : COLOR;
float2 t0 : TEXCOORD0;
};
out_vertex VS_VERTEX(float3 position : POSITION, float2 texCoord : TEXCOORD0 )
{
out_vertex OUT = (out_vertex)0;
OUT.position = mul(float4(position,1.0),WorldViewProjection);
OUT.t0 = texCoord * 1.00001;
return OUT;
}
float3 SoftLite (float2 pos, float2 ps)
{
float4 yx = 0.25*float4(ps, -ps);
float4 xy = 0.50*float4(ps, -ps);
float2 dx = float2(xy.x, 0.0);
float2 dy = float2(0.0, xy.y);
float3 c11 = tex2D(decal, pos ).xyz;
float3 c00 = tex2D(decal, pos + xy.zw).xyz;
float3 c20 = tex2D(decal, pos + xy.xw).xyz;
float3 c22 = tex2D(decal, pos + xy.xy).xyz;
float3 c02 = tex2D(decal, pos + xy.zy).xyz;
float3 s00 = tex2D(decal, pos + yx.zw).xyz;
float3 s20 = tex2D(decal, pos + yx.xw).xyz;
float3 s22 = tex2D(decal, pos + yx.xy).xyz;
float3 s02 = tex2D(decal, pos + yx.zy).xyz;
float3 c01 = tex2D(decal, pos - dx ).xyz;
float3 c21 = tex2D(decal, pos + dx ).xyz;
float3 c10 = tex2D(decal, pos - dy ).xyz;
float3 c12 = tex2D(decal, pos + dy ).xyz;
float3 dt = float3(1.0,1.0,1.0);
float d1=dot(abs(c00-c22),dt)+0.0001;
float d2=dot(abs(c20-c02),dt)+0.0001;
float hl=dot(abs(c01-c21),dt)+0.0001;
float vl=dot(abs(c10-c12),dt)+0.0001;
float m1=dot(abs(s00-s22),dt)+0.0001;
float m2=dot(abs(s02-s20),dt)+0.0001;
float3 t1=(hl*(c10+c12)+vl*(c01+c21))/(2.0*(hl+vl));
float3 t2=(d1*(c20+c02)+d2*(c00+c22))/(2.0*(d1+d2));
return (c11+t1+t2+(m2*(s00+s22)+m1*(s02+s20))/(m1+m2))/5.0;
}
float4 PS_FRAGMENT (in out_vertex VAR) : COLOR
{
float2 tmp = (ir.x < 1.0) ? float2(1.0,1.0) : ir;
float2 ps = ps1*tmp;
return float4(SoftLite(VAR.t0,ps),1.0);
}
technique soft
{
pass P0
{
// shaders
VertexShader = compile vs_3_0 VS_VERTEX();
PixelShader = compile ps_3_0 PS_FRAGMENT();
}
}