Graphics Reference
In-Depth Information
float4
TDeviceSize
[2];
// rtt size in TDeviceSize[0].xy
float4
TTimer
[1];
// game time in TTimer [ 0 ] .w
void
vsmain
(
float3
:
POSITION
,
inPos
float3
:
TEXCOORD
,
inTex
//
out
float4
:
POSITION
,
outPos
out
float4
:
TEXCOORD0
)
outTex0
{
outPos
=
inPos
;
//
outTex0
=
inTex
;
// half pixel offset
outTex0
.
xy
+=
TDeviceSize
[1].
zw
;
// 0.5f / rtt size in [1].zw
}
float
_blend
(
float
val
,
float
val0
,
float
val1
,
float
res0
,
float
res1
)
{
if
(
val
<
=
val0
)
return
res0
;
if
(
val
>
=
val1
)
return
res1
;
//
return
res0
+(
val
−
val0
)
(
res1
−
res0
)/(
val1
−
val0
);
}
float4
psmain
(
float4
inTex0
:
TEXCOORD0
,
float2
inSPos
:
VPOS
):
COLOR
{
// get target depth
float4
poscs
=
tex2D
(
Color1SamplerPoint
,
inTex0
.
xy
);
//
float
len
=
length
(
poscs
.
xyz
);
//
float4
backcolor
=
tex2D
(
Color0SamplerPointClamp
,
inTex0
.
xy
);
// check if color is green (aka grass)
int
isgreen
=
backcolor
.
g
>
backcolor
.
r
+0.01
f
&&
backcolor
.
g
>
backcolor
.
b
+0.01
f
;
//
if
(
isgreen
)
{
float4
color
=0;
// rtt size in TDeviceSize[0].xy
float
xx
=
inSPos
.
x
/
TDeviceSize
[0].
x
;
float
yy
=
inSPos
.
y
/
TDeviceSize
[0].
y
;
//
float
d
=
_blend
(
len
, 0 , 500 , 100 , 500 ) ;
float
dclose
=
_blend
(
len
,0,20 ,30 ,1);
//
d
=
dclose
;
//
yy
+=
xx
1000;
// add a l i t t l e wind movement
yy
+=
TTimer
[0].
w
0.004
f
;
//
float
yoffset
=
frac
(
yy
d
)/
d
;
//
float2
uvoffset
=
inTex0
.
xy
−
float2
(0,
yoffset
);
//
color
=
tex2D
(
Color0SamplerPointClamp
,
uvoffset
);