Skip to content

Commit

Permalink
Merge pull request #217 from RainbowZerg/xd_dev
Browse files Browse the repository at this point in the history
R1 improvements.
  • Loading branch information
Xottab-DUTY committed Jun 27, 2018
2 parents 2aad79a + 10ae347 commit 9fd2d99
Show file tree
Hide file tree
Showing 80 changed files with 1,340 additions and 238 deletions.
Binary file added res/gamedata/shaders/r1/add_point.ps
Binary file not shown.
Binary file added res/gamedata/shaders/r1/add_point_dt.ps
Binary file not shown.
Binary file added res/gamedata/shaders/r1/add_spot.ps
Binary file not shown.
Binary file added res/gamedata/shaders/r1/add_spot_dt.ps
Binary file not shown.
24 changes: 24 additions & 0 deletions res/gamedata/shaders/r1/base_lplanes.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "common.h"

struct vf
{
float4 hpos : POSITION;
float2 tc0 : TEXCOORD0; // base
float4 c0 : COLOR0; // color
};

vf main (v_vert v)
{
vf o;

o.hpos = mul (m_WVP, v.P); // xform, input in world coords
o.tc0 = unpack_tc_base (v.uv0,v.T.w,v.B.w); // copy tc

// calculate fade
float3 dir_v = normalize (mul(m_WV,v.P));
float3 norm_v = normalize (mul(m_WV,unpack_normal(v.N)));
float fade = abs (dot(dir_v,norm_v));
o.c0 = fade;

return o;
}
131 changes: 131 additions & 0 deletions res/gamedata/shaders/r1/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#ifndef COMMON_H
#define COMMON_H

#include "shared\common.h"

uniform half4 L_dynamic_props; // per object, xyz=sun,w=hemi
uniform half4 L_dynamic_color; // dynamic light color (rgb1) - spot/point
uniform half4 L_dynamic_pos; // dynamic light pos+1/range(w) - spot/point
uniform float4x4 L_dynamic_xform;

uniform float4x4 m_plmap_xform;
uniform float4 m_plmap_clamp [2]; // 0.w = factor

half calc_fogging (half4 w_pos) { return dot(w_pos,fog_plane); }
half2 calc_detail (half3 w_pos) {
float dtl = distance(w_pos,eye_position)*dt_params.w;
dtl = min(dtl*dtl, 1);
half dt_mul = 1 - dtl; // dt* [1 .. 0 ]
half dt_add = .5 * dtl; // dt+ [0 .. 0.5]
return half2 (dt_mul,dt_add);
}
float3 calc_reflection (float3 pos_w, float3 norm_w)
{
return reflect(normalize(pos_w-eye_position), norm_w);
}
float4 calc_spot (out float4 tc_lmap, out float2 tc_att, float4 w_pos, float3 w_norm) {
float4 s_pos = mul (L_dynamic_xform, w_pos);
tc_lmap = s_pos.xyww; // projected in ps/ttf
tc_att = s_pos.z; // z=distance * (1/range)
float3 L_dir_n = normalize (w_pos - L_dynamic_pos.xyz);
float L_scale = dot(w_norm,-L_dir_n);
return L_dynamic_color*L_scale*saturate(calc_fogging(w_pos));
}
float4 calc_point (out float2 tc_att0, out float2 tc_att1, float4 w_pos, float3 w_norm) {
float3 L_dir_n = normalize (w_pos - L_dynamic_pos.xyz);
float L_scale = dot (w_norm,-L_dir_n);
float3 L_tc = (w_pos - L_dynamic_pos.xyz) * L_dynamic_pos.w + .5f; // tc coords
tc_att0 = L_tc.xz;
tc_att1 = L_tc.xy;
return L_dynamic_color*L_scale*saturate(calc_fogging(w_pos));
}
float3 calc_sun (float3 norm_w) { return L_sun_color*max(dot((norm_w),-L_sun_dir_w),0); }
float3 calc_model_hemi (float3 norm_w) { return (norm_w.y*0.5+0.5)*L_dynamic_props.w*L_hemi_color; }
float3 calc_model_lq_lighting (float3 norm_w) { return calc_model_hemi(norm_w) + L_ambient + L_dynamic_props.xyz*calc_sun(norm_w); }
float3 _calc_model_hemi (float3 norm_w) { return max(0,norm_w.y)*.2*L_hemi_color; }
float3 _calc_model_lq_lighting (float3 norm_w) { return calc_model_hemi(norm_w) + L_ambient + .5*calc_sun(norm_w); }
float4 calc_model_lmap (float3 pos_w) {
float3 pos_wc = clamp (pos_w,m_plmap_clamp[0],m_plmap_clamp[1]); // clamp to BBox
float4 pos_w4c = float4 (pos_wc,1);
float4 plmap = mul (m_plmap_xform,pos_w4c); // calc plmap tc
return plmap.xyww;
}

struct v_lmap
{
float4 P : POSITION; // (float,float,float,1)
float4 N : NORMAL; // (nx,ny,nz,hemi occlusion)
float4 T : TANGENT;
float4 B : BINORMAL;
float2 uv0 : TEXCOORD0; // (base)
float2 uv1 : TEXCOORD1; // (lmap/compressed)
};
struct v_vert
{
float4 P : POSITION; // (float,float,float,1)
float4 N : NORMAL; // (nx,ny,nz,hemi occlusion)
float4 T : TANGENT;
float4 B : BINORMAL;
float4 color : COLOR0; // (r,g,b,dir-occlusion)
float2 uv0 : TEXCOORD0; // (u0,v0)
};
struct v_model
{
float4 pos : POSITION; // (float,float,float,1)
float3 norm : NORMAL; // (nx,ny,nz)
float3 T : TANGENT; // (nx,ny,nz)
float3 B : BINORMAL; // (nx,ny,nz)
float2 tc : TEXCOORD0; // (u,v)
#ifdef SKIN_COLOR
float3 rgb_tint;
#endif
};
struct v_detail
{
float4 pos : POSITION; // (float,float,float,1)
int4 misc : TEXCOORD0; // (u(Q),v(Q),frac,matrix-id)
};
struct vf_spot
{
float4 hpos : POSITION;
float2 tc0 : TEXCOORD0; // base
float4 tc1 : TEXCOORD1; // lmap, projected
float2 tc2 : TEXCOORD2; // att + clipper
#ifdef DL_DETAILS
float2 tcd : TEXCOORD3; // details
#endif
float4 color: COLOR0;
};
struct vf_point
{
float4 hpos : POSITION;
float2 tc0 : TEXCOORD0; // base
float2 tc1 : TEXCOORD1; // att1 + clipper
float2 tc2 : TEXCOORD2; // att2 + clipper
#ifdef DL_DETAILS
float2 tcd : TEXCOORD3; // details
#endif
float4 color: COLOR0;
};
//////////////////////////////////////////////////////////////////////////////////////////
uniform sampler2D s_base;
uniform samplerCUBE s_env;
uniform sampler2D s_lmap;
uniform sampler2D s_hemi;
uniform sampler2D s_att;
uniform sampler2D s_detail;

#define def_distort half(0.05f) // we get -0.5 .. 0.5 range, this is -512 .. 512 for 1024, so scale it

float3 v_hemi (float3 n) { return L_hemi_color/* *(.5f + .5f*n.y) */; }
float3 v_hemi_wrap (float3 n, float w) { return L_hemi_color/* *(w + (1-w)*n.y) */; }
float3 v_sun (float3 n) { return L_sun_color*max(0,dot(n,-L_sun_dir_w)); }
float3 v_sun_wrap (float3 n, float w) { return L_sun_color*(w+(1-w)*dot(n,-L_sun_dir_w)); }
half3 p_hemi (float2 tc) {
//half3 t_lmh = tex2D (s_hemi, tc);
//return dot (t_lmh,1.h/3.h);
half4 t_lmh = tex2D (s_hemi, tc);
return t_lmh.a;
}

#endif // COMMON_H
41 changes: 41 additions & 0 deletions res/gamedata/shaders/r1/detail_still.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "common.h"

struct vf
{
float4 hpos : POSITION;
float4 C : COLOR0;
float2 tc : TEXCOORD0;
float fog : FOG;
};

uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
uniform float4 array[200] : register(c10);

vf main (v_detail v)
{
vf o;

// index
int i = v.misc.w;
float4 m0 = array[i+0];
float4 m1 = array[i+1];
float4 m2 = array[i+2];
float4 c0 = array[i+3];

// Transform to world coords
float4 pos;
pos.x = dot(m0, v.pos);
pos.y = dot(m1, v.pos);
pos.z = dot(m2, v.pos);
pos.w = 1;

// Calc fog
o.fog = calc_fogging(pos);

// Final out
o.hpos = mul(m_WVP,pos);
o.C = c0;
o.tc.xy = (v.misc * consts).xy;

return o;
}
55 changes: 55 additions & 0 deletions res/gamedata/shaders/r1/detail_wave.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "common.h"

struct vf
{
float4 hpos : POSITION;
float4 C : COLOR0;
float2 tc : TEXCOORD0;
float fog : FOG;
};

uniform float4 consts; // {1/quant,1/quant,diffusescale,ambient}
uniform float4 wave; // cx,cy,cz,tm
uniform float4 dir2D;
uniform float4 array[200] : register(c10);

vf main (v_detail v)
{
vf o;

// index
int i = v.misc.w;
float4 m0 = array[i+0];
float4 m1 = array[i+1];
float4 m2 = array[i+2];
float4 c0 = array[i+3];

// Transform to world coords
float4 pos;
pos.x = dot(m0, v.pos);
pos.y = dot(m1, v.pos);
pos.z = dot(m2, v.pos);
pos.w = 1;

//
float base = m1.w;
float dp = calc_cyclic(dot(pos,wave));
float H = pos.y - base; // height of vertex (scaled)
float frac = v.misc.z*consts.x; // fractional
float inten = H * dp;
float2 result = calc_xz_wave(dir2D.xz*inten,frac);
pos = float4(pos.x+result.x, pos.y, pos.z+result.y, 1);

// Calc fog
o.fog = calc_fogging(pos);

// Fake lighting
float dpc = max(0.f, dp);
o.C = c0 * (consts.w+consts.z*dpc*frac);

// final xform, color, tc
o.hpos = mul(m_WVP,pos);
o.tc.xy = (v.misc * consts).xy;

return o;
}
42 changes: 42 additions & 0 deletions res/gamedata/shaders/r1/effects_wallmarkmult.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function normal (shader, t_base, t_second, t_detail)
shader:begin ("wmark", "wmarkmult")
: sorting (2, false)
: blend (true,blend.destcolor,blend.srccolor)
: aref (false,0)
: zb (true,false)
: fog (true)
: wmark (true)
shader:sampler ("s_base") :texture (t_base)
end


function l_spot (shader, t_base, t_second, t_detail)
shader:begin ("wmark_spot","add_spot")
: fog (false)
: zb (true,false)
: blend (true,blend.srcalpha,blend.one)
: aref (true,aref or 0)
shader:sampler ("s_base") :texture (t_base)
shader:sampler ("s_lmap") :texture ("internal\\internal_light_att")
: clamp ()
: f_linear ()
: project (true)
shader:sampler ("s_att") :texture ("internal\\internal_light_attclip")
: clamp ()
: f_linear ()
end

function l_point (shader, t_base, t_second, t_detail)
shader:begin ("wmark_point","add_point")
: fog (false)
: zb (true,false)
: blend (true,blend.srcalpha,blend.one)
: aref (true,aref or 0)
shader:sampler ("s_base") :texture (t_base)
shader:sampler ("s_lmap") :texture (t_point_att)
: clamp ()
: f_linear ()
shader:sampler ("s_att") :texture (t_point_att)
: clamp ()
: f_linear ()
end
Binary file added res/gamedata/shaders/r1/impl.ps
Binary file not shown.
39 changes: 39 additions & 0 deletions res/gamedata/shaders/r1/impl.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "common.h"

struct vf
{
float4 hpos : POSITION;
float2 tc0 : TEXCOORD0;
float2 tc1 : TEXCOORD1;
#ifdef T_DETAILS
float2 tcd : TEXCOORD2;
float4 c0 : COLOR0; // xyz=hemi, w=dt*
float4 c1 : COLOR1; // xyz=sun, w=dt+
#else
float3 c0 : COLOR0; // hemi
float3 c1 : COLOR1; // sun
#endif
float fog : FOG;
};

vf main (v_lmap v)
{
vf o;

float3 N = unpack_normal(v.N);
o.hpos = mul(m_VP, v.P); // xform, input in world coords
o.tc0 = unpack_tc_base(v.uv0,v.T.w,v.B.w);
o.tc1 = o.tc0; // copy tc
#ifdef T_DETAILS
float2 dt = calc_detail(v.P);
o.tcd = o.tc0*dt_params; // dt tc
o.c0 = float4(v_hemi(N), dt.x); // xyz=hemi, w=dt*
o.c1 = float4(v_sun(N), dt.y); // xyz=sun, w=dt+
#else
o.c0 = v_hemi(N); // hemi
o.c1 = v_sun(N); // sun
#endif
o.fog = calc_fogging(v.P); // fog, input in world coords

return o;
}
Binary file added res/gamedata/shaders/r1/impl_dt.ps
Binary file not shown.
3 changes: 3 additions & 0 deletions res/gamedata/shaders/r1/impl_dt.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define T_DETAILS

#include "impl.vs"
4 changes: 4 additions & 0 deletions res/gamedata/shaders/r1/impl_point.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define DL_LMAP
#define DL_POINT

#include "shared_dynlight.vs"
5 changes: 5 additions & 0 deletions res/gamedata/shaders/r1/impl_point_dt.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define DL_DETAILS
#define DL_LMAP
#define DL_POINT

#include "shared_dynlight.vs"
3 changes: 3 additions & 0 deletions res/gamedata/shaders/r1/impl_spot.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define DL_LMAP

#include "shared_dynlight.vs"
4 changes: 4 additions & 0 deletions res/gamedata/shaders/r1/impl_spot_dt.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define DL_DETAILS
#define DL_LMAP

#include "shared_dynlight.vs"
Binary file added res/gamedata/shaders/r1/lmap.ps
Binary file not shown.
Loading

0 comments on commit 9fd2d99

Please sign in to comment.