Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

160 Neutral

About skyemaidstone

  • Rank

Personal Information

  • Interests

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. skyemaidstone

    Terrain Bump Mapping - but not everywhere please

    Thanks guys, I tried lerping between the normal and the bumpmapped normal but I must have put it in the wrong place. Works pretty nicely now. Weirdly with bump mapping on the whole terrain seems slightly darker even where the bump mapped (blue) texture isn't being used in the splat/blend map but I can live with that.
  2. Hi guys, I wanted my roads to look a little more bumpy on my terrain so I added in bump mapping based on what i had working for the rest of the models. It works and looks nice enough (I'll need to fiddle with the normal map to get the pebble looking just the right amount of sharpness) but anyway.. a problem cropped up that hadn't occurred to me: I don't want it applied to the whole terrain, just the roads. The road texture is simply added using a blend map with green for grass, red for rock, blue for road. So the more blue there more the road texture is used. I don't wan't the other textures bump mapped.. i mean I guess i could but for now i'd rather not. So the code is something like: float3 normalFromMap = PSIn.Normal; if (BumpMapping) { // read the normal from the normal map normalFromMap = tex2D(RoadNormalMapSampler, PSIn.TexCoord * 4); //tranform to [-1,1] normalFromMap = 2.0f * normalFromMap - 1.0f; //transform into world space normalFromMap = mul(normalFromMap, PSIn.WorldToTangentSpace); } else { //tranform to [-1,1] normalFromMap = 2.0f * normalFromMap - 1.0f; } //normalize the result normalFromMap = normalize(normalFromMap); //output the normal, in [0,1] space Output.Normal.rgb = 0.5f * (normalFromMap + 1.0f); I tried checking if the blendmap's blue component was > 0 then use the bump mapping but that just makes a nasty line where it switches between just using the normal of the whole vertex or using the normal map. How do I blend between the two methods? Thanks
  3. skyemaidstone

    Reverse Depth Buffer

    ok thanks guys
  4. skyemaidstone

    Reverse Depth Buffer

    Thanks, I think I know how to do all of that in Monogame except: Swap the near and far plane while constructing the view-to-projection and projection-to-view transformation matrices of your camera, lights, etc. CreateLookAt errors telling me that far must be greater than near. So I don't do anything in the actual depth writing part of the shader?
  5. skyemaidstone

    3D Reverse Depth Buffer

    After reading loads about depth buffer precision (kindly linked/discussed by some people on here) I can't seem to find an actual example of how to do it. In my model shader I currently just write out z/w. Is it as simple as writing out 1 - z/w? That almost seems too simple.
  6. skyemaidstone

    Shadow Map Jiggling/Shimmering

    Sorry a couple more questions. How is reversing the depth generally done? Can i literally just set my cameras far/near in reverse (for the projection matrix) when rendering everything (including models to shadow map)? Do i need to do something different with storing the depth in the buffer? I'm just writing out z/w for everything right now (except linear for mist particles)
  7. skyemaidstone

    Shadow Map Jiggling/Shimmering

    Thanks Joe. I think that explains my problem (and solution) perfectly.
  8. skyemaidstone

    Shadow Map Jiggling/Shimmering

    Thanks again but what i'm asking is if the problem i was experiencing could be caused by using huge coordinates (and therefore causing a lack of depth precision). I have solution, i'm just trying to make sure understand it. Thanks for the link. I will have a read of that in depth later tonight
  9. skyemaidstone

    Shadow Map Jiggling/Shimmering

    Thanks. So just to confirm before I read that, what I'm describing is a depth map precision problem caused by my huge coordinates?
  10. skyemaidstone

    Shadow Map Jiggling/Shimmering

    Well texel snapping is working great. Rock solid shadows at last (this is just one cascade) No more jiggling After much fiddling and comparing my test harness the only difference seemed to be the huge numbers my game was using for the coordinates in game. If i reduced everything by say 100 it all looks the same but the shadows no longer jiggle at all. I don't quite get why that is. Depth map precision? Is it because my huge numbers (the centre of my map was 50000,0,50000 and the bounds were at 1024000. My near/far clip were at 5, 200000. I thought these kind of numbers would be ok in a 24bit depth map or is it because all the precision is near to the camera and you can't use those kind of high numbers? I happy I fixed it in the end but I don't quite get why. Could someone explain it to me if possible?
  11. skyemaidstone

    Shadow Map Jiggling/Shimmering

    Thanks, I found an old test harness for trying out shadows and lights on my models in an old version of my engines. The shadows are rock solid for point lights or directional . So I've introduced this jiggling somehow, somewhere along the line At least I know where to look now. Thanks for your help guys.
  12. skyemaidstone

    Shadow Map Jiggling/Shimmering

    You're spot on. For some reason I was redoing ShadowLightViewProjection = ShadowLightView *ShadowLightProjection just before I passed it to the shader. Which explains why it made no difference entirely. I thought it was finally solved... but no, although when I turn the snapping on my shadow mapping changes a little (so it's doing something). But it still jiggles around a lot. Curse of the Jiggles (The green true false top left is texel snapping enabled or not). I feel like I must be doing something else stupid elsewhere then. When render the models to my map/rendertarget I can just use the normal way i'd render a model can i? ie Make a local matrix for them using their scale, rotation and world position then use that * the shadowLVP. And when I look up the position in my pixel shadow i just use (this is the basic version with no filtering to keep things simple until I solve this): float4 lightScreenPos = mul(worldPos, ShadowLightViewProjection); //find sample position in shadow map float2 lightSamplePos; lightSamplePos.x = lightScreenPos.x/2.0f+0.5f; lightSamplePos.y = (-lightScreenPos.y/2.0f+0.5f); float realDistanceToLight = lightScreenPos.z; distanceStoredInDepthMap = tex2D(ShadowMapSampler, lightSamplePos); shadowCondition = distanceStoredInDepthMap <= (realDistanceToLight - 0.00035f); Does that all make sense or do I need to apply rounding somewhere else too?
  13. skyemaidstone

    Shadow Map Jiggling/Shimmering

    Ok I also tried simply adding a flag to stop recalculating the shadow light view and projection when I set it to true - I was thinking if it's a texel snapping issue then that would stop the jiggling/shimmering (although obviously only the area of the projection when it was last created would be shadowed). I can see my flag working because the shadow render target now remains fixed when the flag is on. But the jiggling remains even with that. Maybe I'm doing texel snapping and using a bounding radius correctly but the problem lies elsewhere. Do I need to some kind of rounding on the camera position for the calculation of shadows or something? I'm a bit stumped again. Or maybe my texel snapping just isn't following what MJP's post suggested somehow. Anyone have anything else I can try or any other ideas?
  14. skyemaidstone

    Shadow Map Jiggling/Shimmering

    Yes I thought that too at first so i played around with a depthbias (not going as far a slope based) but it still visibly moves/jiggles when I move or rotate the camera. Adding a bias does stop the wall (for example) flicking in and out of shadow but not the edges of the wall from shimmering. I've removed that (and my filtering too) for now to try and narrow down the problem.
  15. Hello! I've read MJP's great post on CSM and jiggling/shimmering and it seem to be the exact problem i'm having (I realise it's from 7 years ago or so but it seems very relevant) I was hoping someone you had time to help me solve it or point me in the right direction. I feel like i've learned the concepts and read everything I can find on the subject but I just can't seem to solve it. I'm more than happy to pay someone for their time, I just want this solved so I can forget about it because my game is at a fun stage were I can really start adding all the good bits (combat and spell effects, dungeons, swords etc). Anyway.. Here is a youtube video of the problem. I turn on the render target view about halfway through so you can see the shadow map top right. I've turned off all but the closest cascade for now and stretched it rather far so the quality isn't amazing but it shows the jiggling problem nicely. Please help My method for making the projection is pretty short and is very similar to MJPs post: public void GenerateCSMOrthoSliceTS(float pNearClip, float pfarClip) { Vector3[] frustumCorners = new Vector3[8]; Matrix mCameraViewProj = _Camera.CameraView; mCameraViewProj *= Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, _Camera._aspectRatio, pNearClip, pfarClip); BoundingFrustum oCameraViewProjFrustum = new BoundingFrustum(mCameraViewProj); frustumCorners = oCameraViewProjFrustum.GetCorners(); Vector3 frustumCenter = new Vector3(0, 0, 0); for (int i = 0; i < 8; i++) frustumCenter += frustumCorners; frustumCenter /= 8; // don't bother recaculating the radius if we've already done it if (radius == 0) radius = (frustumCorners[0] - frustumCorners[6]).Length() / 2.0f; Vector3 eye = frustumCenter + (SunlightDirection * radius); ShadowLightPos = eye; Vector3 ShadowLookAt = frustumCenter; ShadowLightView = Matrix.CreateLookAt(eye, ShadowLookAt, new Vector3(0, 1, 0)); ShadowLightProjection = Matrix.CreateOrthographicOffCenter(-radius, radius, -radius, radius, -radius * 8.0f, radius * 8.0f); ShadowLightViewProjectionMatrix = ShadowLightView * ShadowLightProjection; if (_nojiggle) { float ShadowMapSize = 4096.0f; // Set this to the size of your shadow map Vector3 shadowOrigin = Vector3.Transform(Vector3.Zero, ShadowLightViewProjectionMatrix); shadowOrigin *= (ShadowMapSize / 2.0f); Vector2 roundedOrigin = new Vector2((float)Math.Round(shadowOrigin.X), (float)Math.Round(shadowOrigin.Y)); Vector2 rounding = roundedOrigin - new Vector2(shadowOrigin.X, shadowOrigin.Y); rounding /= (ShadowMapSize / 2.0f); Matrix roundMatrix = Matrix.CreateTranslation(rounding.X, rounding.Y, 0.0f); ShadowLightViewProjectionMatrix *= roundMatrix; } }
  • 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!