Jump to content
  • Advertisement
Sign in to follow this  

weird texture issue

This topic is 3456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi So I planned on having simple shadowmapping in my learning app, and I looked on NVIDIA's VSM sample and copy-pasted the code to make the shadowmap texture. Everything seemed fine and I got the linear depth rendered nicely onto my shadowmap texture. But when I tried to apply the texture to a simple vertical quad (just simple basic texturing), the texture got rendered wrong. It looks correct when viewed close, but when I move the camera farther away from the quad, it darkens. This can't be my shader's fault because its a simple float4 color = SMtexture.Sample( samLinear, input.Tex ); return color; I've tried replacing the texture with a loaded bitmap, and this WEIRD DARKENING effect didn't happen. It only happens when I apply that shadowmap texture. So I think the shadowmap somehow screws up texture sampling or something? Resources : ID3D10RenderTargetView* pSMRTV; ID3D10DepthStencilView* pSMDSV; ID3D10Texture2D* pSMZ; ID3D10Texture2D* pSMRT; ID3D10ShaderResourceView* pSMSRV; ID3D10ShaderResourceView* pSMDepthSRV; In OnD3D10CreateDevice() : UINT SMSize = 1024; //NULL out resources pSMZ = NULL; pSMRT = NULL; pSMDSV = NULL; pSMSRV = NULL; //Create our textures D3D10_TEXTURE2D_DESC Desc; Desc.ArraySize = 1; Desc.CPUAccessFlags = 0; Desc.Format = DXGI_FORMAT_R32G32_TYPELESS; Desc.Width = SMSize; Desc.Height = SMSize; Desc.MipLevels = 0; //Full mip-chain Desc.MiscFlags = D3D10_RESOURCE_MISC_GENERATE_MIPS; Desc.SampleDesc.Count = 1; Desc.SampleDesc.Quality = 0; Desc.BindFlags = D3D10_BIND_SHADER_RESOURCE | D3D10_BIND_RENDER_TARGET; Desc.Usage = D3D10_USAGE_DEFAULT; //Create our renderable 2-component texture array pd3dDevice->CreateTexture2D( &Desc, NULL, &pSMRT); _ASSERT( pSMRT ); pSMRT->GetDesc( &Desc ); iMipLevels = Desc.MipLevels; Desc.Width = SMSize; Desc.Height = SMSize; Desc.CPUAccessFlags = 0; Desc.Usage = D3D10_USAGE_DEFAULT; Desc.Format = DXGI_FORMAT_R32_TYPELESS; Desc.BindFlags = D3D10_BIND_DEPTH_STENCIL | D3D10_BIND_SHADER_RESOURCE; Desc.MipLevels = 1; Desc.ArraySize = 1; Desc.MiscFlags = 0; //Create our MSAA depth buffer pd3dDevice->CreateTexture2D( &Desc, NULL, &pSMZ ); D3D10_DEPTH_STENCIL_VIEW_DESC DSVDesc; DSVDesc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D; DSVDesc.Format = DXGI_FORMAT_D32_FLOAT; DSVDesc.Texture2D.MipSlice = 0; //Create our depth stencil view pd3dDevice->CreateDepthStencilView( pSMZ, &DSVDesc, &pSMDSV ); D3D10_RENDER_TARGET_VIEW_DESC RTVDesc; RTVDesc.Format = DXGI_FORMAT_R32G32_FLOAT; RTVDesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D; RTVDesc.Texture2D.MipSlice = 0; //Create our render target view pd3dDevice->CreateRenderTargetView( pSMRT, &RTVDesc, &pSMRTV ); D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc; SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; SRVDesc.Format = DXGI_FORMAT_R32G32_FLOAT; SRVDesc.Texture2D.MipLevels = iMipLevels; SRVDesc.Texture2D.MostDetailedMip = 0; //Create our shader resource view pd3dDevice->CreateShaderResourceView( pSMRT, &SRVDesc, &pSMSRV ); _ASSERT( pSMSRV ); SRVDesc.Format = DXGI_FORMAT_R32_FLOAT; SRVDesc.Texture2D.MipLevels = 1; pd3dDevice->CreateShaderResourceView( pSMZ, &SRVDesc, &pSMDepthSRV ); _ASSERT( pSMDepthSRV ); ZeroMemory( &ShadowMapVP, sizeof( D3D10_VIEWPORT ) ); ShadowMapVP.Height = SMSize; ShadowMapVP.Width = SMSize; ShadowMapVP.MaxDepth = 1.0f; As I said before, this was copy-pasted from NVIDIA's VSM source code. Is there anything wrong with the texture? Also, I can't seem to change the texture's format. If I change it to anything else than R32G32 it returns an error. Please help I'm a n00b.

Share this post

Link to post
Share on other sites
This is somewhat related to your question.. but could you possibly give us an indication of what experience you might have coding against the Direct3D10 SDK?

The reason I am asking is because, let's say that a person is a complete beginner and don't know anything about how things are rendered nor has he/she done the traditional Nehe style tutorials. Then messing with shadowmapping is not really desired.

From my experience, it's sometimes difficult to copy and paste a wud of code into an application and then try to figure out what the developer was doing. I find it easier myself to first understand the theory and then either read the code or scan through it and then implement the solution in my own framework.

With this approach, it gives us on the forums a better idea on where you are coming from and you can also give us a better description of what your problem is.

Share this post

Link to post
Share on other sites
thanks for the reponse
I'm sorry if you feel like I suddenly rushed in without any expalantion.

well I'm not exactly a SUPERNOOB.
I learned DX10 from the tutorials in the SDK.
yes, I have an understanding of how things work. I know the theory behind what i am trying to accomplish.
yes, I know how rendering onto an off-screen texture works, im just a little confused on the DX10 texture creating part.
I wanted to have shadowmapping in my app, so i knew the steps would be:
-first create a texture to store depth
-create a shader to calulate the depth
-set the render target to be that texture and render objects
-project onto scene and compare depths for the actual screen rendering

I knew very well how to do the above, all except the first step. So I thought about tackling it myself, the only thing I didn't know how to do was creating proper textures for shadowmaps in DX10, so I looked in NVIDIA's sample on how to do it. It worked as expected, only there's a weird darkening-on-distance effect.
I tried to not render anything onto the shadowmap and just cleared it to white, it still happened. So the problem seems to be the texture.

here's the problem
even when viewed close, you can see the yellow (because it's a 2-component texture) quad gradienting into black:

moving the camera farther away from the quad, you can see the problem clearly:

Then I tried changing the texture to a premade bitmap for testing, and the problem didn't happen. It's definately the texture.

so I am asking for a little guidance regarding DX10 texture creation. i DID search first. Sorry for asking such a n00by question, but im just stuck.

thank you

Share this post

Link to post
Share on other sites
aaah solved it
the MipLevels should be set to 1

But I have another question
how do I set the depth buffer so the depth distribution is even acros distances, not concentrated near the camera?
Can I? Right now I have the depth calculatd in shader, but that's a waste since I can access the depth buffer and just get the depth from there, but it's not distributed evenly in a w-buffer fashion. How to get the w-buffer instead of zbuffer?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!