|
| 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 |
0 commit comments