-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfish.fx
94 lines (78 loc) · 1.87 KB
/
fish.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
extern const texture TextureDiffuse;
extern const float4x4 View;
extern const float4x4 Projection;
extern const float Angle;
sampler SamplerDiffuse = sampler_state
{
Texture = TextureDiffuse;
MinFilter = ANISOTROPIC;
MagFilter = LINEAR;
MipFilter = POINT;
AddressU = WRAP;
AddressV = WRAP;
};
struct VsInput
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float3 Tangent : TANGENT;
float3 Bitangent : BINORMAL;
float2 Texcoord : TEXCOORD0;
float4 Row0 : TEXCOORD1;
float4 Row1 : TEXCOORD2;
float4 Row2 : TEXCOORD3;
float4 Row3 : TEXCOORD4;
};
struct VsOutput
{
float4 Position : POSITION;
float3 Normal : NORMAL;
float2 Texcoord : TEXCOORD;
float Fog : BLENDWEIGHT0;
};
struct PsInput
{
float3 Normal : NORMAL;
float2 Texcoord : TEXCOORD;
float Fog : BLENDWEIGHT0;
};
static const float3 LightDirection = { 1, 2, 1 };
static const float4 WaterColor = { 0, 0.125, 0.1, 0 };
VsOutput Vshader(VsInput In)
{
VsOutput Out = (VsOutput)0;
float4x4 World = { In.Row0, In.Row1, In.Row2, In.Row3 };
In.Position.x += 15 * sin(Angle + 0.01 * In.Position.z);
float4 WorldPosition = mul(World, In.Position);
float4 ViewPosition = mul(View, WorldPosition);
Out.Position = mul(Projection, ViewPosition);
Out.Normal = mul(World, In.Normal);
Out.Texcoord = In.Texcoord;
Out.Fog = saturate(1 / exp(ViewPosition.z * 0.0035));
return Out;
}
float4 Pshader(PsInput In) : COLOR
{
float diffuse = dot(normalize(LightDirection), normalize(In.Normal)) * 0.5 + 0.5;
float4 color = tex2D(SamplerDiffuse, In.Texcoord) * diffuse;
float d = smoothstep(0.9, 1, In.Fog);
return lerp(WaterColor, color, d);
}
technique Normal
{
pass Pass0
{
CullMode = CW;
VertexShader = compile vs_3_0 Vshader();
PixelShader = compile ps_3_0 Pshader();
}
}
technique Reflect
{
pass Pass0
{
CullMode = CCW;
VertexShader = compile vs_3_0 Vshader();
PixelShader = compile ps_3_0 Pshader();
}
}