OpenGL 3.3 Two different results on two GPUs nVidia Optimus with Shadow mapping -


so i'm working on project (to both learn , create game in future) in c++ , rendering i've chose opengl 3.3. i've been working on intel hd 4000 built in processor opens default new apps , went sweet. i've tried open on 2nd gpu - nvidia gtx660m much faster one, , i've expected more fpses on it. nope, not had dozens of dozens bugs (in example - intel went ok if i've put out vec3 color in fragment shader, nvidia went full-on crazy style if didnt put out vec4...). of course not errors @ compile extremly hard fix...

but now, when i've fixed of it, im stuggling 1 problem cannot fix (there dirty ways but... that's not point).

in short way: generate on both gpu valid depth maps, on nvidia gpu not grey-scale, bur red-to-black scale extremely odd, since same code on same machine (almost) should run same (also same api!). due fact fragment shader propably doesnt catch-up it, , on nvidia not detect lit areas , completly dark (at least in spotlight, directional light doesnt work).

pics: image when using intel hd4000 (which comes i5 ivy-bridge cpu) image when using nvidia gtx660m when running app rmb menu. no soft shadows "buildings" (big blocks) nor flashlight effect (spot light)

important - notice depth maps on gtx660m redtoblack scale, not grey-scale on intel gpu. top 1 directional light , bottom 1 point light of course.

my fragmentshader: #version 330 core

in vec2 uv;                         //coords standard texture (model) in vec4 shadowcoord;                //coords directional light (pos) in vec4 povshadowcoord;             //coords spot light (flashlight) (pos)  out vec4 color;                     //output color  uniform sampler2d mytexturesampler; //standard texture data models uniform sampler2d shadowmap;        //shadowmap directional light uniform sampler2d povshadowmap;     //shadowmap spot light (flashlight)  void main(){     vec3 tex_data = texture2d( mytexturesampler, uv ).rgb;      float bias = 0.005;     float visibility = 0.7;     float decrease = 0.002;      int early_bailing = 0;     if ( texture2d( shadowmap, shadowcoord.xy + vec2(0,0)/1850.0 ).z  <  shadowcoord.z-bias ) {         visibility -= decrease; early_bailing++;     }     if ( texture2d( shadowmap, shadowcoord.xy + vec2(-2,-2)/1850.0 ).z  <  shadowcoord.z-bias ) {         visibility -= decrease; early_bailing++;     }     if ( texture2d( shadowmap, shadowcoord.xy + vec2(-2, 2)/1850.0 ).z  <  shadowcoord.z-bias ) {         visibility -= decrease; early_bailing++;     }     if ( texture2d( shadowmap, shadowcoord.xy + vec2( 2,-2)/1850.0 ).z  <  shadowcoord.z-bias ) {         visibility -= decrease; early_bailing++;     }     if ( texture2d( shadowmap, shadowcoord.xy + vec2( 2, 2)/1850.0 ).z  <  shadowcoord.z-bias ) {         visibility -= decrease; early_bailing++;     }     if(early_bailing < 5) {         if(early_bailing > 0) {             (int i=-2; < 2; i++) {                 for(int j = -2; j < 2; j++) {                     if(i ==  0 && j ==  0) continue;                     if(i == -2 && j == -2) continue;                     if ( texture2d( shadowmap, shadowcoord.xy + vec2(i,j)/850.0 ).z  <  shadowcoord.z-bias )                         visibility -= decrease;                 }             }         }     } else {         visibility -= 14 * decrease;     }      float x = povshadowcoord.x/povshadowcoord.w;     float y = povshadowcoord.y/povshadowcoord.w;     bias = 0.0004;     if(x < 0 || x > 1 || y < 0 || y > 1) {         visibility -= 0.6;     } else {         float min_visibility = visibility - 0.6;         if ( textureproj( povshadowmap, povshadowcoord.xyw).z < (povshadowcoord.z - bias)/povshadowcoord.w) {             visibility = min_visibility;         } else {             //flashlight effect             float dx = 0.5 - x;             float dy = 0.5 - y;             visibility -= sqrt(dx*dx + dy*dy);             if(visibility < min_visibility)                 visibility = min_visibility;         }     }      color = vec4(visibility * tex_data, 1); } 

first part directional light - pre-sample depthmap in 5 points, if same dont sample more (early bailing - performance optimization!), or if differs, sample , calculate intensity of shadow on current fragment.

second part sample point light depth map, , check distance center of ray simulate flashlight effect (stronger in center).

i dont think more needed if is, please write , i'll post needed code.

also - shadowmaps 16bits precision (gl_depth_component16) intel hd4000 faster gtx660m (which in way more powerfull) - weird. though think becouse dont draw high-poly, many very-low-poly. correct?

i've got answer elsewhere. future reference - sampling depth map uses red channel (or .x value) sample.r (/ sample.x), not .b (/ .z) had.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -