Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

A sampled float value in a Texture2D is unexpectedly 1.0 higher.

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 collie   Members   

213
Like
0Likes
Like

Posted 24 March 2014 - 11:15 AM

Hi, I'm rendering to a Texture2D via a pixelshader and everything is working correctly.
The input.depth value being returned from it is 0.045904520.

Texture2D DepthMap : register(t0);
SamplerState DepthMapSampler : register(s0);

float4 txDepthMapPixelShader(in PixelShaderInput_DepthMap input) : SV_TARGET
{  
  return float4(input.depth, 0, 0, 0); <-- 0.045904520
}


When I sample the texture in another pixel shader the depth value has changed to 1.045904520; becoming 1.0 higher.

float4 txPixelShader(in PixelShaderInput input) : SV_TARGET
{
    float2 depthTexCoords = 0.5 * input.vertexPosition2.xy / input.vertexPosition2.w + float2(0.5, 0.5);
    depthTexCoords.y = 1.0f - depthTexCoords.y; // Inverse - good for debugging.

    float depth = DepthMap.Sample(DepthMapSampler, depthTexCoords.xy).r; <-- 1.045904520
    ...


Now I can delete this value by 1.0 to get the effect I desire so it's not really a problem; but I'm curious as to where this additional 1.0 has originated from?
Has anyone got any ideas?  Thank you in advance.

The data structures I use are as follows.

D3D11_TEXTURE2D_DESC depthTextureDesc;
::ZeroMemory(&depthTextureDesc, sizeof(D3D11_TEXTURE2D_DESC));
depthTextureDesc.Width = _windowWidth;
depthTextureDesc.Height = _windowHeight;
depthTextureDesc.MipLevels = 1;
depthTextureDesc.ArraySize = 1;
depthTextureDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
depthTextureDesc.SampleDesc.Count = 1;
depthTextureDesc.Usage = D3D11_USAGE_DEFAULT;
depthTextureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
depthTextureDesc.CPUAccessFlags = 0;
depthTextureDesc.MiscFlags = 0;

hr = _device->CreateTexture2D(&depthTextureDesc, NULL, &_depthDepthStencil);
assert(SUCCEEDED(hr));

D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc;
::ZeroMemory(&shaderResourceViewDesc, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));
shaderResourceViewDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
shaderResourceViewDesc.Texture2D.MostDetailedMip = 0;
shaderResourceViewDesc.Texture2D.MipLevels = 1;

hr = _device->CreateShaderResourceView(_depthDepthStencil, &shaderResourceViewDesc, &_depthResourceView);
assert(SUCCEEDED(hr));

D3D11_RENDER_TARGET_VIEW_DESC depthTargetViewDesc;
::ZeroMemory(&depthTargetViewDesc, sizeof(D3D11_RENDER_TARGET_VIEW_DESC));
depthTargetViewDesc.Format = shaderResourceViewDesc.Format;
depthTargetViewDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
depthTargetViewDesc.Texture2D.MipSlice = 0;

hr = _device->CreateRenderTargetView(_depthDepthStencil, &depthTargetViewDesc, &_depthRenderTargetView);
assert(SUCCEEDED(hr));

D3D11_RASTERIZER_DESC depthRenderStateDesc;
::ZeroMemory(&depthRenderStateDesc, sizeof(D3D11_RASTERIZER_DESC));
depthRenderStateDesc.CullMode = D3D11_CULL_FRONT;
depthRenderStateDesc.FillMode = D3D11_FILL_SOLID;
depthRenderStateDesc.DepthClipEnable = true;

hr = _device->CreateRasterizerState(&depthRenderStateDesc, &_depthRasterState);
assert(SUCCEEDED(hr));

 


Edited by collie, 24 March 2014 - 11:16 AM.


#2 Jason Z   Members   

6430
Like
0Likes
Like

Posted 25 March 2014 - 07:52 PM

Do you have any blend state enabled?  For example, even if you output a depth value, the Output Merger can still modify the value before it gets written to a render target.  Can you double check that the blending is disabled?



#3 collie   Members   

213
Like
0Likes
Like

Posted 29 March 2014 - 02:57 AM

Hi Jason,  Thank you for the reply.

Yes I believe blending was off..

 

D3D11_BLEND_DESC desc;
::ZeroMemory(&desc, sizeof(D3D11_BLEND_DESC));
desc.RenderTarget[0].BlendEnable = FALSE;

...

 

Regards






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.