Skip to content

Commit 9fd2d99

Browse files
authored
Merge pull request #217 from RainbowZerg/xd_dev
R1 improvements.
2 parents 2aad79a + 10ae347 commit 9fd2d99

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1340
-238
lines changed
392 Bytes
Binary file not shown.
68 Bytes
Binary file not shown.
385 Bytes
Binary file not shown.
67 Bytes
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "common.h"
2+
3+
struct vf
4+
{
5+
float4 hpos : POSITION;
6+
float2 tc0 : TEXCOORD0; // base
7+
float4 c0 : COLOR0; // color
8+
};
9+
10+
vf main (v_vert v)
11+
{
12+
vf o;
13+
14+
o.hpos = mul (m_WVP, v.P); // xform, input in world coords
15+
o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc
16+
17+
// calculate fade
18+
float3 dir_v = normalize (mul(m_WV,v.P));
19+
float3 norm_v = normalize (mul(m_WV,unpack_normal(v.N)));
20+
float fade = abs (dot(dir_v,norm_v));
21+
o.c0 = fade;
22+
23+
return o;
24+
}

res/gamedata/shaders/r1/common.h

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#ifndef COMMON_H
2+
#define COMMON_H
3+
4+
#include "shared\common.h"
5+
6+
uniform half4 L_dynamic_props; // per object, xyz=sun,w=hemi
7+
uniform half4 L_dynamic_color; // dynamic light color (rgb1) - spot/point
8+
uniform half4 L_dynamic_pos; // dynamic light pos+1/range(w) - spot/point
9+
uniform float4x4 L_dynamic_xform;
10+
11+
uniform float4x4 m_plmap_xform;
12+
uniform float4 m_plmap_clamp [2]; // 0.w = factor
13+
14+
half calc_fogging (half4 w_pos) { return dot(w_pos,fog_plane); }
15+
half2 calc_detail (half3 w_pos) {
16+
float dtl = distance(w_pos,eye_position)*dt_params.w;
17+
dtl = min(dtl*dtl, 1);
18+
half dt_mul = 1 - dtl; // dt* [1 .. 0 ]
19+
half dt_add = .5 * dtl; // dt+ [0 .. 0.5]
20+
return half2 (dt_mul,dt_add);
21+
}
22+
float3 calc_reflection (float3 pos_w, float3 norm_w)
23+
{
24+
return reflect(normalize(pos_w-eye_position), norm_w);
25+
}
26+
float4 calc_spot (out float4 tc_lmap, out float2 tc_att, float4 w_pos, float3 w_norm) {
27+
float4 s_pos = mul (L_dynamic_xform, w_pos);
28+
tc_lmap = s_pos.xyww; // projected in ps/ttf
29+
tc_att = s_pos.z; // z=distance * (1/range)
30+
float3 L_dir_n = normalize (w_pos - L_dynamic_pos.xyz);
31+
float L_scale = dot(w_norm,-L_dir_n);
32+
return L_dynamic_color*L_scale*saturate(calc_fogging(w_pos));
33+
}
34+
float4 calc_point (out float2 tc_att0, out float2 tc_att1, float4 w_pos, float3 w_norm) {
35+
float3 L_dir_n = normalize (w_pos - L_dynamic_pos.xyz);
36+
float L_scale = dot (w_norm,-L_dir_n);
37+
float3 L_tc = (w_pos - L_dynamic_pos.xyz) * L_dynamic_pos.w + .5f; // tc coords
38+
tc_att0 = L_tc.xz;
39+
tc_att1 = L_tc.xy;
40+
return L_dynamic_color*L_scale*saturate(calc_fogging(w_pos));
41+
}
42+
float3 calc_sun (float3 norm_w) { return L_sun_color*max(dot((norm_w),-L_sun_dir_w),0); }
43+
float3 calc_model_hemi (float3 norm_w) { return (norm_w.y*0.5+0.5)*L_dynamic_props.w*L_hemi_color; }
44+
float3 calc_model_lq_lighting (float3 norm_w) { return calc_model_hemi(norm_w) + L_ambient + L_dynamic_props.xyz*calc_sun(norm_w); }
45+
float3 _calc_model_hemi (float3 norm_w) { return max(0,norm_w.y)*.2*L_hemi_color; }
46+
float3 _calc_model_lq_lighting (float3 norm_w) { return calc_model_hemi(norm_w) + L_ambient + .5*calc_sun(norm_w); }
47+
float4 calc_model_lmap (float3 pos_w) {
48+
float3 pos_wc = clamp (pos_w,m_plmap_clamp[0],m_plmap_clamp[1]); // clamp to BBox
49+
float4 pos_w4c = float4 (pos_wc,1);
50+
float4 plmap = mul (m_plmap_xform,pos_w4c); // calc plmap tc
51+
return plmap.xyww;
52+
}
53+
54+
struct v_lmap
55+
{
56+
float4 P : POSITION; // (float,float,float,1)
57+
float4 N : NORMAL; // (nx,ny,nz,hemi occlusion)
58+
float4 T : TANGENT;
59+
float4 B : BINORMAL;
60+
float2 uv0 : TEXCOORD0; // (base)
61+
float2 uv1 : TEXCOORD1; // (lmap/compressed)
62+
};
63+
struct v_vert
64+
{
65+
float4 P : POSITION; // (float,float,float,1)
66+
float4 N : NORMAL; // (nx,ny,nz,hemi occlusion)
67+
float4 T : TANGENT;
68+
float4 B : BINORMAL;
69+
float4 color : COLOR0; // (r,g,b,dir-occlusion)
70+
float2 uv0 : TEXCOORD0; // (u0,v0)
71+
};
72+
struct v_model
73+
{
74+
float4 pos : POSITION; // (float,float,float,1)
75+
float3 norm : NORMAL; // (nx,ny,nz)
76+
float3 T : TANGENT; // (nx,ny,nz)
77+
float3 B : BINORMAL; // (nx,ny,nz)
78+
float2 tc : TEXCOORD0; // (u,v)
79+
#ifdef SKIN_COLOR
80+
float3 rgb_tint;
81+
#endif
82+
};
83+
struct v_detail
84+
{
85+
float4 pos : POSITION; // (float,float,float,1)
86+
int4 misc : TEXCOORD0; // (u(Q),v(Q),frac,matrix-id)
87+
};
88+
struct vf_spot
89+
{
90+
float4 hpos : POSITION;
91+
float2 tc0 : TEXCOORD0; // base
92+
float4 tc1 : TEXCOORD1; // lmap, projected
93+
float2 tc2 : TEXCOORD2; // att + clipper
94+
#ifdef DL_DETAILS
95+
float2 tcd : TEXCOORD3; // details
96+
#endif
97+
float4 color: COLOR0;
98+
};
99+
struct vf_point
100+
{
101+
float4 hpos : POSITION;
102+
float2 tc0 : TEXCOORD0; // base
103+
float2 tc1 : TEXCOORD1; // att1 + clipper
104+
float2 tc2 : TEXCOORD2; // att2 + clipper
105+
#ifdef DL_DETAILS
106+
float2 tcd : TEXCOORD3; // details
107+
#endif
108+
float4 color: COLOR0;
109+
};
110+
//////////////////////////////////////////////////////////////////////////////////////////
111+
uniform sampler2D s_base;
112+
uniform samplerCUBE s_env;
113+
uniform sampler2D s_lmap;
114+
uniform sampler2D s_hemi;
115+
uniform sampler2D s_att;
116+
uniform sampler2D s_detail;
117+
118+
#define def_distort half(0.05f) // we get -0.5 .. 0.5 range, this is -512 .. 512 for 1024, so scale it
119+
120+
float3 v_hemi (float3 n) { return L_hemi_color/* *(.5f + .5f*n.y) */; }
121+
float3 v_hemi_wrap (float3 n, float w) { return L_hemi_color/* *(w + (1-w)*n.y) */; }
122+
float3 v_sun (float3 n) { return L_sun_color*max(0,dot(n,-L_sun_dir_w)); }
123+
float3 v_sun_wrap (float3 n, float w) { return L_sun_color*(w+(1-w)*dot(n,-L_sun_dir_w)); }
124+
half3 p_hemi (float2 tc) {
125+
//half3 t_lmh = tex2D (s_hemi, tc);
126+
//return dot (t_lmh,1.h/3.h);
127+
half4 t_lmh = tex2D (s_hemi, tc);
128+
return t_lmh.a;
129+
}
130+
131+
#endif // COMMON_H
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "common.h"
2+
3+
struct vf
4+
{
5+
float4 hpos : POSITION;
6+
float4 C : COLOR0;
7+
float2 tc : TEXCOORD0;
8+
float fog : FOG;
9+
};
10+
11+
uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
12+
uniform float4 array[200] : register(c10);
13+
14+
vf main (v_detail v)
15+
{
16+
vf o;
17+
18+
// index
19+
int i = v.misc.w;
20+
float4 m0 = array[i+0];
21+
float4 m1 = array[i+1];
22+
float4 m2 = array[i+2];
23+
float4 c0 = array[i+3];
24+
25+
// Transform to world coords
26+
float4 pos;
27+
pos.x = dot(m0, v.pos);
28+
pos.y = dot(m1, v.pos);
29+
pos.z = dot(m2, v.pos);
30+
pos.w = 1;
31+
32+
// Calc fog
33+
o.fog = calc_fogging(pos);
34+
35+
// Final out
36+
o.hpos = mul(m_WVP,pos);
37+
o.C = c0;
38+
o.tc.xy = (v.misc * consts).xy;
39+
40+
return o;
41+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "common.h"
2+
3+
struct vf
4+
{
5+
float4 hpos : POSITION;
6+
float4 C : COLOR0;
7+
float2 tc : TEXCOORD0;
8+
float fog : FOG;
9+
};
10+
11+
uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
12+
uniform float4 wave; // cx,cy,cz,tm
13+
uniform float4 dir2D;
14+
uniform float4 array[200] : register(c10);
15+
16+
vf main (v_detail v)
17+
{
18+
vf o;
19+
20+
// index
21+
int i = v.misc.w;
22+
float4 m0 = array[i+0];
23+
float4 m1 = array[i+1];
24+
float4 m2 = array[i+2];
25+
float4 c0 = array[i+3];
26+
27+
// Transform to world coords
28+
float4 pos;
29+
pos.x = dot(m0, v.pos);
30+
pos.y = dot(m1, v.pos);
31+
pos.z = dot(m2, v.pos);
32+
pos.w = 1;
33+
34+
//
35+
float base = m1.w;
36+
float dp = calc_cyclic(dot(pos,wave));
37+
float H = pos.y - base; // height of vertex (scaled)
38+
float frac = v.misc.z*consts.x; // fractional
39+
float inten = H * dp;
40+
float2 result = calc_xz_wave(dir2D.xz*inten,frac);
41+
pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1);
42+
43+
// Calc fog
44+
o.fog = calc_fogging(pos);
45+
46+
// Fake lighting
47+
float dpc = max(0.f, dp);
48+
o.C = c0 * (consts.w+consts.z*dpc*frac);
49+
50+
// final xform, color, tc
51+
o.hpos = mul(m_WVP,pos);
52+
o.tc.xy = (v.misc * consts).xy;
53+
54+
return o;
55+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function normal (shader, t_base, t_second, t_detail)
2+
shader:begin ("wmark", "wmarkmult")
3+
: sorting (2, false)
4+
: blend (true,blend.destcolor,blend.srccolor)
5+
: aref (false,0)
6+
: zb (true,false)
7+
: fog (true)
8+
: wmark (true)
9+
shader:sampler ("s_base") :texture (t_base)
10+
end
11+
12+
13+
function l_spot (shader, t_base, t_second, t_detail)
14+
shader:begin ("wmark_spot","add_spot")
15+
: fog (false)
16+
: zb (true,false)
17+
: blend (true,blend.srcalpha,blend.one)
18+
: aref (true,aref or 0)
19+
shader:sampler ("s_base") :texture (t_base)
20+
shader:sampler ("s_lmap") :texture ("internal\\internal_light_att")
21+
: clamp ()
22+
: f_linear ()
23+
: project (true)
24+
shader:sampler ("s_att") :texture ("internal\\internal_light_attclip")
25+
: clamp ()
26+
: f_linear ()
27+
end
28+
29+
function l_point (shader, t_base, t_second, t_detail)
30+
shader:begin ("wmark_point","add_point")
31+
: fog (false)
32+
: zb (true,false)
33+
: blend (true,blend.srcalpha,blend.one)
34+
: aref (true,aref or 0)
35+
shader:sampler ("s_base") :texture (t_base)
36+
shader:sampler ("s_lmap") :texture (t_point_att)
37+
: clamp ()
38+
: f_linear ()
39+
shader:sampler ("s_att") :texture (t_point_att)
40+
: clamp ()
41+
: f_linear ()
42+
end

res/gamedata/shaders/r1/impl.ps

912 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)