Jump to content
  • Advertisement

Modestas Andrijauskas

Member
  • Content Count

    26
  • Joined

  • Last visited

Community Reputation

202 Neutral

About Modestas Andrijauskas

  • Rank
    Member
  1. I have two ways to calculate min and max vectors, which are later used to create light's orthogonal projection. Lets name them A and B, so A looks like this: // Calculate min and max vectors, using viewer's camera frustum slice centroid and radius minOrtho.set(0, 0, 0, 1).assign(centroid).sub(frustumRadius, frustumRadius, -frustumRadius, 0); maxOrtho.set(0, 0, 0, 1).assign(centroid).add(frustumRadius, frustumRadius, -frustumRadius, 0); // Transform min and max vectors into light's eye space Matrix4f.transform(lightTransforms[i].view, minOrtho, tmpVector); minOrtho.assign(tmpVector); Matrix4f.transform(lightTransforms[i].view, maxOrtho, tmpVector); maxOrtho.assign(tmpVector); and B: minOrtho.set(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE, 1.0f); maxOrtho.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, 1.0f); // Transform viewer's frustum slice points into light's eye space, then find mins and maxes for(int j=0; j<8; j++){ Matrix4f.transform(lightTransforms[i].view, tmpCamera.frustum.points[j].xyzw(), tmpVector); tmpCamera.frustum.points[j].assign(tmpVector); if(tmpCamera.frustum.points[j].x < minOrtho.x) minOrtho.x = tmpCamera.frustum.points[j].x; if(tmpCamera.frustum.points[j].y < minOrtho.y) minOrtho.y = tmpCamera.frustum.points[j].y; if(tmpCamera.frustum.points[j].z < minOrtho.z) minOrtho.z = tmpCamera.frustum.points[j].z; if(tmpCamera.frustum.points[j].x > maxOrtho.x) maxOrtho.x = tmpCamera.frustum.points[j].x; if(tmpCamera.frustum.points[j].y > maxOrtho.y) maxOrtho.y = tmpCamera.frustum.points[j].y; if(tmpCamera.frustum.points[j].z > maxOrtho.z) maxOrtho.z = tmpCamera.frustum.points[j].z; } Now what gives me headache is that I can't understand one thing. When I was writing graphics engine I used A code because shadows looked much softer than using B, but now I'm rewriting my graphics engine (old one was static and now I'm writing object-oriented) from scratch and now B gives better results than A, but I can't understand why?   I think myself that calculating min and max by fitting frustum into sphere and using that sphere radius is better solution, than finding min and max using frustum points. Maybe I did a mistake in A technique?
  2. Modestas Andrijauskas

    Combining shadows from multiple light sources

    Yes, I'm not getting unwanted artifacts anymore. But I have another question, take a look at this screenshot: http://s16.postimg.org/rzbnd4rv9/ss14538.png Is it normal that point light shadow is brighter than directional light shadow?
  3. Modestas Andrijauskas

    Combining shadows from multiple light sources

    I used min of both shadows values because when shadows of two light sources were overlapping, they were darker, and shadows that were not overlapping was lighter. But it seems that this was one of my problems (and I think it's result is unrealistic). Now shadows looks good, thank you for helping.
  4. I've been implementing shadow mapping in my game for a while, now I got directional and point light shadows working correctly, unless I use them both at the same time. Take a look at this screenshot: http://s13.postimg.org/sjcmje2w7/point_Light.png I marked area with red arrows where weird thing happens. As you can see this area must be in shadow according to point light, but directional light lit up this area and it looks horribly. I think this problem is somehow related to biasing, but I'm not sure.   Same thing happens to directional light shadow mapping, here's how it looks: http://s11.postimg.org/jbz9qqx5v/directional_Light.png Again, I marked area where problem happens with arrows, but here it looks a lot better, when this area must be in shadow, point light lit up this area and it smoothly goes from light to dark, but still, there are some unwanted artifacts, I marked them around in white.   This is my fragment shader: vec3 textureColor = texture2D(colorTexture, TexCoord).rgb; //ShadowCalculation returns value between 0 and 1. 0 - fragment in shadow, 1 - fragment is not in shadow float shadowDirectional = ShadowCalculationDirectionalLight(); float shadowPoint = ShadowCalculationPointLight(); float shadow = min(shadowPoint, shadowDirectional); vec3 colorDirectional = PhongShade(directionalLight, normal, textureColor, shadow); vec3 colorPoint = PhongShade(pointLight, normal, textureColor, shadow); vec3 shadeColor = colorDirectional + colorPoint; FragColor = vec4(shadeColor, 1.0); And at the end of PhongShade function this is how I compute the result: return attenuation * (diffuse + specular) * shadow + ambient What am I doing wrong?
  5. Modestas Andrijauskas

    Shadow mapping problems

    Yes, because small shadowmap-acne artifact disappears. Here is the blender file: http://www14.zippyshare.com/v/shvo4v1l/file.html I didn't tried to render it in blender, because all I can do with blender, just make some model and export it to obj file, nothing else. And if you still wanna take a look at screenshots with wireframes, here you go: http://s10.postimg.org/55ub72q09/ss01_30_53.png http://s23.postimg.org/xnija6qm3/ss01_30_55.png
  6. Modestas Andrijauskas

    Shadow mapping problems

    Omg.. In blender you can set shading to smooth or flat, I've been using smooth shading because it looked better when lit, and that caused the problem. Here is how it looks with smooth shading: http://s14.postimg.org/6j0rtch1t/ss03_23_39.png and flat: http://s9.postimg.org/55a6z76rj/ss03_23_42.png  With flat shading shadow looks better, but how then I would make surfaces look smoother without smooth shading?
  7. Modestas Andrijauskas

    Shadow mapping problems

    Okay, here is screenshots with wireframes, and more contrasting colors, lit surfaces red, unlit green: http://s11.postimg.org/fj7kr4b1v/ss01_41_07.png  and here is shadow mapping, shadowed surfaces black, and not shadowed white: http://s14.postimg.org/4gfhevan5/ss01_40_56.png   I would give you all project files, but it would be mess for you, because you wouldn't know where what is. I can give you some parts of code e.g. lighting and shadow mapping including shaders. Or you could connect to my pc via teamviewer, and I would show you where all needed code is.   P.s. I was thinking about shadow mapping technique that I'm using. In my previous project (accidentally cleared my whole hdd and lost it..) I used different shadow mapping technique and as far as I remember shadow mapping for monkey head were pretty nice, and now I added monkey head to current project and it doesn't looks good. Maybe that's the problem? Currently I do shadow mapping with these texture parameters: glTexParameteri(GL_TEXTURE_2D, GL14.GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE); glTexParameteri(GL_TEXTURE_2D, GL14.GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL); So in fragment shader I can use sampler2DShadow and this is how I render shadows float shadow = textureProj(ShadowMap, ShadowCoord); FragColor = diffuse * shadow + ambient; And in previous project it was done differently. I didn't used those texture parameters and instead of sampler2DShadow I used sampler2D. It was actually code from Fabien Sanglard, this article: http://fabiensanglard.net/shadowmapping/ Maybe I should try switching my shadow mapping technique to that, which Fabien Sanglard showed?
  8. Modestas Andrijauskas

    Shadow mapping problems

    As I said bias wasn't the problem, so I tried this, and still no changes.       Light's direction vector is in eye space, and normal vector I think is also in eye space, because in vertex shader it's multiplied by normal matrix and normalized, so they are in same coordinate space.    I'm actually not sure how to debug lighting, but I tried things that you said. Here is the screenshot how diffuse and ambient lighting looks (red is ambient, pink is diffuse): http://s18.postimg.org/f2zv74a15/ss09_01_11.png and here is lighting with shadow mapping: http://s23.postimg.org/vlywtvg2j/ss09_01_13.png   The only thing I know, is that the part where is diffuse lighting between shadow and ambient lighting, is the part where lighting transitions from ambient to diffuse and this is the problem, but I dunno how to fix this problem. 
  9. Modestas Andrijauskas

    Shadow mapping problems

      I think I should ignore this thing (do not lit surfaces which normals are orthogonal to the light). As you said this problem seems unique to me, so yeah I found out that my bias matrix is wrong, instead of this: 0.5 0.0 0.0 0.0 0.0 0.5 0.0 0.0 0.0 0.0 0.5 0.0 0.5 0.5 0.5 1.0 I've had this: 0.5 0.0 0.0 0.5 0.0 0.5 0.0 0.5 0.0 0.0 0.5 0.5 0.0 0.0 0.0 1.0 But after correcting bias matrix everything got screwed up, and now I can think of one problem, matrices multiplication, I think I did it wrong. My program is written in Java and using LWJGL library, there is a matrix class with multiply function and I think I'm multiplying it wrong. By reading shadow mapping tutorial, my light's matrix should be computed like this: lightMatrix = bias * projection * view * model Function for multiply looks like this: public static Matrix4f mul(Matrix4f left, Matrix4f right, Matrix4f dest)  It multiplies right matrix by left matrix and stores to the dest matrix. For testing purposes I set light projection matrix to perspective, and this is how I multiply them(): Matrix4f.mul(projectionMatrix, biasMatrix, lightViewProjectionMatrix); Matrix4f.mul(viewMatrix, lightViewProjectionMatrix, lightViewProjectionMatrix); //After every model transform I send this matrix to the shader: Matrix4f matrix = new Matrix4f(); Matrix4f.mul(modelMatrix, lightViewProjectionMatrix, matrix); And the only thing that I get is just black line across the terrain   EDIT: It's not the bias problem, I tried to calculate matrices in vertex shader to make sure bias matrix is correct and results were same.
  10. Modestas Andrijauskas

    Shadow mapping problems

    The direction of the light. L. Spiro     This one:  if(dot(norm, s) < 0.05) didn't helped, but this:  if(max(dot(norm, s), 0.0) < 0.05) helped, until I didn't looked at other places, for example top of the hill was not lit by the light, where it should. So this is not the right way as a solution.
  11. Modestas Andrijauskas

    Shadow mapping problems

    I've actually found my problem, but can't remember in what website it was described. The problem is that orthogonal (or not, can't remember) faces should not be lit by light, but they are. There was another problem with lighting, source vector was wrong and after fixing it, now it looks like this: http://s10.postimg.org/7kot0nleh/ss11_01_21.png   As you can see there is only like 1-3 triangles that are having problem with shadowing, and for me it looks like they are orthogonal to the directional light. I've found my problem described in stackoverflow http://stackoverflow.com/questions/13371893/shadow-mapping-artifacts-on-thin-wall-orthogonal-to-light In the answer is said to make sure that face is facing the light and do it by checking if dot of normal is greater than epsilon, so I think it's same as checking if face is orthogonal to light. But how I would do that? I can't check if dot of normal is greater than epsilon, because dot function takes 2 parameters and not 1, what should be second parameter?
  12. Modestas Andrijauskas

    Shadow mapping problems

    I was changing z near and far, but couldn't find proper.    I know, and I'm always generating shadow map with back-faces only.   I've been reading about cascaded shadow maps and here is a quote from nvidia pdf about cascaded shadow maps:   So I think I should implement CSM in my game, but couldn't find good tutorial about it. I think I need to make the thing that was explained by MJP in this topic: http://www.gamedev.net/topic/505893-orthographic-projection-for-shadow-mapping/#entry4299499 2nd post, and to make cascaded shadow maps just increase camera z position to create more orthographic projections for further distances, am I correct?
  13. Modestas Andrijauskas

    Shadow mapping problems

    Lighting maybe helps a little bit: http://s1.postimg.org/iw9gcncnz/ss05_07_11.png And adding 0.0005 bias helps even more: http://s3.postimg.org/q103n8ern/ss05_08_55.png but it doesn't for cube (look at the edges, there is small amount of shadow): http://s17.postimg.org/itae40u0f/ss05_09_11.png
  14. Modestas Andrijauskas

    Shadow mapping problems

    Hello! Yesterday and today I was thinking where is the problem with lighting and shadows, but today when I disabled lighting I noticed that the problem is with shadow mapping. I've never had this problem before, but here's how it looks:     As you can see cube casts good shadow, but it has some self shadowing problems itself, and you can clearly see the same problem with terrain. Why this problem occurs?
  15. Modestas Andrijauskas

    Soft water edges

    Finally.. After so much days of googling I found the solution. Now I realized that I need to have both scene depth and water depth values linear, then subtract them and scale. Here is the code if someone needs it: vec2 textureCoords = gl_FragCoord.xy / ScreenSize; float sceneZ = texture2D(sceneDepthTexture, textureCoords).x; float linearSceneDepth = (2.0 * ZNEAR) / (ZFAR + ZNEAR - sceneZ * (ZFAR - ZNEAR)); float linearWaterDepth = (2.0 * ZNEAR) / (ZFAR + ZNEAR - gl_FragCoord.z * (ZFAR - ZNEAR)); const float alphaScale = 1000.0; float alpha = clamp(linearSceneDepth - linearWaterDepth, 0.0, 1.0) * alphaScale;
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!