Texture render target size

Started by
10 comments, last by JohnnyCode 9 years, 2 months ago

After few completed projects with DirectX 9 i started to learn DirectX 11. Now i'm trying to implement blured shadow maps but i have problems render the scene to textures. When i render the first scene depths to shadow map texture, the image is a bit distored. Then i use orthogonal projection to render this texture to a temporary quad with x blur shader then back to shadow map texture with y blur shader but the final result is completly distored.

In RasterTek tutorial i somewhere readed that render target textures need to have the same aspect ratio like screen.

So i tried to create render target textures every time the window is resized with half the window width and height but not even this worked so i created these textures with original window width and height and only that worked so far.

So now i have a question. Is it somehow possible to create render target textures with custom size?

Advertisement

So now i have a question. Is it somehow possible to create render target textures with custom size?

Of course it is. I'm not sure why the Rastertek tutorial is giving you wrong information, or if you've somehow misread it, but you can create a rendertarget at any size, and there are no restrictions beyond the normal max texture size which applies to any texture you create.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Problem isn't creating custom sized texture, problem is using custom size texture as render target.

I show it, these are textures with screen size:

depth:

http://postimg.org/image/6op6bvezj/

blur:

http://postimg.org/image/6431k9ibt/

These are textures with size 1024 x 1024:

depth:

http://postimg.org/image/k3c8wuaoh/

blur:

http://postimg.org/image/bufazvrex/

Rendered scene wont fit into that texture.

To help you, it's first necessary to understand clearly what you want to do. From your description, it sounds like what you want to do is to render a scene with shadows to a texture.

Is that correct?

In any case, describe what it is you want to do, rather than how you're doing it. You won't get any useful help trying fix something that is incorrect to begin with.


When i render the first scene depths to shadow map texture, the image is a bit distored.

The first and second pictures you provide links to apparently show the shadow depth map in a quad. If so, the shadow map appears correct. I.e., first image - depth map correct, maybe with orthogonal projection? Second image - blurred depth map correct. IF the quad has the same aspect ratio as the texture, there appears to be no distortion. Why do you think it's distorted?

In the third and fourth pictures you provide links to, it's not clear exactly what the red-and-black images are. The third image appears to be the original unblurred depth map rendered somehow with a different view, perhaps a perspective (vs. orthogonal) projection? The fourth image appears to be the blurred depth map rendered with yet a different view?

A general comment which may help: when you sample the depth texture, you must sample it using tex coords calculated from positions calculated from the view and projection matrices used to render the depth map, not the positions calculated from the view and projection matrices used to render the scene.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

What i want to do: i want to apply blured shadows to my scene. I know how shadow maps work.

First i render the scene depths from point of light with (yes) orthogonal projection matrix to a texture. First image

Then i apply blur efect to this texture. Second image.

Then i use this texture to determine whitch parts of the rendered scene are in shadows.


In the third and fourth pictures you provide links to, it's not clear exactly what the red-and-black image is. The third image appears to be the original unblurred depth map rendered somehow with a different view, perhaps a perspective (vs. orthogonal) projection? The fourth image appears to be the blurred depth map rendered with yet a different view?

Now this is where things get complicated. The third image is renderd in the same way as the first. Same projection matrix. The fourth image is the same as the second image. Same blur effect same projection matrix. The only difference between first/third, second/fourth image is the size of texture to whitch i render. First and second textures have same size as screen and third and fourth have size 1024 x 1024.


I know how shadow maps work.

If you're not getting the results you expect, you'll have to accept you're doing something incorrectly. If you're going to be offended and respond like that to comments posted in good faith, you won't get the help you're asking for. That response doesn't provide any information that will help anyone help you.


the final result is completly distored.


Can you describe what "completely distor[t]ed" means, and post a final shadowed scene rendered with the 1024x1024 unblurred shadowmap? EDIT: It might be useful if you posted a pix of the final shadowed scene rendered with the window width/height shadowmap, also.

FYI, the shadowmap quad displays appear to all be the same aspect ratio for both non-square and square textures. If you want to display the shadowmap, that's fine, but at least display the texture with the proper aspect ratio. In any case, without knowing exactly how that quad display is generated and rendered, it's difficult to derive any technical information from them, or make any conclusions about yet-to-be-defined "distortion."

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Scene rendered with shadows:

Here size of shadow map texture is same as size of window:

http://postimg.org/image/oiliy12xp/

Here size of shadow map is 1024x1024, different than size of window:

http://postimg.org/image/cz226jcgh/

Maybe i asked a wrong question in the first place.

This is how i switch render targets:


	ID3D11RenderTargetView *prentw = 0;
	ID3D11DepthStencilView *dsw = 0;
	float ClearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };

	pd3dImmediateContext->OMGetRenderTargets(1, &prentw, &dsw);
	pd3dImmediateContext->OMSetRenderTargets(1, &m_ShadowCtrl->m_pShadowRTV[0], m_ShadowCtrl->m_pDSV);
	pd3dImmediateContext->ClearDepthStencilView(m_ShadowCtrl->m_pDSV, D3D11_CLEAR_DEPTH, 1.0, 0);
	pd3dImmediateContext->ClearRenderTargetView(m_ShadowCtrl->m_pShadowRTV[0], ClearColor);

//
// rendering
//

	pd3dImmediateContext->OMSetRenderTargets(1, &prentw, dsw);
	SAFE_RELEASE(dsw);
	SAFE_RELEASE(prentw);

After pd3dImmediateContext->OMSetRenderTargets(1, &m_ShadowCtrl->m_pShadowRTV[0], m_ShadowCtrl->m_pDSV); the size of render target changes from size of window to size of texture.

Does ID3D11DeviceContext know that the size changed? If no, how do i tell him?


the size of render target changes from size of window to size of texture.

IF your posted code is for rendering just depth (to the depth map,) is there a reason you're binding a render target (and clearing it)?


Does ID3D11DeviceContext know that the size changed?

Yes. See the docs for ID3D11DeviceContext::OMSetRenderTargets - in particular "...all of the render-target views must have the same array size. This restriction also applies to the depth-stencil view, its array size must match that of the render-target views being bound." You'll get debug errors if sizes differ.

EDIT: The "1024" picture you posted doesn't really look like distortion. Rather, it looks to me like incorrectly calculated tex coords for depth map texture sampling. Do you set the depth texture width/height parameters used in the tex coords calculation correctly in your scene pixel shader?

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Well, you must still set the correct viewport. I don't see you doing that.

Well, you must still set the correct viewport. I don't see you doing that.

I believe he desn't, he changes the targets and thus their very entire dimensions. As buckeye mentioned, he needs to make sure there are depth/stencil buffers of the same dimensions as current render target dimensions, corectly incorporated . That should get him straight on the go

This topic is closed to new replies.

Advertisement