02-04-2010, 10:33 PM,
|
|
[PATCH] Reverse lights
This is one of the first eye-candies I wanted to see for VDrift. I tweaked some code and added a reverse light systems for cars, with appropriate textures for all cars that have taillights which support this (SVN data). It uses the same system as the brake lights, but a second lightening layer.
The only minor issue I couldn't fix (although I seen and modified part of the rendering code) is that brake lights won't show while reverse lights are active. So if you're in Reverse you won't be seeing the red lights as you brake. My coding experience is small and I can't figure where one layer overwrites the other, but if any dev could fix this I'd be grateful. Either way I hope this can be added to VDrift, even with the overwriting if there's no way to show both lights at the same time.
The patch can be downloaded here (I included the src files for backup): http://www.mediafire.com/?51gmdydzy4j alt link http://upload.ps/rhvutlebx163/reverse_li...r1.zip.htm
|
|
02-04-2010, 11:28 PM,
|
|
portets
Member
|
Posts: 152
Threads: 12
Joined: Apr 2009
|
|
cool!
i hope this gets included
|
|
02-05-2010, 07:25 AM,
|
|
NaN Wrote:Thanks MirceaKitsune! I've taken the liberty to commit it.
Thank you very much I reverted everything to SVN, but as I mentioned in another topic the latest shaders are broken (fragment.glsl and / or vertex.glsl). Since this includes modifications to them I can't test it, as I have to use older versions of the shaders. Maybe someone can fix them if it isn't a big issue... this is my stterr:
Code: ERROR: Shader compilation failure: data/shaders/full/vertex.glsl and data/shaders/full/fragment.glsl
ERROR:
ERROR: Vertex shader:
ERROR: 1 : #define _ALPHATEST_
ERROR: 2 : #define _SHADOWSVHIGH_
ERROR: 3 : #define _CSM3_
ERROR: 4 : #define _CSM2_
ERROR: 5 : #define _SHADOWS_
ERROR: 6 : #define _REFLECTIONSTATIC_
ERROR: 7 : #define SCREENRESY 864
ERROR: 8 : #define SCREENRESX 1152
ERROR: 9 : #version 120
ERROR: 10 :
ERROR: 11 : #ifdef _SHADOWS_
ERROR: 12 : varying vec4 projshadow_0;
ERROR: 13 : #ifdef _CSM2_
ERROR: 14 : varying vec4 projshadow_1;
ERROR: 15 : #endif
ERROR: 16 : #ifdef _CSM3_
ERROR: 17 : varying vec4 projshadow_2;
ERROR: 18 : #endif
ERROR: 19 : #endif
ERROR: 20 :
ERROR: 21 : uniform vec3 lightposition;
ERROR: 22 :
ERROR: 23 : varying vec2 texcoord_2d;
ERROR: 24 : varying vec3 V, N;
ERROR: 25 : varying vec3 refmapdir, ambientmapdir;
ERROR: 26 :
ERROR: 27 : void main()
ERROR: 28 : {
ERROR: 29 : //transform the vertex
ERROR: 30 : gl_Position = ftransform();
ERROR: 31 :
ERROR: 32 : vec4 pos = gl_ModelViewMatrix * gl_Vertex;
ERROR: 33 : vec3 pos3 = pos.xyz;
ERROR: 34 :
ERROR: 35 : #ifdef _SHADOWS_
ERROR: 36 : projshadow_0 = gl_TextureMatrix[4] * gl_TextureMatrixInverse[3] * pos;
ERROR: 37 : #ifdef _CSM2_
ERROR: 38 : projshadow_1 = gl_TextureMatrix[5] * gl_TextureMatrixInverse[3] * pos;
ERROR: 39 : #endif
ERROR: 40 : #ifdef _CSM3_
ERROR: 41 : projshadow_2 = gl_TextureMatrix[6] * gl_TextureMatrixInverse[3] * pos;
ERROR: 42 : #endif
ERROR: 43 : #endif
ERROR: 44 :
ERROR: 45 : //set the color
ERROR: 46 : gl_FrontColor = gl_Color;
ERROR: 47 :
ERROR: 48 : //set the texture coordinates
ERROR: 49 : texcoord_2d = vec2(gl_MultiTexCoord0);
ERROR: 50 :
ERROR: 51 : //compute the eyespace normal
ERROR: 52 : N = normalize(gl_NormalMatrix * gl_Normal);
ERROR: 53 : V = normalize(-pos3);
ERROR: 54 : //R = normalize(reflect(pos3,N));
ERROR: 55 :
ERROR: 56 : #ifndef _REFLECTIONDISABLED_
ERROR: 57 : refmapdir = vec3(gl_TextureMatrix[2] * vec4(reflect(pos3, N),0));
ERROR: 58 : #else
ERROR: 59 : refmapdir = vec3(0.);
ERROR: 60 : #endif
ERROR: 61 :
ERROR: 62 : ambientmapdir = mat3(gl_TextureMatrix[2]) * N;
ERROR: 63 : }
ERROR: 64 :
ERROR:
ERROR: Fragment shader:
ERROR: 1 : #version 120
ERROR: 2 : #define _ALPHATEST_
ERROR: 3 : #define _SHADOWSVHIGH_
ERROR: 4 : #define _CSM3_
ERROR: 5 : #define _CSM2_
ERROR: 6 : #define _SHADOWS_
ERROR: 7 : #define _REFLECTIONSTATIC_
ERROR: 8 : #define SCREENRESY 864
ERROR: 9 : #define SCREENRESX 1152
ERROR: 10 : uniform sampler2D tu0_2D; //diffuse map
ERROR: 11 : uniform sampler2D tu1_2D; //misc map (includes gloss on R channel, metallic on G channel, ...
ERROR: 12 : uniform samplerCube tu3_cube; //ambient light cube map
ERROR: 13 :
ERROR: 14 : //width and height of the diffuse texture, in pixels
ERROR: 15 : //uniform float diffuse_texture_width;
ERROR: 16 :
ERROR: 17 : uniform float contrast;
ERROR: 18 :
ERROR: 19 : #ifdef _SHADOWS_
ERROR: 20 : #ifdef _SHADOWSULTRA_
ERROR: 21 : uniform sampler2D tu4_2D; //close shadow map
ERROR: 22 : #else
ERROR: 23 : uniform sampler2DShadow tu4_2D; //close shadow map
ERROR: 24 : #endif
ERROR: 25 : #ifdef _CSM2_
ERROR: 26 : uniform sampler2DShadow tu5_2D; //far shadow map
ERROR: 27 : #endif
ERROR: 28 : #ifdef _CSM3_
ERROR: 29 : uniform sampler2DShadow tu6_2D; //far far shadow map
ERROR: 30 : #endif
ERROR: 31 : #endif
ERROR: 32 :
ERROR: 33 : //#define _FANCIERSHADOWBLENDING_
ERROR: 34 :
ERROR: 35 : #ifndef _REFLECTIONDISABLED_
ERROR: 36 : uniform samplerCube tu2_cube; //reflection map
ERROR: 37 : #endif
ERROR: 38 : uniform sampler2D tu7_2D; //additive map (for reverse lights)
ERROR: 39 : uniform sampler2D tu8_2D; //additive map (for brake lights)
ERROR: 40 :
ERROR: 41 : #ifdef _EDGECONTRASTENHANCEMENT_
ERROR: 42 : uniform sampler2DShadow tu7_2D; //edge contrast enhancement depth map
ERROR: 43 : #endif
ERROR: 44 :
ERROR: 45 : varying vec2 texcoord_2d;
ERROR: 46 : varying vec3 V, N;
ERROR: 47 : varying vec3 refmapdir, ambientmapdir;
ERROR: 48 : uniform vec3 lightposition;
ERROR: 49 :
ERROR: 50 : const float PI = 3.141593;
ERROR: 51 : const float ONE_OVER_PI = 1.0 / PI;
ERROR: 52 :
ERROR: 53 : #ifdef _SHADOWS_
ERROR: 54 : varying vec4 projshadow_0;
ERROR: 55 : #ifdef _CSM2_
ERROR: 56 : varying vec4 projshadow_1;
ERROR: 57 : #endif
ERROR: 58 : #ifdef _CSM3_
ERROR: 59 : varying vec4 projshadow_2;
ERROR: 60 : #endif
ERROR: 61 : #endif
ERROR: 62 :
ERROR: 63 : #if ( defined (_SHADOWS_) && ( defined (_SHADOWSULTRA_) || defined (_SHADOWSVHIGH_) ) ) || defined (_EDGECONTRASTENHANCEMENT_)
ERROR: 64 : vec2 poissonDisk[16];
ERROR: 65 : #endif
ERROR: 66 :
ERROR: 67 : #ifdef _SHADOWSULTRA_
ERROR: 68 : #define BLOCKER_SEARCH_NUM_SAMPLES 16
ERROR: 69 : #define PCF_NUM_SAMPLES 16
ERROR: 70 : #define NEAR_PLANE 9.5
ERROR: 71 : #define LIGHT_WORLD_SIZE .05
ERROR: 72 : #define LIGHT_FRUSTUM_WIDTH 3.75
ERROR: 73 : // Assuming that LIGHT_FRUSTUM_WIDTH == LIGHT_FRUSTUM_HEIGHT
ERROR: 74 : #define LIGHT_SIZE_UV (LIGHT_WORLD_SIZE / LIGHT_FRUSTUM_WIDTH)
ERROR: 75 :
ERROR: 76 : float unpackFloatFromVec4i(const vec4 value)
ERROR: 77 : {
ERROR: 78 : const vec4 bitSh = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
ERROR: 79 : return(dot(value, bitSh));
ERROR: 80 : }
ERROR: 81 :
ERROR: 82 : float unpackFloatFromVec3i(const vec3 value)
ERROR: 83 : {
ERROR: 84 : const vec3 bitSh = vec3(1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
ERROR: 85 : return(dot(value, bitSh));
ERROR: 86 : }
ERROR: 87 :
ERROR: 88 : float unpackFloatFromVec2i(const vec2 value)
ERROR: 89 : {
ERROR: 90 : const vec2 unpack_constants = vec2(1.0/256.0, 1.0);
ERROR: 91 : return dot(unpack_constants,value);
ERROR: 92 : }
ERROR: 93 :
ERROR: 94 : float shadow_comparison(sampler2D tu, vec2 uv, float comparison)
ERROR: 95 : {
ERROR: 96 : float lookupvalue = unpackFloatFromVec3i(texture2D(tu, uv).rgb);
ERROR: 97 : return lookupvalue > comparison ? 1.0 : 0.0;
ERROR: 98 : }
ERROR: 99 :
ERROR: 100 : float PenumbraSize(float zReceiver, float zBlocker) //Parallel plane estimation
ERROR: 101 : {
ERROR: 102 : return (zReceiver - zBlocker) / zBlocker;
ERROR: 103 : }
ERROR: 104 :
ERROR: 105 : void FindBlocker(in vec2 poissonDisk[16], in sampler2D tu,
ERROR: 106 : out float avgBlockerDepth,
ERROR: 107 : out float numBlockers,
ERROR: 108 : vec2 uv, float zReceiver )
ERROR: 109 : {
ERROR: 110 : //This uses similar triangles to compute what
ERROR: 111 : //area of the shadow map we should search
ERROR: 112 : //float searchWidth = LIGHT_SIZE_UV * (zReceiver - NEAR_PLANE) / zReceiver;
ERROR: 113 : float searchWidth = 10.0/2048.0;
ERROR: 114 : //float searchWidth = LIGHT_SIZE_UV;
ERROR: 115 : float blockerSum = 0;
ERROR: 116 : numBlockers = 0;
ERROR: 117 : for( int i = 0; i < BLOCKER_SEARCH_NUM_SAMPLES; ++i )
ERROR: 118 : {
ERROR: 119 : //float shadowMapDepth = tDepthMap.SampleLevel(PointSampler,uv + poissonDisk[i] * searchWidth,0);
ERROR: 120 : float shadowMapDepth = unpackFloatFromVec3i(texture2D(tu, uv + poissonDisk[i] * searchWidth).rgb);
ERROR: 121 : if ( shadowMapDepth < zReceiver ) {
ERROR: 122 : blockerSum += shadowMapDepth;
ERROR: 123 : numBlockers++;
ERROR: 124 : }
ERROR: 125 : }
ERROR: 126 : avgBlockerDepth = blockerSum / numBlockers;
ERROR: 127 : }
ERROR: 128 :
ERROR: 129 : float PCF_Filter( in vec2 poissonDisk[16], in sampler2D tu, in vec2 uv, in float zReceiver, in float filterRadiusUV )
ERROR: 130 : {
ERROR: 131 : float sum = 0.0f;
ERROR: 132 : for ( int i = 0; i < PCF_NUM_SAMPLES; ++i )
ERROR: 133 : {
ERROR: 134 : vec2 offset = poissonDisk[i] * filterRadiusUV;
ERROR: 135 : sum += shadow_comparison(tu, uv + offset, zReceiver);
ERROR: 136 : }
ERROR: 137 : return sum / PCF_NUM_SAMPLES;
ERROR: 138 : //vec2 offset = vec2(1.0/2048.0,1.0/2048.0);
ERROR: 139 : //vec2 offset = vec2(0.0,0.0);
ERROR: 140 : //return unpackFloatFromVec4i(texture2D(tu, uv + offset)) >= zReceiver ? 1.0 : 0.0;
ERROR: 141 : //return unpackFloatFromVec3i(texture2D(tu, uv + offset).rgb) > zReceiver + 1.0/(256.0*256.0) ? 1.0 : 0.0;
ERROR: 142 : //return unpackFloatFromVec3i(texture2D(tu, uv + offset).rgb) > zReceiver + 1.0/(256.0*4.0) ? 1.0 : 0.0;
ERROR: 143 : //return unpackFloatFromVec2i(texture2D(tu, uv + offset).rg) >= zReceiver ? 1.0 : 0.0;
ERROR: 144 : }
ERROR: 145 :
ERROR: 146 : float PCSS ( in vec2 poissonDisk[16], in sampler2D tu, vec3 coords )
ERROR: 147 : {
ERROR: 148 : vec2 uv = coords.xy;
ERROR: 149 : float zReceiver = coords.z; // Assumed to be eye-space z in this code
ERROR: 150 : // STEP 1: blocker search
ERROR: 151 : float avgBlockerDepth = 0;
ERROR: 152 : float numBlockers = 0;
ERROR: 153 : FindBlocker( poissonDisk, tu, avgBlockerDepth, numBlockers, uv, zReceiver );
ERROR: 154 : if( numBlockers < 1 )
ERROR: 155 : //There are no occluders so early out (this saves filtering)
ERROR: 156 : return 1.0f;
ERROR: 157 : // STEP 2: penumbra size
ERROR: 158 : float penumbraRatio = PenumbraSize(zReceiver, avgBlockerDepth);
ERROR: 159 : //float filterRadiusUV = penumbraRatio * LIGHT_SIZE_UV * NEAR_PLANE / coords.z;
ERROR: 160 : float filterRadiusUV = clamp(penumbraRatio*0.05,0,20.0/2048.0);
ERROR: 161 : //float filterRadiusUV = penumbraRatio*(256.0/2048.0);
ERROR: 162 : // STEP 3: filtering
ERROR: 163 : return PCF_Filter( poissonDisk, tu, uv, zReceiver, filterRadiusUV );
ERROR: 164 : }
ERROR: 165 :
ERROR: 166 : float shadow_lookup(sampler2D tu, vec3 coords)
ERROR: 167 : #else
ERROR: 168 : float shadow_lookup(sampler2DShadow tu, vec3 coords)
ERROR: 169 : #endif
ERROR: 170 : {
ERROR: 171 : #ifdef _SHADOWSULTRA_
ERROR: 172 : float notshadowfinal = PCSS(poissonDisk, tu, coords);
ERROR: 173 : #else
ERROR: 174 : #ifdef _SHADOWSVHIGH_
ERROR: 175 : float notshadowfinal = 0.0;
ERROR: 176 : float radius = 3.0/2048.0;
ERROR: 177 : for (int i = 0; i < 16; i++)
ERROR: 178 : notshadowfinal += float(shadow2D(tu,coords + radius*vec3(poissonDisk[i],0.0)).r);
ERROR: 179 : notshadowfinal *= 1.0/16.0;
ERROR: 180 : #else
ERROR: 181 : //no PCF
ERROR: 182 : float notshadowfinal = float(shadow2D(tu, coords).r);
ERROR: 183 : #endif
ERROR: 184 : #endif
ERROR: 185 :
ERROR: 186 : return notshadowfinal;
ERROR: 187 : }
ERROR: 188 :
ERROR: 189 : #ifdef _EDGECONTRASTENHANCEMENT_
ERROR: 190 : float GetEdgeContrastEnhancementFactor(in sampler2DShadow tu, in vec3 coords)
ERROR: 191 : {
ERROR: 192 : float factor = 0.0;
ERROR: 193 : float radius = 3.0/1024.0;
ERROR: 194 : for (int i = 0; i < 8; i++)
ERROR: 195 : factor += float(shadow2D(tu,coords + radius*vec3(poissonDisk[i],0.0)).r);
ERROR: 196 : factor *= 1.0/8.0;
ERROR: 197 : return factor;
ERROR: 198 : }
ERROR: 199 : #endif
ERROR: 200 :
ERROR: 201 : //post-processing functions
ERROR: 202 : vec3 ContrastSaturationBrightness(vec3 color, float con, float sat, float brt)
ERROR: 203 : {
ERROR: 204 : // Increase or decrease theese values to adjust r, g and b color channels seperately
ERROR: 205 : const float AvgLumR = 0.5;
ERROR: 206 : const float AvgLumG = 0.5;
ERROR: 207 : const float AvgLumB = 0.5;
ERROR: 208 :
ERROR: 209 : const vec3 LumCoeff = vec3(0.2125, 0.7154, 0.0721);
ERROR: 210 :
ERROR: 211 : vec3 AvgLumin = vec3(AvgLumR, AvgLumG, AvgLumB);
ERROR: 212 : vec3 brtColor = color * brt;
ERROR: 213 : vec3 intensity = vec3(dot(brtColor, LumCoeff));
ERROR: 214 : vec3 satColor = mix(intensity, brtColor, sat);
ERROR: 215 : vec3 conColor = mix(AvgLumin, satColor, con);
ERROR: 216 : return conColor;
ERROR: 217 :
ERROR: 218 : //vec3 AvgLumin = vec3(0.5,0.5,0.5);
ERROR: 219 : //return mix(AvgLumin, color, con);
ERROR: 220 : }
ERROR: 221 : #define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend)))
ERROR: 222 : #define BlendSoftLightf(base, blend) ((blend < 0.5) ? (2.0 * base * blend + base * base * (1.0 - 2.0 * blend)) : (sqrt(base) * (2.0 * blend - 1.0) + 2.0 * base * (1.0 - blend)))
ERROR: 223 : #define BlendOverlayf(base, blend) (base < 0.5 ? (2.0 * base * blend) : (1.0 - 2.0 * (1.0 - base) * (1.0 - blend)))
ERROR: 224 : #define Blend(base, blend, funcf) vec3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b))
ERROR: 225 : #define BlendOverlay(base, blend) Blend(base, blend, BlendOverlayf)
ERROR: 226 : #define BlendSoftLight(base, blend) Blend(base, blend, BlendSoftLightf)
ERROR: 227 : #define BlendScreen(base, blend) Blend(base, blend, BlendScreenf)
ERROR: 228 : #define GammaCorrection(color, gamma) pow(color, 1.0 / gamma)
ERROR: 229 : #define LevelsControlInputRange(color, minInput, maxInput) min(max(color - vec3(minInput), vec3(0.0)) / (vec3(maxInput) - vec3(minInput)), vec3(1.0))
ERROR: 230 : #define LevelsControlInput(color, minInput, gamma, maxInput) GammaCorrection(LevelsControlInputRange(color, minInput, maxInput), gamma)
ERROR: 231 :
ERROR: 232 : float GetShadows()
ERROR: 233 : {
ERROR: 234 : #if ( defined (_SHADOWS_) && ( defined (_SHADOWSULTRA_) || defined (_SHADOWSVHIGH_) ) ) || defined (_EDGECONTRASTENHANCEMENT_)
ERROR: 235 : poissonDisk[0] = vec2( -0.94201624, -0.39906216 );
ERROR: 236 : poissonDisk[1] = vec2( 0.94558609, -0.76890725 );
ERROR: 237 : poissonDisk[2] = vec2( -0.094184101, -0.92938870 );
ERROR: 238 : poissonDisk[3] = vec2( 0.34495938, 0.29387760 );
ERROR: 239 : poissonDisk[4] = vec2( -0.91588581, 0.45771432 );
ERROR: 240 : poissonDisk[5] = vec2( -0.81544232, -0.87912464 );
ERROR: 241 : poissonDisk[6] = vec2( -0.38277543, 0.27676845 );
ERROR: 242 : poissonDisk[7] = vec2( 0.97484398, 0.75648379 );
ERROR: 243 : poissonDisk[8] = vec2( 0.44323325, -0.97511554 );
ERROR: 244 : poissonDisk[9] = vec2( 0.53742981, -0.47373420 );
ERROR: 245 : poissonDisk[10] = vec2( -0.26496911, -0.41893023 );
ERROR: 246 : poissonDisk[11] = vec2( 0.79197514, 0.19090188 );
ERROR: 247 : poissonDisk[12] = vec2( -0.24188840, 0.99706507 );
ERROR: 248 : poissonDisk[13] = vec2( -0.81409955, 0.91437590 );
ERROR: 249 : poissonDisk[14] = vec2( 0.19984126, 0.78641367 );
ERROR: 250 : poissonDisk[15] = vec2( 0.14383161, -0.14100790 );
ERROR: 251 : #endif
ERROR: 252 :
ERROR: 253 : #ifdef _SHADOWS_
ERROR: 254 :
ERROR: 255 : #ifdef _CSM3_
ERROR: 256 : const int numcsm = 3;
ERROR: 257 : #else
ERROR: 258 : #ifdef _CSM2_
ERROR: 259 : const int numcsm = 2;
ERROR: 260 : #else
ERROR: 261 : const int numcsm = 1;
ERROR: 262 : #endif
ERROR: 263 : #endif
ERROR: 264 :
ERROR: 265 : vec3 shadowcoords[numcsm];
ERROR: 266 :
ERROR: 267 : shadowcoords[0] = projshadow_0.xyz;
ERROR: 268 : #ifdef _CSM2_
ERROR: 269 : shadowcoords[1] = projshadow_1.xyz;
ERROR: 270 : #endif
ERROR: 271 : #ifdef _CSM3_
ERROR: 272 : shadowcoords[2] = projshadow_2.xyz;
ERROR: 273 : #endif
ERROR: 274 :
ERROR: 275 : #ifndef _FANCIERSHADOWBLENDING_
ERROR: 276 : const float boundmargin = 0.1;
ERROR: 277 : const float boundmax = 1.0 - boundmargin;
ERROR: 278 : const float boundmin = 0.0 + boundmargin;
ERROR: 279 :
ERROR: 280 : bool effect[numcsm];
ERROR: 281 :
ERROR: 282 : for (int i = 0; i < numcsm; i++)
ERROR: 283 : {
ERROR: 284 : effect[i] = (shadowcoords[i].x < boundmin || shadowcoords[i].x > boundmax) ||
ERROR: 285 : (shadowcoords[i].y < boundmin || shadowcoords[i].y > boundmax) ||
ERROR: 286 : (shadowcoords[i].z < boundmin || shadowcoords[i].z > boundmax);
ERROR: 287 : }
ERROR: 288 : #endif //no fancier shadow blending
ERROR: 289 :
ERROR: 290 : //shadow lookup that works better with ATI cards: no early out
ERROR: 291 : float notshadow[numcsm];
ERROR: 292 : notshadow[0] = shadow_lookup(tu4_2D, shadowcoords[0]);
ERROR: 293 : #ifdef _CSM2_
ERROR: 294 : notshadow[1] = shadow_lookup(tu5_2D, shadowcoords[1]);
ERROR: 295 : #endif
ERROR: 296 : #ifdef _CSM3_
ERROR: 297 : notshadow[2] = shadow_lookup(tu6_2D, shadowcoords[2]);
ERROR: 298 : #endif
ERROR: 299 :
ERROR: 300 : //simple shadow mixing, no shadow fade-in
ERROR: 301 : #ifndef _FANCIERSHADOWBLENDING_
ERROR: 302 : //float notshadowfinal = notshadow[0];
ERROR: 303 : float notshadowfinal = max(notshadow[0],float(effect[0]));
ERROR: 304 : #ifdef _CSM3_
ERROR: 305 : notshadowfinal = mix(notshadowfinal,mix(notshadow[1],notshadow[2],float(effect[1])),float(effect[0]));
ERROR: 306 : notshadowfinal = max(notshadowfinal,float(effect[2]));
ERROR: 307 : #else
ERROR: 308 : #ifdef _CSM2_
ERROR: 309 : notshadowfinal = mix(notshadowfinal,notshadow[1],float(effect[0]));
ERROR: 310 : notshadowfinal = max(notshadowfinal,float(effect[1]));
ERROR: 311 : #endif
ERROR: 312 : #endif
ERROR: 313 : #endif //no fancier shadow blending
ERROR: 314 :
ERROR: 315 : //fancy shadow mixing, gives shadow fade-in
ERROR: 316 : #ifdef _FANCIERSHADOWBLENDING_
ERROR: 317 : const float bound = 1.0;
ERROR: 318 : const float fade = 10.0;
ERROR: 319 : float effect[numcsm];
ERROR: 320 :
ERROR: 321 : for (int i = 0; i < numcsm; ++i)
ERROR: 322 : //for (int i = 3; i < 4; ++i)
ERROR: 323 : {
ERROR: 324 : shadowcoords[i] = clamp(shadowcoords[i], 0.0, bound);
ERROR: 325 : float xf1 = 1.0-min(1.0,shadowcoords[i].x*fade);
ERROR: 326 : float xf2 = max(0.0,shadowcoords[i].x*fade-(fade-1.0));
ERROR: 327 : float yf1 = 1.0-min(1.0,shadowcoords[i].y*fade);
ERROR: 328 : float yf2 = max(0.0,shadowcoords[i].y*fade-(fade-1.0));
ERROR: 329 : float zf1 = 1.0-min(1.0,shadowcoords[i].z*fade);
ERROR: 330 : float zf2 = max(0.0,shadowcoords[i].z*fade-(fade-1.0));
ERROR: 331 : effect[i] = max(xf1,max(xf2,max(yf1,max(yf2,max(zf1,zf2)))));
ERROR: 332 : //notshadow[i] = max(notshadow[i],effect[i]);
ERROR: 333 : }
ERROR: 334 :
ERROR: 335 : float notshadowfinal = notshadow[0];
ERROR: 336 : #ifdef _CSM3_
ERROR: 337 : notshadowfinal = mix(notshadowfinal,mix(notshadow[1],notshadow[2],effect[1]),effect[0]);
ERROR: 338 : notshadowfinal = max(notshadowfinal,effect[2]);
ERROR: 339 : #else
ERROR: 340 : #ifdef _CSM2_
ERROR: 341 : notshadowfinal = mix(notshadowfinal,notshadow[1],effect[0]);
ERROR: 342 : notshadowfinal = max(notshadowfinal,effect[1]);
ERROR: 343 : #else
ERROR: 344 : notshadowfinal = max(notshadowfinal,effect[0]);
ERROR: 345 : #endif
ERROR: 346 : #endif
ERROR: 347 : #endif //fancier shadow blending
ERROR: 348 :
ERROR: 349 : #else //no SHADOWS
ERROR: 350 : float notshadowfinal = 1.0;
ERROR: 351 : #endif
ERROR: 352 :
ERROR: 353 : return notshadowfinal;
ERROR: 354 : //return notshadow[2];
ERROR: 355 : //return max(shadow_lookup(tu6_2D, shadowcoords[2]),float(effect[2]));
ERROR: 356 : //return float(effect[0])*0.25+float(effect[1])*0.25+float(effect[2])*0.25;
ERROR: 357 : //return float(effect[0]);
ERROR: 358 : }
ERROR: 359 :
ERROR: 360 : float EffectStrength(float val, float coeff)
ERROR: 361 : {
ERROR: 362 : return val*coeff+1.0-coeff;
ERROR: 363 : }
ERROR: 364 :
ERROR: 365 : vec3 EffectStrength(vec3 val, float coeff)
ERROR: 366 : {
ERROR: 367 : return val*coeff+vec3(1.0-coeff);
ERROR: 368 : }
ERROR: 369 :
ERROR: 370 : float ColorCorrectfloat(in float x)
ERROR: 371 : {
ERROR: 372 : //return pow(x,5.0)*5.23878+pow(x,4.0)*-14.45564+pow(x,3.0)*12.6883+pow(x,2.0)*-3.78462+x*1.31897-.01041;
ERROR: 373 : return (1.-pow(1.-clamp(x,0.,1.),1.5))*1.2-0.2;
ERROR: 374 : //return x;
ERROR: 375 : }
ERROR: 376 :
ERROR: 377 : vec3 ColorCorrect(in vec3 val)
ERROR: 378 : {
ERROR: 379 : return vec3(ColorCorrectfloat(val.r),ColorCorrectfloat(val.g),ColorCorrectfloat(val.b));
ERROR: 380 : }
ERROR: 381 :
ERROR: 382 : vec3 Expose(vec3 light, float exposure)
ERROR: 383 : {
ERROR: 384 : return vec3(1.)-exp(-light*exposure);
ERROR: 385 : }
ERROR: 386 :
ERROR: 387 : float BRDF_Ward(vec3 N, vec3 L, vec3 H, vec3 R, vec3 T, vec3 B, vec2 P, vec2 A, vec3 scale)
ERROR: 388 : {
ERROR: 389 : float e1 = dot(H, T) / A.x;
ERROR: 390 : float e2 = dot(H, B) / A.y;
ERROR: 391 : float E = -2.0 * ((e1 * e1 + e2 * e2) / (1.0 + dot(H,N)));
ERROR: 392 : float cosThetaI = dot(N, L);
ERROR: 393 : float cosThetaR = dot(N, R);
ERROR: 394 : float brdf = P.x * ONE_OVER_PI +
ERROR: 395 : P.y * (1.0 / sqrt(cosThetaI * cosThetaR)) *
ERROR: 396 : (1.0 / (4.0 * PI * A.x * A.y)) * exp(E);
ERROR: 397 : return scale.x * P.x * ONE_OVER_PI +
ERROR: 398 : scale.y * P.y * cosThetaI * brdf +
ERROR: 399 : scale.z * dot(H,N) * P.y;
ERROR: 400 : }
ERROR: 401 :
ERROR: 402 : float BRDF_OrenNayar(vec3 V, vec3 N, vec3 L, float roughness)
ERROR: 403 : {
ERROR: 404 : float S2 = roughness * roughness;
ERROR: 405 : float dotVN = dot(V,N);
ERROR: 406 : float dotLN = dot(L,N);
ERROR: 407 : float thetai = acos(dotVN);
ERROR: 408 : float thetar = acos(dotLN);
ERROR: 409 : float alpha = max(thetai,thetar);
ERROR: 410 : float beta = min(thetai, thetar);
ERROR: 411 :
ERROR: 412 : float gamma = dot(V - N * dotVN, L - N*dotLN);
ERROR: 413 :
ERROR: 414 : float C1 = 1.-0.5*(S2/(S2+0.33));
ERROR: 415 : float C2 = 0.45*(S2/(S2+0.09));
ERROR: 416 :
ERROR: 417 : if (gamma >= 0.)
ERROR: 418 : {
ERROR: 419 : C2 *= sin(alpha);
ERROR: 420 : }
ERROR: 421 : else
ERROR: 422 : {
ERROR: 423 : C2 *= (sin(alpha)-pow((2.*beta)*ONE_OVER_PI,3.));
ERROR: 424 : }
ERROR: 425 :
ERROR: 426 : float C3 = 0.125 * (S2/(S2+0.09)) * pow((4.*alpha*beta)*ONE_OVER_PI*ONE_OVER_PI,2.);
ERROR: 427 :
ERROR: 428 : float A = gamma * C2 * tan(beta);
ERROR: 429 : float B = (1.-abs(gamma)) * C3 * tan((alpha+beta)*0.5);
ERROR: 430 :
ERROR: 431 : return max(0.,dotLN)*(C1+A+B);
ERROR: 432 : }
ERROR: 433 :
ERROR: 434 : float BRDF_CookTorrance(vec3 V, vec3 N, vec3 L, vec3 H, float roughness, float fresnel)
ERROR: 435 : {
ERROR: 436 : float R2 = roughness * 3.0;
ERROR: 437 : R2 *= R2;
ERROR: 438 : float NdotH = dot(N, H);
ERROR: 439 : float VdotH = dot(V, H);
ERROR: 440 : float NdotV = dot(N, V);
ERROR: 441 : float NdotL = max(0.,dot(N, L));
ERROR: 442 : float OneOverVdotH = 1. / max(VdotH,0.001);
ERROR: 443 :
ERROR: 444 : //geometric term
ERROR: 445 : float G1 = (2.*NdotH*NdotV) * OneOverVdotH;
ERROR: 446 : float G2 = (2.*NdotH*NdotL) * OneOverVdotH;
ERROR: 447 : float G = min(1.,max(0.,min(G1,G2)));
ERROR: 448 :
ERROR: 449 : //fresnel term
ERROR: 450 : float F = fresnel + (1.-fresnel)*pow(1.-NdotV,5.);
ERROR: 451 :
ERROR: 452 : //roughness term
ERROR: 453 : float NdotH2 = NdotH*NdotH;
ERROR: 454 : float A = 1./(4.*R2*NdotH2*NdotH2);
ERROR: 455 : float B = exp(-(1.-NdotH2)/(R2*NdotH2));
ERROR: 456 : float R0 = A * B;
ERROR: 457 :
ERROR: 458 : //final term
ERROR: 459 : return max(0.,(G*F*R0)/(NdotL*NdotV));
ERROR: 460 : }
ERROR: 461 :
ERROR: 462 : float BRDF_Lambert(vec3 N, vec3 L)
ERROR: 463 : {
ERROR: 464 : return max(0.,dot(L,N));
ERROR: 465 : }
ERROR: 466 :
ERROR: 467 : void main()
ERROR: 468 : {
ERROR: 469 : float notshadowfinal = GetShadows();
ERROR: 470 :
ERROR: 471 : vec4 tu0_2D_val = texture2D(tu0_2D, texcoord_2d);
ERROR: 472 : vec3 surfacecolor = tu0_2D_val.rgb;
ERROR: 473 : vec3 additive = texture2D(tu7_2D, texcoord_2d).rgb + texture2D(tu8_2D, texcoord_2d).rgb;
ERROR: 474 : vec3 ambient_light = textureCube(tu3_cube, ambientmapdir).rgb;
ERROR: 475 : //const vec3 ambient_light = vec3(1.);
ERROR: 476 : vec4 tu1_2D_val = texture2D(tu1_2D, texcoord_2d);
ERROR: 477 : float gloss = tu1_2D_val.r;
ERROR: 478 : float metallic = tu1_2D_val.g;
ERROR: 479 : vec3 L = lightposition;
ERROR: 480 : vec3 Nn = normalize(N);
ERROR: 481 : vec3 Vn = normalize(V);
ERROR: 482 : vec3 H = normalize(lightposition+V);
ERROR: 483 :
ERROR: 484 : vec3 diffuse = surfacecolor * (BRDF_Lambert(N,L)*notshadowfinal+ambient_light)*0.5;
ERROR: 485 :
ERROR: 486 : vec3 specular = vec3(0.);
ERROR: 487 : if (gloss > 0. || metallic > 0.)
ERROR: 488 : {
ERROR: 489 : #ifndef _REFLECTIONDISABLED_
ERROR: 490 : vec3 specular_environment = textureCube(tu2_cube, refmapdir).rgb;
ERROR: 491 : #else
ERROR: 492 : vec3 specular_environment = vec3(1.);
ERROR: 493 : #endif
ERROR: 494 :
ERROR: 495 : float specval = max(dot(reflect(-Vn,Nn),L),0.0);
ERROR: 496 : float spec_add_highlight = metallic*2.0*max((pow(specval,512.0)-0.5)*2.0,0.0);
ERROR: 497 : float brdf_gloss = clamp(BRDF_CookTorrance(Vn, Nn, L, H, 0.1, 0.05)*gloss,0.,1.);
ERROR: 498 : float brdf_metal = clamp(BRDF_CookTorrance(Vn, Nn, L, H, 0.3, 0.15)*metallic,0.,1.);
ERROR: 499 : //float brdf = brdf_gloss+brdf_metal;
ERROR: 500 : specular = (notshadowfinal*0.5+0.5)*(brdf_gloss*vec3(1.)+brdf_metal*specular_environment) + vec3(1.)*spec_add_highlight*notshadowfinal;
ERROR: 501 : diffuse *= 1.0-(brdf_gloss+brdf_metal)*0.5;
ERROR: 502 : }
ERROR: 503 :
ERROR: 504 : vec3 finalcolor = diffuse + specular + additive;
ERROR: 505 :
ERROR: 506 : //finalcolor = surfacecolor*vec3((BRDF_Lambert(N,L)*notshadowfinal+ambient_light)*0.5);
ERROR: 507 : //finalcolor = 1.156*(vec3(1.)-exp(-pow(finalcolor,vec3(1.3))*2.));
ERROR: 508 : finalcolor = 1.58*(vec3(1.)-exp(-finalcolor*1.));
ERROR: 509 : //finalcolor = (finalcolor+0.05)*1.1;
ERROR: 510 : //finalcolor = ColorCorrect(finalcolor);
ERROR: 511 :
ERROR: 512 : finalcolor = ContrastSaturationBrightness(finalcolor, contrast, 1.0/contrast, (contrast-1.0)*0.5+1.0);
ERROR: 513 : //finalcolor = Expose(finalcolor, contrast*3.0-2.0)*1.15;//(1./(1.-exp(-(contrast*3.-2.))));
ERROR: 514 : finalcolor = clamp(finalcolor,0.0,1.0);
ERROR: 515 :
ERROR: 516 : #ifdef _EDGECONTRASTENHANCEMENT_
ERROR: 517 : vec3 depthcoords = vec3(gl_FragCoord.x/SCREENRESX, gl_FragCoord.y/SCREENRESY, gl_FragCoord.z-0.001);
ERROR: 518 : float edgefactor = GetEdgeContrastEnhancementFactor(tu7_2D, depthcoords);
ERROR: 519 : finalcolor *= edgefactor*0.5+0.5;
ERROR: 520 : #endif
ERROR: 521 :
ERROR: 522 : #ifdef _ALPHATEST_
ERROR: 523 : //float width = clamp(dFdx(texcoord_2d.x) * diffuse_texture_width * 0.5,0.0,0.5);
ERROR: 524 : float width = clamp(dFdx(texcoord_2d.x) * 512.0 * 0.5,0.0,0.5);
ERROR: 525 : float alpha = smoothstep(0.5-width, 0.5+width, tu0_2D_val.a);
ERROR: 526 : #else
ERROR: 527 : float alpha = tu0_2D_val.a;
ERROR: 528 : #endif
ERROR: 529 :
ERROR: 530 : gl_FragColor.a = alpha*gl_Color.a;
ERROR: 531 :
ERROR: 532 : gl_FragColor.rgb = finalcolor;
ERROR: 533 : //gl_FragColor.rgb = finalcolor*gl_Color.a;
ERROR: 534 : //gl_FragColor.rgb = finalcolor*alpha;
ERROR: 535 : }
ERROR: 536 :
ERROR:
ERROR: Disabling shaders due to shader loading error
|
|
02-05-2010, 07:44 AM,
|
|
Yes, it works now thanks
|
|
04-23-2010, 11:36 AM,
|
|
Hey, sorry for the revive. I was looking at the reverse lights again and noticed I missed a texture for one of the cars with reverse stops on it, back when I did them. Can someone please add this to the Z06? http://www.mediafire.com/?bwzmo4znrdm
|
|
|