Jump to content
  • Advertisement

KieranHay

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

128 Neutral

About KieranHay

  • Rank
    Newbie
  1. KieranHay

    Deferred Renderer and Shadow mapping

    Yh, its a bit of a mess at the moment. I just wanted to get something working and clean it all up after... The World Position is being used elsewhere in the shader, it just got copied over along with the shadow mapping code.   I'm sorry but I don't see why I would need to use the inverse view matrix, (Math is not really a strong area of mine). Needing to think about multiple coordinate systems isn't fun... At the moment on the second pass, the vertex shader is just passing the normalised device coordinates through so I haven't even got the camera's view or projection matrix as I'm doing all that within the first pass. The first pass renders all the geometry and then the second basically uses a bunch of textures to perform the lighting.   How would I go from there to determine if each pixel is in shadow or not?     Yes it is, I'm storing that from the first pass however like you said before I should only need to send the depth information. I didn't mean to there that's a bi-product of all this testing and changing things to see what happens, basically a hope for the best at the moment lol...
  2. KieranHay

    Deferred Renderer and Shadow mapping

    Thanks for the replay Kauna.     This is the part that is confusing me. How would I go about doing this.. I'm sure my shadow map is correct as I can now see it being displayed correctly but it shows up in the incorrect places and the shadows move when the camera moves. If you/or someone could show/advise me the correct way to do this I would be very grateful.   Also, I'm aware that I should only be outputting the depth of the shadow map, it was while I was testing. I was going off two different tutorials that do it 2 different ways so having them both just saved myself time, however these could be confusing the matter atm.
  3. Hello Forum, hoping this is in the correct place.   I have implemented a deferred renderer with DirectX 11 using HLSL shaders. The process is as follows: The first pass renders all information to separate textures like albedo, normals, worldPosition etc.. The second pass does all the lighting calculations. I know that I could be working out the position using the depth, however that doesn't matter at the moment as the deferred lighting works.   The problem that is now arising is I want to include shadows into the procedure, most online tutorials assume forward rendering but I would believe the process is the same. At the moment I have simply added in the view and projection matrix values into the light buffer, these are bound within both passes as I'm trying to get the depth value of the light within the first pass and then used the shadow map on the second. Note the shaders do allow for multiple lights but I'm focusing on using one light to get the shadows working and then I can easily add the rest in.   This is what I have at the moment:   First pass struct PS_OUTPUT {     //Other targets here     /*ShadowMaps*/     float4 light1ViewPos : SV_Target4;     float4 light1ShadowMap : SV_Target5;     /*ShadowMaps*/ }; VS_OUTPUT VS_Main(float3 inPos : POSITION, float2 inTexCoord : TEXCOORD, float3 normal : NORMAL) {     VS_OUTPUT output;     //Camera world view projection transformations here..     /*Light Map*/     output.lightPos = mul(float4(inPos, 1.0f), worldMatrix);     output.lightPos = mul(output.lightPos, lights[0]._viewMatrix);     output.lightPos = mul(output.lightPos, lights[0]._projMatrix);          /*Light Map*/     return output; } PS_OUTPUT PS_Main(VS_OUTPUT input) : SV_TARGET {     PS_OUTPUT output; //other renderTarget values here..          float depth = input.lightPos.z / input.lightPos.w;     output.light1ViewPos = input.lightPos;     output.light1ShadowMap = float4(depth, depth, depth, 1.0f);     return output; } Second pass in the pixel shader:   pixel.lightViewPosition = Light1ViewPosMapTexture.Sample(ObjSamplerState, pixel.texCoord); pixel.lightViewPosition.xyz /= pixel.lightViewPosition.w;   if (pixel.lightViewPosition.x < -1.0f || pixel.lightViewPosition.x > 1.0f || pixel.lightViewPosition.y < -1.0f || pixel.lightViewPosition.y > 1.0f || pixel.lightViewPosition.z < 0.0f || pixel.lightViewPosition.z > 1.0f) return output;     //transform clip space coords to texture space coords (-1:1 to 0:1) pixel.lightViewPosition.x = pixel.lightViewPosition.x / 2 + 0.5; pixel.lightViewPosition.y = pixel.lightViewPosition.y / -2 + 0.5;     float shadowMapBias = 0.2f; pixel.lightViewPosition.z -= shadowMapBias;     float shadowMapDepth = Light1ViewPosMapTexture.Sample(ObjSamplerState, pixel.lightViewPosition.xy).r; worldPosition = WorldPositionTexture.Sample(ObjSamplerState, pixel.texCoord);   if (shadowMapDepth < pixel.lightViewPosition.z) return output;   output.color = float4(1.0f, 1.0f, 1.0f, 1.0f); return output; //Actual lighting calculations after here       The result I'm actually getting is quite odd... it seems to render shadows but they seem to move when the camera moves, meaning the are always in incorrect positions. I have been looking the cause of this for a couple of days with no hope, if any of you could point me to the right direction I would be very appreciated. On a side note the fustrum for the light is working as if I remove the if (shadowMapDepth < pixel.lightViewPosition.z) return output; Then I get a nice square of white light so its deffo something to do with the shadow map.   One question would be if I render the shadow map should it be white or go light to dark with depth because different tutorials show different things for example:   http://www.rastertek.com/dx11tut40.html http://takinginitiative.wordpress.com/2011/05/15/directx10-tutorial-10-shadow-mapping/   Thanks for any help.
  4. KieranHay

    Directx 11 Draw Causing Memory Leak?

    I have used the debug layer of directx and here is the output when my application exits:  I have also tried deleaker and it hasn't found anything. D3D11 WARNING: Live ID3D11Device at 0x006C611C, Refcount: 3 [ STATE_CREATION WARNING #441: LIVE_DEVICE] D3D11 WARNING: Live ID3D11Context at 0x006C9010, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #2097226: LIVE_CONTEXT] D3D11 WARNING: Live ID3DDeviceContextState at 0x006D3010, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #3145742: LIVE_DEVICECONTEXTSTATE] D3D11 WARNING: Live ID3D11BlendState at 0x006D9124, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #435: LIVE_BLENDSTATE] D3D11 WARNING: Live ID3D11DepthStencilState at 0x006D926C, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #436: LIVE_DEPTHSTENCILSTATE] D3D11 WARNING: Live ID3D11RasterizerState at 0x006D93DC, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #437: LIVE_RASTERIZERSTATE] D3D11 WARNING: Live ID3D11Sampler at 0x006D962C, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #434: LIVE_SAMPLER] D3D11 WARNING: Live ID3D11Query at 0x006D9774, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #438: LIVE_QUERY] D3D11 WARNING: Live IDXGISwapChain at 0x006D98C0, Refcount: 0 [ STATE_CREATION WARNING #442: LIVE_SWAPCHAIN] D3D11 WARNING: Live ID3D11Texture2D at 0x006C185C, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D] D3D11 WARNING: Live ID3D11RenderTargetView at 0x006C260C, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #428: LIVE_RENDERTARGETVIEW] D3D11 WARNING: Live ID3D11Texture2D at 0x006C298C, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D] D3D11 WARNING: Live ID3D11DepthStencilView at 0x006C242C, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #429: LIVE_DEPTHSTENCILVIEW] D3D11 WARNING: Live ID3D11VertexShader at 0x006C327C, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #430: LIVE_VERTEXSHADER] D3D11 WARNING: Live ID3D11InputLayout at 0x006C3044, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #433: LIVE_INPUTLAYOUT] D3D11 WARNING: Live ID3D11PixelShader at 0x006DA8A4, Refcount: 0, IntRef: 0 [ STATE_CREATION WARNING #432: LIVE_PIXELSHADER] D3D11 WARNING: Live ID3D11Buffer at 0x006F2A64, IntRef: 0 [ STATE_CREATION WARNING #423: LIVE_BUFFER] D3D11 WARNING: Live ID3D11Buffer at 0x006F2CBC, IntRef: 0 [ STATE_CREATION WARNING #423: LIVE_BUFFER] D3D11 WARNING: Live ID3D11Buffer at 0x006F1E54, IntRef: 0 [ STATE_CREATION WARNING #423: LIVE_BUFFER] D3D11 WARNING: Live ID3D11Buffer at 0x006F345C, IntRef: 0 [ STATE_CREATION WARNING #423: LIVE_BUFFER] D3D11 WARNING: Live ID3D11Buffer at 0x006F36B4, IntRef: 0 [ STATE_CREATION WARNING #423: LIVE_BUFFER] D3D11 WARNING: Live ID3D11Texture2D at 0x006F390C, Refcount: 0, IntRef: 1 [ STATE_CREATION WARNING #425: LIVE_TEXTURE2D] D3D11 WARNING: Process is terminating. Using simple reporting. Please call ReportLiveObjects() at runtime for standard reporting. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Producer at 0x006C6190, Refcount: 2. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006C9010, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006D3010, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006D9124, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006D926C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006D93DC, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006D962C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006D9774, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006D98C0, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006C185C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006C260C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006C298C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006C242C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006C327C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006C3044, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006DA8A4, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006F2A64, Refcount: -1. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006F2CBC, Refcount: -1. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006F1E54, Refcount: -1. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006F345C, Refcount: -1. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006F36B4, Refcount: -1. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x006F390C, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] so that all looks okay to me. I have ran one before and after rendering and they are the same and as expected. However as I've stepped through this many times the memory usage only goes up sometimes and not every render call.       I completely agree, it doesn't increase reference count and that's why I'm confused about memory going up and not going up when its commented out... The GetModel method just returns a pointer to a model.   I was using a list because I was planning on sorting that but using an index array sounds good.   It seems like I am chasing a red herring at the moment and the problem is somewhere else as ankhd said, any ideas?
  5. Hi all...   I'm having a big problem carrying on with my project because within my Renderer Class there seems to be a memory leak being caused by directx DrawIndexed method. However I'm sure it is obviously something I have done incorrectly. I know there's a leak because I have been looking at task managers process list at the memory and it continually rises, if I comment the line out it doesn't rise. The code is below, there is still a bit of refactoring needed to be done any comments are useful. DirectX::XMMATRIX camView = camera->GetCamView(); DirectX::XMMATRIX camProjection = camera->GetCamProjection(); viewCB_.UpdateSubresource(deviceContext, &camView); projCB_.UpdateSubresource(deviceContext, &camProjection); viewCB_.BindBuffer(deviceContext, 1, 1, PIPE_LINE_STAGE::VERTEXSHADER); projCB_.BindBuffer(deviceContext, 2, 1, PIPE_LINE_STAGE::VERTEXSHADER); for (std::list<std::shared_ptr<Object>>::iterator it = _renderQueue.begin(); it != _renderQueue.end(); it++) { //float clearColor[4] = { 0.0f, 0.0f, 0.25f, 1.0f }; unsigned int stride = sizeof(Vertex); unsigned int offset = 0; contentManager->_inputLayoutManager.BindInputLayout(deviceContext, "position"); PurgeModel& tempModel = *contentManager->_purgeModelManager.GetPurgeModel((*it)->GetModelName()); tempModel.GetIndexBuffer()->BindBuffer(deviceContext, DXGI_FORMAT_R32_UINT, 0); tempModel.GetVertexBuffer()->BindBuffer(deviceContext, 0, 1, stride, offset); SetPrimitiveTopology(deviceContext, PRIMITIVE_TOPOLOGY::PRIMITIVE_TOPOLOGY_TRIANGLELIST); contentManager->_shaderManager.BindVertexShader(deviceContext, "test"); // shader name will be in world file contentManager->_shaderManager.BindPixelShader(deviceContext, "test"); worldCB_.UpdateSubresource(deviceContext, &(*it)->cube1World); worldCB_.BindBuffer(deviceContext, 0, 1, PIPE_LINE_STAGE::VERTEXSHADER); int j = tempModel.GetNumIndices(); deviceContext->DrawIndexed(j, 0, 0); // memory leak is here for some reason //deviceContext->GetDeviceContext()->Draw(30, 0); Have tried this too } _renderQueue.clear(); I do call flush later on and I am using ComPtr, any help will be appreciated as have been lost with this for the past few days.   Thanks in advance.    
  6. This I my first post after only just creating my account, what I basically want to do is create a 3D game engine. I know how much of a task this will be and I have many reasons for wanting to do it. I am not hoping for a massive and complex engine just the basics seeing as it would take a team to complete a commercail product.   The reason I want to do this is because I have just completed my second year at university and one of my moduals in the 3rd year will be producing a simple game engine I think in C++. Furthermore to this I am looking to start my own project now so that I am able to get a head start and have somthing up and running before I start. Another reason for doing this is that I have been programming for a while now and have gotten a wide variety of code in multiple projects, examples of these include 3D model loaders, camera systems, management systems in my games for assets, simple scene graph structures, AI using state machines, collision detection and response etc.... I've done these within Opengl and directX 11.   I now want to put these together so I can easily reuse code using object oriented techniques, the problem I am having when starting the engine is how it should be structured. What I mean is how would you seperate the game from the actual engine and also the front interface (GUI). I have been messing around with other engines like unity and have got a good idea but I need more information.   I've been looking at http://www.flipcode.com/archives/Elements_Of_A_Game_Engine.shtml which gave me a good idea too how to put something together and have been looking at multiple books but there ain't much out there on this topic. I am wondering if anyone could give me some pointers or some resource links/ good books that would help.   If anyone has a class diagram that I could look at, I would be very greatful, this will give me the visual aspects of the engine. I wouldn't think the programming language been used would matter because its mainly the theory i'm interested in, but i'm looking at using c++ and XML for saving the game.   Thanks in advance
  • 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!