Skip to content

Commit 8cdddef

Browse files
committed
Add some original R1 shaders (1.6.0.2)
1 parent 2aad79a commit 8cdddef

Some content is hidden

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

45 files changed

+1238
-0
lines changed
573 Bytes
Binary file not shown.
545 Bytes
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.uv,v.T.w,v.B.w); // copy tc
16+
// o.tc0 = unpack_tc_base (v.tc); // copy tc
17+
18+
// calculate fade
19+
float3 dir_v = normalize (mul(m_WV,v.P));
20+
float3 norm_v = normalize (mul(m_WV,unpack_normal(v.N)));
21+
float fade = abs (dot(dir_v,norm_v));
22+
o.c0 = fade;
23+
24+
return o;
25+
}

res/gamedata/shaders/r1/common.h

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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 uv : 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+
float4 color : COLOR0;
95+
};
96+
struct vf_point
97+
{
98+
float4 hpos : POSITION;
99+
float2 tc0 : TEXCOORD0; // base
100+
float2 tc1 : TEXCOORD1; // att1 + clipper
101+
float2 tc2 : TEXCOORD2; // att2 + clipper
102+
float4 color : COLOR0;
103+
};
104+
//////////////////////////////////////////////////////////////////////////////////////////
105+
uniform sampler2D s_base;
106+
uniform samplerCUBE s_env;
107+
uniform sampler2D s_lmap;
108+
uniform sampler2D s_hemi;
109+
uniform sampler2D s_att;
110+
uniform sampler2D s_detail;
111+
112+
#define def_distort half(0.05f) // we get -0.5 .. 0.5 range, this is -512 .. 512 for 1024, so scale it
113+
114+
float3 v_hemi (float3 n) { return L_hemi_color/* *(.5f + .5f*n.y) */; }
115+
float3 v_hemi_wrap (float3 n, float w) { return L_hemi_color/* *(w + (1-w)*n.y) */; }
116+
float3 v_sun (float3 n) { return L_sun_color*max(0,dot(n,-L_sun_dir_w)); }
117+
float3 v_sun_wrap (float3 n, float w) { return L_sun_color*(w+(1-w)*dot(n,-L_sun_dir_w)); }
118+
half3 p_hemi (float2 tc) {
119+
//half3 t_lmh = tex2D (s_hemi, tc);
120+
//return dot (t_lmh,1.h/3.h);
121+
half4 t_lmh = tex2D (s_hemi, tc);
122+
return t_lmh.a;
123+
}
124+
125+
#endif // COMMON_H
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "common.h"
2+
3+
struct vf
4+
{
5+
float4 hpos : POSITION;
6+
float4 C : COLOR0;
7+
float2 tc : TEXCOORD0;
8+
};
9+
10+
uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
11+
uniform float4 array [200] : register(c10);
12+
13+
vf main (v_detail v)
14+
{
15+
vf o;
16+
17+
// index
18+
int i = v.misc.w;
19+
float4 m0 = array[i+0];
20+
float4 m1 = array[i+1];
21+
float4 m2 = array[i+2];
22+
float4 c0 = array[i+3];
23+
24+
// Transform to world coords
25+
float4 pos;
26+
pos.x = dot (m0, v.pos);
27+
pos.y = dot (m1, v.pos);
28+
pos.z = dot (m2, v.pos);
29+
pos.w = 1;
30+
31+
// Final out
32+
o.hpos = mul (m_WVP,pos);
33+
o.C = c0;
34+
o.tc.xy = (v.misc * consts).xy;
35+
36+
return o;
37+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "common.h"
2+
3+
struct vf
4+
{
5+
float4 hpos : POSITION;
6+
float4 C : COLOR0;
7+
float2 tc : TEXCOORD0;
8+
};
9+
10+
uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
11+
uniform float4 wave; // cx,cy,cz,tm
12+
uniform float4 dir2D;
13+
uniform float4 array [200] : register(c10);
14+
15+
vf main (v_detail v)
16+
{
17+
vf o;
18+
19+
// index
20+
int i = v.misc.w;
21+
float4 m0 = array[i+0];
22+
float4 m1 = array[i+1];
23+
float4 m2 = array[i+2];
24+
float4 c0 = array[i+3];
25+
26+
// Transform to world coords
27+
float4 pos;
28+
pos.x = dot (m0, v.pos);
29+
pos.y = dot (m1, v.pos);
30+
pos.z = dot (m2, v.pos);
31+
pos.w = 1;
32+
33+
//
34+
float base = m1.w;
35+
float dp = calc_cyclic (dot(pos,wave));
36+
float H = pos.y - base; // height of vertex (scaled)
37+
float frac = v.misc.z*consts.x; // fractional
38+
float inten = H * dp;
39+
float2 result = calc_xz_wave (dir2D.xz*inten,frac);
40+
pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1);
41+
o.hpos = mul (m_WVP,pos);
42+
43+
// Fake lighting
44+
float dpc = max (0.f, dp);
45+
o.C = c0 * (consts.w+consts.z*dpc*frac);
46+
47+
// final xform, color, tc
48+
o.tc.xy = (v.misc * consts).xy;
49+
50+
return o;
51+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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,true)
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+
r1_lspot (shader, t_base, "wmark_spot")
15+
end
16+
17+
function l_point (shader, t_base, t_second, t_detail)
18+
r1_lpoint (shader, t_base, "wmark_point")
19+
end

res/gamedata/shaders/r1/impl.ps

722 Bytes
Binary file not shown.

res/gamedata/shaders/r1/impl.vs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "common.h"
2+
3+
struct vf
4+
{
5+
float4 hpos : POSITION;
6+
float2 tc0 : TEXCOORD0;
7+
float2 tc1 : TEXCOORD1;
8+
float3 c0 : COLOR0; // c0=hemi, c0.a = dt*
9+
float3 c1 : COLOR1; // c1=sun, c1.a = dt+
10+
float fog : FOG;
11+
};
12+
13+
vf main (v_lmap v)
14+
{
15+
vf o;
16+
17+
float3 N = unpack_normal (v.N);
18+
o.hpos = mul (m_VP, v.P); // xform, input in world coords
19+
o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc
20+
o.tc1 = o.tc0; // copy tc
21+
o.c0 = v_hemi (N); // hemi
22+
o.c1 = v_sun (N); // sun
23+
o.fog = calc_fogging (v.P); // fog, input in world coords
24+
25+
return o;
26+
}

res/gamedata/shaders/r1/impl_dt.ps

894 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)