|
| 1 | +#ifndef COMMON_H |
| 2 | +#define COMMON_H |
| 3 | + |
| 4 | +// #define USE_SUPER_SPECULAR |
| 5 | + |
| 6 | +#include "shared\common.h" |
| 7 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 8 | +// *** options |
| 9 | + |
| 10 | +// #define DBG_TEST_NMAP |
| 11 | +// #define DBG_TEST_NMAP_SPEC |
| 12 | +// #define DBG_TEST_SPEC |
| 13 | +// #define DBG_TEST_LIGHT |
| 14 | +// #define DBG_TEST_LIGHT_SPEC |
| 15 | + |
| 16 | +// #define USE_GAMMA_22 |
| 17 | +// #define USE_SJITTER |
| 18 | +// #define USE_SUNFILTER |
| 19 | +// #define USE_FETCH4 |
| 20 | +// #define USE_MBLUR //- HW-options defined |
| 21 | +// #define USE_HWSMAP //- HW-options defined |
| 22 | + |
| 23 | +// #define USE_HWSMAP_PCF //- nVidia GF3+, R600+ |
| 24 | + |
| 25 | +// #define USE_BRANCHING //- HW-options defined |
| 26 | +// #define USE_VTF //- HW-options defined, VertexTextureFetch |
| 27 | +// #define FP16_FILTER //- HW-options defined |
| 28 | +// #define FP16_BLEND //- HW-options defined |
| 29 | +// |
| 30 | +// #define USE_PARALLAX //- shader defined |
| 31 | +// #define USE_TDETAIL //- shader defined |
| 32 | +// #define USE_LM_HEMI //- shader defined |
| 33 | +// #define USE_DISTORT //- shader defined |
| 34 | +// #define USE_SUNMASK //- shader defined |
| 35 | +// #define DBG_TMAPPING |
| 36 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 37 | +#ifndef SMAP_size |
| 38 | +#define SMAP_size 1024 |
| 39 | +#endif |
| 40 | +#define PARALLAX_H 0.02 |
| 41 | +#define parallax float2(PARALLAX_H, -PARALLAX_H/2) |
| 42 | + |
| 43 | +#ifdef USE_R2_STATIC_SUN |
| 44 | +# define xmaterial half(1.0h/4.h) |
| 45 | +#else |
| 46 | +# define xmaterial half(L_material.w) |
| 47 | +#endif |
| 48 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 49 | +uniform half4 hemi_cube_pos_faces; |
| 50 | +uniform half4 hemi_cube_neg_faces; |
| 51 | +uniform half4 L_material; // 0,0,0,mid |
| 52 | +uniform half4 Ldynamic_color; // dynamic light color (rgb1) - spot/point |
| 53 | +uniform half4 Ldynamic_pos; // dynamic light pos+1/range(w) - spot/point |
| 54 | +uniform half4 Ldynamic_dir; // dynamic light direction - sun |
| 55 | + |
| 56 | +uniform half4 J_direct [6]; |
| 57 | +uniform half4 J_spot [6]; |
| 58 | + |
| 59 | +half calc_fogging (half4 w_pos) { return dot(w_pos,fog_plane); } |
| 60 | +half2 calc_detail (half3 w_pos) { |
| 61 | + float dtl = distance (w_pos,eye_position)*dt_params.w; |
| 62 | + dtl = min (dtl*dtl, 1); |
| 63 | + half dt_mul = 1 - dtl; // dt* [1 .. 0 ] |
| 64 | + half dt_add = .5 * dtl; // dt+ [0 .. 0.5] |
| 65 | + return half2 (dt_mul,dt_add); |
| 66 | +} |
| 67 | +float3 calc_reflection (float3 pos_w, float3 norm_w) |
| 68 | +{ |
| 69 | + return reflect(normalize(pos_w-eye_position), norm_w); |
| 70 | +} |
| 71 | + |
| 72 | +float3 calc_sun_r1 (float3 norm_w) { return L_sun_color*saturate(dot((norm_w),-L_sun_dir_w)); } |
| 73 | +float3 calc_model_hemi_r1 (float3 norm_w) { return max(0,norm_w.y)*L_hemi_color; } |
| 74 | +float3 calc_model_lq_lighting (float3 norm_w) { return L_material.x*calc_model_hemi_r1(norm_w) + L_ambient + L_material.y*calc_sun_r1(norm_w); } |
| 75 | + |
| 76 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 77 | +struct v_static { |
| 78 | + float4 P : POSITION; // (float,float,float,1) |
| 79 | + float4 Nh : NORMAL; // (nx,ny,nz,hemi occlusion) |
| 80 | + float4 T : TANGENT; // tangent |
| 81 | + float4 B : BINORMAL; // binormal |
| 82 | + float2 tc : TEXCOORD0; // (u,v) |
| 83 | + float2 lmh : TEXCOORD1; // (lmu,lmv) |
| 84 | + float4 color : COLOR0; // (r,g,b,dir-occlusion) |
| 85 | +}; |
| 86 | + |
| 87 | +struct v_tree { |
| 88 | + float4 P : POSITION; // (float,float,float,1) |
| 89 | + float4 Nh : NORMAL; // (nx,ny,nz) |
| 90 | + float3 T : TANGENT; // tangent |
| 91 | + float3 B : BINORMAL; // binormal |
| 92 | + float4 tc : TEXCOORD0; // (u,v,frac,???) |
| 93 | +}; |
| 94 | + |
| 95 | +struct v_model { |
| 96 | + float4 P : POSITION; // (float,float,float,1) |
| 97 | + float3 N : NORMAL; // (nx,ny,nz) |
| 98 | + float3 T : TANGENT; // (nx,ny,nz) |
| 99 | + float3 B : BINORMAL; // (nx,ny,nz) |
| 100 | + float2 tc : TEXCOORD0; // (u,v) |
| 101 | +}; |
| 102 | + |
| 103 | +struct v_detail { |
| 104 | + float4 pos : POSITION; // (float,float,float,1) |
| 105 | + int4 misc : TEXCOORD0; // (u(Q),v(Q),frac,matrix-id) |
| 106 | +}; |
| 107 | + |
| 108 | +#ifdef USE_HWSMAP |
| 109 | +struct v_shadow_direct_aref |
| 110 | +{ |
| 111 | + float4 hpos: POSITION; // Clip-space position (for rasterization) |
| 112 | + float2 tc0: TEXCOORD1; // Diffuse map for aref |
| 113 | +}; |
| 114 | +struct v_shadow_direct |
| 115 | +{ |
| 116 | + float4 hpos: POSITION; // Clip-space position (for rasterization) |
| 117 | +}; |
| 118 | +#else |
| 119 | +struct v_shadow_direct_aref |
| 120 | +{ |
| 121 | + float4 hpos: POSITION; // Clip-space position (for rasterization) |
| 122 | + float depth: TEXCOORD0; // Depth |
| 123 | + float2 tc0: TEXCOORD1; // Diffuse map for aref |
| 124 | +}; |
| 125 | +struct v_shadow_direct |
| 126 | +{ |
| 127 | + float4 hpos: POSITION; // Clip-space position (for rasterization) |
| 128 | + float depth: TEXCOORD0; // Depth |
| 129 | +}; |
| 130 | + |
| 131 | + |
| 132 | +#endif |
| 133 | + |
| 134 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 135 | +struct p_bumped { |
| 136 | + float4 hpos : POSITION; |
| 137 | +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) |
| 138 | + float4 tcdh : TEXCOORD0; // Texture coordinates, w=sun_occlusion |
| 139 | +#else |
| 140 | + float2 tcdh : TEXCOORD0; // Texture coordinates |
| 141 | +#endif |
| 142 | + float4 position : TEXCOORD1; // position + hemi |
| 143 | + half3 M1 : TEXCOORD2; // nmap 2 eye - 1 |
| 144 | + half3 M2 : TEXCOORD3; // nmap 2 eye - 2 |
| 145 | + half3 M3 : TEXCOORD4; // nmap 2 eye - 3 |
| 146 | +#ifdef USE_TDETAIL |
| 147 | + float2 tcdbump : TEXCOORD5; // d-bump |
| 148 | + #ifdef USE_LM_HEMI |
| 149 | + float2 lmh : TEXCOORD6; // lm-hemi |
| 150 | + #endif |
| 151 | +#else |
| 152 | + #ifdef USE_LM_HEMI |
| 153 | + float2 lmh : TEXCOORD5; // lm-hemi |
| 154 | + #endif |
| 155 | +#endif |
| 156 | +}; |
| 157 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 158 | +struct p_flat { |
| 159 | + float4 hpos : POSITION; |
| 160 | +#if defined(USE_R2_STATIC_SUN) && !defined(USE_LM_HEMI) |
| 161 | + float4 tcdh : TEXCOORD0; // Texture coordinates, w=sun_occlusion |
| 162 | +#else |
| 163 | + float2 tcdh : TEXCOORD0; // Texture coordinates |
| 164 | +#endif |
| 165 | + float4 position : TEXCOORD1; // position + hemi |
| 166 | + half3 N : TEXCOORD2; // Eye-space normal (for lighting) |
| 167 | + #ifdef USE_TDETAIL |
| 168 | + float2 tcdbump : TEXCOORD3; // d-bump |
| 169 | + #ifdef USE_LM_HEMI |
| 170 | + float2 lmh : TEXCOORD4; // lm-hemi |
| 171 | + #endif |
| 172 | + #else |
| 173 | + #ifdef USE_LM_HEMI |
| 174 | + float2 lmh : TEXCOORD3; // lm-hemi |
| 175 | + #endif |
| 176 | + #endif |
| 177 | +}; |
| 178 | + |
| 179 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 180 | +struct f_deffer { |
| 181 | + half4 position : COLOR0; // px,py,pz, m-id |
| 182 | + half4 Ne : COLOR1; // nx,ny,nz, hemi |
| 183 | + half4 C : COLOR2; // r, g, b, gloss |
| 184 | +}; |
| 185 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 186 | +struct p_screen { |
| 187 | + float4 hpos : POSITION; |
| 188 | + float2 tc0 : TEXCOORD0; // Texture coordinates (for sampling maps) |
| 189 | +}; |
| 190 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 191 | +// Geometry phase / deferring // |
| 192 | +uniform sampler2D s_base; // |
| 193 | +uniform sampler2D s_bump; // |
| 194 | +uniform sampler2D s_bumpX; // |
| 195 | +uniform sampler2D s_detail; // |
| 196 | +uniform sampler2D s_detailBump; // |
| 197 | +uniform sampler2D s_detailBumpX; // Error for bump detail |
| 198 | +uniform sampler2D s_bumpD; // |
| 199 | +uniform sampler2D s_hemi; // |
| 200 | + |
| 201 | +uniform sampler2D s_mask; // |
| 202 | + |
| 203 | +uniform sampler2D s_dt_r; // |
| 204 | +uniform sampler2D s_dt_g; // |
| 205 | +uniform sampler2D s_dt_b; // |
| 206 | +uniform sampler2D s_dt_a; // |
| 207 | + |
| 208 | +uniform sampler2D s_dn_r; // |
| 209 | +uniform sampler2D s_dn_g; // |
| 210 | +uniform sampler2D s_dn_b; // |
| 211 | +uniform sampler2D s_dn_a; // |
| 212 | + |
| 213 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 214 | +// Lighting/shadowing phase // |
| 215 | +uniform sampler2D s_depth; // |
| 216 | +uniform sampler2D s_position; // |
| 217 | +uniform sampler2D s_normal; // |
| 218 | +uniform sampler s_lmap; // 2D/cube projector lightmap |
| 219 | +uniform sampler3D s_material; // |
| 220 | +uniform sampler1D s_attenuate; // |
| 221 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 222 | +// Combine phase // |
| 223 | +uniform sampler2D s_diffuse; // rgb.a = diffuse.gloss |
| 224 | +uniform sampler2D s_accumulator; // rgb.a = diffuse.specular |
| 225 | +uniform sampler2D s_generic; // |
| 226 | +uniform sampler2D s_bloom; // |
| 227 | +uniform sampler s_image; // used in various post-processing |
| 228 | +uniform sampler2D s_tonemap; // actually MidleGray / exp(Lw + eps) |
| 229 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 230 | +// Defines // |
| 231 | +#define def_gloss half(2.f /255.f) |
| 232 | +#define def_aref half(200.f/255.f) |
| 233 | +#define def_dbumph half(0.333f) |
| 234 | +#define def_virtualh half(0.05f) // 5cm |
| 235 | +#define def_distort half(0.05f) // we get -0.5 .. 0.5 range, this is -512 .. 512 for 1024, so scale it |
| 236 | +#define def_hdr half(9.h) // hight luminance range half(3.h) |
| 237 | +#define def_hdr_clip half(0.75h) // |
| 238 | + |
| 239 | +////////////////////////////////////////////////////////////////////////////////////////// |
| 240 | +#define LUMINANCE_VECTOR half3(0.3f, 0.38f, 0.22f) |
| 241 | +void tonemap (out half4 low, out half4 high, half3 rgb, half scale) |
| 242 | +{ |
| 243 | + rgb = rgb*scale ; |
| 244 | + |
| 245 | + const float fWhiteIntensity = 1.7; |
| 246 | + |
| 247 | + const float fWhiteIntensitySQR = fWhiteIntensity*fWhiteIntensity; |
| 248 | +#ifdef USE_BRANCHING // ps_3_0 |
| 249 | + //low = rgb.xyzz ; |
| 250 | + |
| 251 | + low = ( (rgb*(1+rgb/fWhiteIntensitySQR)) / (rgb+1) ).xyzz; |
| 252 | + |
| 253 | + high = low/def_hdr ; // 8x dynamic range |
| 254 | +#else |
| 255 | + low = half4 ( ( (rgb*(1+rgb/fWhiteIntensitySQR)) / (rgb+1) ), 0 ) ; |
| 256 | + high = half4 (rgb/def_hdr, 0 ) ; // 8x dynamic range |
| 257 | +#endif |
| 258 | + |
| 259 | +/* |
| 260 | + rgb = rgb*scale; |
| 261 | +
|
| 262 | + low = rgb.xyzz; |
| 263 | + high = low/def_hdr; // 8x dynamic range |
| 264 | +*/ |
| 265 | + |
| 266 | +// low = half4 (rgb, 0); |
| 267 | +// rgb /= def_hdr ; |
| 268 | +// high = half4 (rgb, dot(rgb,0.333f)-def_hdr_clip) ; |
| 269 | +} |
| 270 | +half4 combine_bloom (half3 low, half4 high) { |
| 271 | + return half4(low + high*high.a, 1.h); |
| 272 | +} |
| 273 | + |
| 274 | +float3 v_hemi (float3 n) { return L_hemi_color*(.5f + .5f*n.y); } |
| 275 | +float3 v_hemi_wrap (float3 n, float w) { return L_hemi_color*(w + (1-w)*n.y); } |
| 276 | +float3 v_sun (float3 n) { return L_sun_color*dot(n,-L_sun_dir_w); } |
| 277 | +float3 v_sun_wrap (float3 n, float w) { return L_sun_color*(w+(1-w)*dot(n,-L_sun_dir_w)); } |
| 278 | +half3 p_hemi (float2 tc) { |
| 279 | +// half3 t_lmh = tex2D (s_hemi, tc); |
| 280 | +// return dot (t_lmh,1.h/4.h); |
| 281 | + half4 t_lmh = tex2D (s_hemi, tc); |
| 282 | + return t_lmh.a; |
| 283 | +} |
| 284 | + |
| 285 | +half get_hemi( half4 lmh) |
| 286 | +{ |
| 287 | + return lmh.a; |
| 288 | +} |
| 289 | + |
| 290 | +half get_sun( half4 lmh) |
| 291 | +{ |
| 292 | + return lmh.g; |
| 293 | +} |
| 294 | + |
| 295 | +// contrast function |
| 296 | +half Contrast(half Input, half ContrastPower) |
| 297 | +{ |
| 298 | + //piecewise contrast function |
| 299 | + bool IsAboveHalf = Input > 0.5 ; |
| 300 | + half ToRaise = saturate(2*(IsAboveHalf ? 1-Input : Input)); |
| 301 | + half Output = 0.5*pow(ToRaise, ContrastPower); |
| 302 | + Output = IsAboveHalf ? 1-Output : Output; |
| 303 | + return Output; |
| 304 | +} |
| 305 | + |
| 306 | +#define FXPS technique _render{pass _code{PixelShader=compile ps_3_0 main();}} |
| 307 | +#define FXVS technique _render{pass _code{VertexShader=compile vs_3_0 main();}} |
| 308 | + |
| 309 | +#endif |
0 commit comments