Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

1443 Excellent

About george7378

  • Rank

Personal Information

  • Role
    Amateur / Hobbyist
  • Interests

Recent Profile Visitors

18681 profile views
  1. Hey everyone, I have the following loop in my main shader which samples my shadow map with a 3x3 PCF grid to achieve anti-aliased shadows: int shadowFactor = 0; for (int y = -1; y <= 1; y++) { for (int x = -1; x <= 1; x++) { float2 shadowSampleOffset = float2(x/ShadowMapSize, y/ShadowMapSize); if (tex2D(ShadowMapTextureSampler, projectedTextureCoordinatesLight + shadowSampleOffset).r < input.ProjectedPositionLight.z - 0.002f) { shadowFactor += 1; } } } float lightingCorrectionFactor = 1 - shadowFactor/9.0f; diffuseLightingFactor *= lightingCorrectionFactor; specularLightingFactor *= lightingCorrectionFactor; ...however, it always pushes the number of instructions up to the point where I normally need to use a higher shader model (in MonoGame, it causes me to go from the default 4_0_level_9_1 up to 4_0_level_9_3). Can anyone see a more obvious and efficient way to do the PCF operation? Thanks!
  2. Hey everyone, I've got a memory leak in my XNA/MonoGame app, and I'm pretty sure it's due to the fact that I create a lot of VertexBuffers manually and never dispose of them. I'm dealing with a dynamic quadtree terrain where every possible tile, at all levels of detail (down to a limit I impose), is created at loading time, each with its own vertex buffer which is sent straight to the GPU when I want to draw that particular tile. This means that, each time I load a level, I have something like 24,000 small VertexBuffers comprising my terrain, and each frame I pick and choose which ones to draw based on the camera position. The problem is that when I exit to the main menu and reload, I create another NEW quadtree which generates another 24,000 VertexBuffers. I can see that the memory allocated to the previous VertexBuffers is NOT being reclaimed, even though the quadtree objects which own them are no longer referenced and have been garbage collected. So, my question is - do I have to manually dispose of a VertexBuffer every time I'm done with it in my program? I've seen a load of tutorials for XNA which create VertexBuffers and IndexBuffers manually and allocate data into them (here and here, to name two of the most famous) and they never dispose of them. Are they doing it wrong, or are they correct since the buffers are in use throughout the whole program and so will be disposed cleanly when it exits anyway? Appreciate the help
  3. Thanks for the info - I did some more research and the general agreement seems to be that any content I create outside of ContentManager should have its Dispose() method called when I'm done with it. So now, in the UnloadContent() method, I call Dispose() on all the Texture2Ds that I create manually (and I leave the ContentManager to do its thing with its own Textures, Models, Effects, etc...)
  4. george7378

    XNA SpriteBatch depth with 3D objects

    Hey - thanks for the reply! In the end I decided to use a flat 3D billboard instead of a sprite, so that depth is taken care of naturally. The effect is also a lot nicer, and closer to what I had in my mind!
  5. Hey everyone, I'm working on an XNA (well, MonoGame) app and I'm wondering what needs to go in the auto-generated UnloadContent() method? Most of my models, textures, effects, etc... are loaded from ContentManager and so don't need to be manually unloaded. I do have a few tiny things that I'm creating myself though - for example, a couple of 1x1 Texture2Ds which I use for rendering coloured rectangles and lines via SpriteBatch, and a RenderTarget2D that I use for my shadow mapping. What's your rule for when something needs to go into UnloadContent(), and what should I actually do with it there? Thanks so much!
  6. Hey everyone, I'm using SpriteBatch to add some 2D elements to my 3D scene. Some of these elements are always in front of/behind the 3D objects so depth isn't always important, but others need to merge with the scene such that 3D geometry can partially obscure them based on depth. Does anyone know how I could do this with XNA? I did something similar with raw D3D and C++ a few years ago, and I think ID3DXSPRITE.Draw() took care of it as you were able to pass position in as a 3D vector with a Z value for depth. I guess I could always create a 3D quad and just render it with the rest of the scene, but if there's a more elegant way to do it with SpriteBatch then I'd love to know! Thanks for the help.
  7. Ah, yeah I did find this which gives the allowable values for the filters. Says that anisotropic for the Mip filter is undefined. That page's parent also has info about MaxAnisotropy which is handy.
  8. Hey everyone, I've got a few quick questions about my D3D9 sampler state in HLSL. I'm specifically looking at Anisotropic filtering, and was wondering if this is the correct way to do it? sampler TerrainTextureSampler = sampler_state { texture = <TerrainTexture>; magfilter = ANISOTROPIC; minfilter = ANISOTROPIC; mipfilter = LINEAR; AddressU = Wrap; AddressV = Wrap; }; Should I set all three filters to ANISOTROPIC, or should it just be the first two? Also, what happens if I don't set MaxAnisotropy? Does it default to the maximum value that the hardware can handle? I'm not setting it right now, and from what I can tell in-game the anisotropic filtering is still working. Thanks very much!
  9. Ah so you create/store every possible node when you begin, and just pick the ones to draw each frame? That's not a bad idea. I'll give that a go and see how much memory it uses for my game. My algorithm is based on this paper, where each node is an N x N vertex grid and a bunch of pre-determined index buffers are used to fix cracks where different edges meet.
  10. Hey everyone, I'm designing a game which uses a quadtree system for creating and rendering terrain. There's nothing special about it - just create a single root tile covering the whole area, traverse the tree from the root and, using the camera position, split/merge cells to move the detail around where it's needed. I'm happy with how it works, but I'm trying to come up with a better way to decide when I actually need to traverse the tree. Right now I'm using brute force and doing it every single frame, which seems like overkill as the camera isn't moving very quick. It seems like a waste of CPU time to force updates that regularly. I also tried doing the same thing but on a background thread, but this wasn't ideal either as it just seemed to lock up and I was only seeing the terrain update every 10 seconds or so. Plus I find that threading with more complicated stuff like this is a great way to take something that I understand, and turn it into a mess of hidden problems! I guess I could put a timer on and update every ~second, possibly using a background thread to create a brand new terrain tree and swapping it out with the current one when it's ready (so I know for sure there aren't any conflicts with the terrain that I'm using and drawing), but that doesn't seem like a very intelligent way of doing it either. Does anyone out there know a better way to decide when I should re-traverse and update my quadtree terrain? Thanks for the help!
  11. george7378

    An Algorithm for Infinite Worlds

    Hey everyone - I wrote a little article recently which covers some of the aspects of creating adaptive terrain: http://www.gkristiansen.co.uk/2018/04/an-algorithm-for-infinite-worlds.html It's more of a high-level description of the idea rather than a technical article and I created it mainly to practice my writing, but there's also a GitHub link to a full implementation at the bottom. I've been working on and off with my virtual terrain project for a year now, and I just thought I'd share the results in case anyone over here might find my simple example code to be helpful. Thanks for taking a look!
  12. Hi everyone, I have a quadtree terrain system which uses camera distance to decide when a node should split into 4 children (or merge the children). It's basically 'split if distance between camera and the centre of the node is less than a constant * the node's edge length'. This has worked OK so far, but now I've changed my algorithm to have many more vertices per node. This means that I want to get a lot closer to a node before deciding to split - maybe something like 0.1*edgeLength. I can no longer just check my distance from the centre as it won't work when I approach the edges of the node. I thought I could check the distance from each vertex in each node and find the smallest, but that seems like overkill (I'd be looping over every vertex in my terrain). So my question is - what's a more elegant way to decide whether to split/merge my quadtree nodes? Thanks for the help!
  13. george7378

    Neighbour nodes on a cube

    Thanks again for the inputs I decided to add properties to each root node which describe the rotations that need to be done in order to extract the correct neighbour node in each direction. These are passed around to any relevant child nodes which also touch the root border, and the end result is something that requires minimal 'if' statements and does most of the work itself provided you set the root nodes up properly.
  14. Hi again, another quadtree question - this time about neighbour finding in a set of 6 planar quadtrees forming a cube. At the moment, I've got a single quadtree in the XZ plane so finding neighbouring nodes of the same level is easy - e.g. If a top-left node wants to know it's left-hand neighbour, all it has to do is get a reference to the top-right child of its parent's left-hand neighbour. This still works for nodes contained on the same side of the cube, but it fails if I want to know a neighbour across the boundary between two different quadtrees in the cube. It doesn't work because the definition of up, left, down or right depends on which border you're querying across so asking for your left-hand neighbor using the above logic will only return the correct cell for some of the faces. Can anyone think of a way to get this simple system to work for a cube, or will it have to be more complicated? I can't think of a way to make it work without having horrible edge cases resulting in a very inflexible system. Perhaps I will just have to ignore neighbours across the boundaries and hence have small gaps in the terrain there. Thanks for the help
  15. Thanks for the reply - yes, I thought about what would happen if I used the same arbitrary vectors for every position, which is why I choose between the X direction or the Y direction depending on the Y component of the position. I was thinking this would ensure that the tangents always form an orthonormal basis around the point on the sphere. it will result in different tangents for different positions, but I was thinking this wouldn't matter as long as I was taking samples across two perpendicular directions in the tangent plane.
  • 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!