skyemaidstone

Members
  • Content count

    40
  • Joined

  • Last visited

Community Reputation

160 Neutral

About skyemaidstone

  • Rank
    Member

Personal Information

  • Interests
    Programming
  1. 3D Reverse Depth Buffer

    ok thanks guys
  2. 3D 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?
  3. 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.
  4. 3D 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)
  5. 3D Shadow Map Jiggling/Shimmering

    Thanks Joe. I think that explains my problem (and solution) perfectly.
  6. 3D 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
  7. 3D 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?
  8. 3D 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?
  9. 3D 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.
  10. 3D 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?
  11. 3D 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?
  12. 3D 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.
  13. 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[i]; 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; } }
  14. 3D Converting my DX9 HLSL to DX10/11

    So essentially what i'm doing is correct with SampleCmpLevelZero is it? It compares whatever is at that texture coordinate with the float I pass in parameter 3 (using whatever samplercomparisionstate is have set)? Or have I misunderstood something else?
  15. Just a quick one (hopefully). I'm trying to use hardward PCF that's apparently built in later than dx9 so I'm updating some old shaders. I was using: distanceStoredInDepthMap = tex2D(ShadowMapSamplerHQ, lightSamplePos); shadowCondition = distanceStoredInDepthMap <= (realDistanceToLight); float lit = float(ShadowMapHQ.SampleCmpLevelZero(cmpSampler, lightSamplePos, realDistanceToLight)); distanceStoredInDepthMap = tex2D(ShadowMapSamplerHQ, lightSamplePos); shadowCondition = distanceStoredInDepthMap <= (realDistanceToLight); I'm trying update it to use the comparison method on the Texture2D object; float lit = float(ShadowMapHQ.SampleCmpLevelZero(cmpSampler, lightSamplePos, realDistanceToLight)); But it's just returning 0. I've just left SamplerComparisonState as defaults. Sorry if this is a dumb question.