# Terin

Members

40

192 Neutral

• Rank
Member
1. ## Help with Shadow Mapping and Multi-Texturing

OK, so I've been working on my engine some more and I'm having an issue when calculating the face normals. I've seen a lot of different methods online about calculating the subtraction between vertices in a triangle. The most common appears to be B - A = Vector 1; C - A = Vector 2; Then cross-product the two vectors and you have your face normal. So, say I have two triangles that compose a tile that is used. The triangles form a triangle mesh in the form of: AD BC Wherein ABC is the first triangle and CDA is the second triangle. When I run through the calculations to do the face normal of ABC, the vector appears to be in the wrong direction. My directional light is at 0,0,1; the normal is at 0,0,-1 for a flat face (or in the negative Z axis, in general). I was using B - A and C - A; Then I figured it should be B - A and B - C to calculate the correct direction -- and indeed, my face normal goes to +Z. Is this the correct order to do it? I've googled and haven't found a very good explanation on what the correct order is -- very few sites actually draw it out cleanly to explain which order one should do it in -- they just throw in Spaghetti code (which I'm guilty of copying) to do the basic B - A and C - A -- which was totally wrong. EDIT: And now I see another topic a little further down that suggest A - B and C - B, wherein B is the common shared point between the two in the triangle... Which again, works to some degree. At this point, I think I may have my light being setup incorrectly -- which sucks, but it's good to know that my Light is just wrong (so I can fix it). Once I know the correct order, I can proceed, I think, to building this correctly. Thoughts?
2. ## Help with Shadow Mapping and Multi-Texturing

That fixed it! Thank you. Now, to try and solve other problems and get this all working together. :-)
3. ## Help with Shadow Mapping and Multi-Texturing

Some **are** negative... How do I identify what the correct order is? Is there a good URL or site that explains what the order is -- because for what I thought, it was all the same, so long as you take three points in a triangle. EDIT: I revisited a few things and saw that a "Front" face is defined (by default) as going COUNTER clockwise (unless you change it). I reversed the order of my points for the triangles that were always rendering funky, so that they were counter-clockwise (one triangle of the quad was counter-clockwise, the other was clockwise). That seems to have fixed everything! Oy! I *never* read/learned anything about this stuff before even in formal education.
4. ## Help with Shadow Mapping and Multi-Texturing

I was hoping to do something flat like face normals. Is this a problem if that's the case? Good point on the method, which I've done. I'm sorry the pictures are "ridiculous." I figured you'd still be able to tell, even with textures on. I haven't pushed anything else into the engine to test it. I figured a flat surface with occasional changes in height would be a good test.

8. ## Help with Shadow Mapping and Multi-Texturing

Beans, THANK YOU for pointing out my BIG mistake. Lookie what I got working... [img]https://dl.dropbox.com/u/20940511/2012.07.21%20Shadow%20Mapping%20III%20%28Shadows%20Working%29.png[/img] Mind you, it's still not perfectly correct. But it's closer! While I get a shadow, it does not seem to be correct when rendering, so I need to figure out any other gotcha's. The other problem that is prevalent in this image, is that the water is transparent at all -- I assume the problem is with the Alpha channel not being preserved. I think, perhaps, I had better be multiplying my color by only XYZ instead of XYZW. XYZW should correspond to RGBA, yes? I'd assume that if an image is in ARGB format (specified in the texture creation), then XYZW would map A => X, and so forth, yes? Thanks for all of your help!
9. ## Help with Shadow Mapping and Multi-Texturing

And that being said -- do I need the Model View * Projection to be multiplied for the actual display? That may be my problem... I'm not sure if that's the correct parameter, because I think I remember it being Projection -- not Projection * ModelView -- but if it is both, that should be a relatively simple fix, yes? :-)
10. ## Help with Shadow Mapping and Multi-Texturing

Would it help to confirm that the Matrix is the exact same going in at both locations when I get them? My goal is to have this code working on a netbook in addition to a high-end machine -- so unfortunately, I have to stick with GL 2.0 and before -- with few optimizations here and there for GL3.
11. ## Help with Shadow Mapping and Multi-Texturing

For some reason, it's not letting me edit my prior post, but I did this: [source lang="cpp"] varying vec3 Normal; varying vec4 LightCoordinate; varying vec4 WorldPosition; void main() { // Direct lighting // ------------------------------ vec4 Color = gl_LightSource[0].ambient; vec3 l = normalize(gl_LightSource[0].position.xyz); // direction to the light source vec3 view_normal = normalize(gl_NormalMatrix * Normal); vec3 view_light_direction = normalize(vec3(gl_LightSource[0].position)); //(WorldMatrix * vec4( LightPosition.x, LightPosition.y, LightPosition.z, 0 ) ).xyz; //float lambert = max(dot(view_normal, view_light_direction), MinimumShadow); float lambert = max(dot(Normal, l), MinimumShadow); Color.xyz *= lambert; //Blend in Color from primary texture unit Color.wxyz *= texture2D(DiffuseMap, vec2(gl_TexCoord[0])).wxyz; // Shadow mapping // ------------------------------ vec4 lcoord = LightCoordinate; // Fragment position in light space. //lcoord /= lcoord.w; // Project to cartesian space lcoord.xy = lcoord.xy * 0.5 + 0.5; // Scale since light clipping space is in [-1,1] but texture space is [0,1] float fragmentDepth = lcoord.z; // Depth of the fragment in light space. float shadowMapDepth = texture2D(ShadowMap, lcoord.xy).z; // Depth in the shadow map. float eps = 0.001; // depth bias float shadow = fragmentDepth - eps > shadowMapDepth ? 0.5: 1.0; gl_FragColor = vec4(1,1,1,1) * shadow; }[/source] So basically I avoid the color stuff at all -- just calculate the shadow. My screen is pure white, and that's it.
12. ## Help with Shadow Mapping and Multi-Texturing

Well, that still doesn't solve the issue of the shadows... Is there a way to just render shadows only? I was assuming I could get rid of all the texture stuff at the top to calculate light and just set the variable Color as 1,1,1,1 -- then multiply by the Shadow Map to see if shadows are correctly rendered. When I do that, though, the screen just stays a solid color.