• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By fs1
      I have been trying to see how the ID3DInclude, and how its methods Open and Close work.
      I would like to add a custom path for the D3DCompile function to search for some of my includes.
      I have not found any working example. Could someone point me on how to implement these functions? I would like D3DCompile to look at a custom C:\Folder path for some of the include files.
      Thanks
    • By stale
      I'm continuing to learn more about terrain rendering, and so far I've managed to load in a heightmap and render it as a tessellated wireframe (following Frank Luna's DX11 book). However, I'm getting some really weird behavior where a large section of the wireframe is being rendered with a yellow color, even though my pixel shader is hard coded to output white. 

      The parts of the mesh that are discolored changes as well, as pictured below (mesh is being clipped by far plane).

      Here is my pixel shader. As mentioned, I simply hard code it to output white:
      float PS(DOUT pin) : SV_Target { return float4(1.0f, 1.0f, 1.0f, 1.0f); } I'm completely lost on what could be causing this, so any help in the right direction would be greatly appreciated. If I can help by providing more information please let me know.
    • By evelyn4you
      Hello,
      i try to implement voxel cone tracing in my game engine.
      I have read many publications about this, but some crucial portions are still not clear to me.
      At first step i try to emplement the easiest "poor mans" method
      a.  my test scene "Sponza Atrium" is voxelized completetly in a static voxel grid 128^3 ( structured buffer contains albedo)
      b. i dont care about "conservative rasterization" and dont use any sparse voxel access structure
      c. every voxel does have the same color for every side ( top, bottom, front .. )
      d.  one directional light injects light to the voxels ( another stuctured buffer )
      I will try to say what i think is correct ( please correct me )
      GI lighting a given vertecie  in a ideal method
      A.  we would shoot many ( e.g. 1000 ) rays in the half hemisphere which is oriented according to the normal of that vertecie
      B.  we would take into account every occluder ( which is very much work load) and sample the color from the hit point.
      C. according to the angle between ray and the vertecie normal we would weigth ( cosin ) the color and sum up all samples and devide by the count of rays
      Voxel GI lighting
      In priciple we want to do the same thing with our voxel structure.
      Even if we would know where the correct hit points of the vertecie are we would have the task to calculate the weighted sum of many voxels.
      Saving time for weighted summing up of colors of each voxel
      To save the time for weighted summing up of colors of each voxel we build bricks or clusters.
      Every 8 neigbour voxels make a "cluster voxel" of level 1, ( this is done recursively for many levels ).
      The color of a side of a "cluster voxel" is the average of the colors of the four containing voxels sides with the same orientation.

      After having done this we can sample the far away parts just by sampling the coresponding "cluster voxel with the coresponding level" and get the summed up color.
      Actually this process is done be mip mapping a texture that contains the colors of the voxels which places the color of the neighbouring voxels also near by in the texture.
      Cone tracing, howto ??
      Here my understanding is confus ?? How is the voxel structure efficiently traced.
      I simply cannot understand how the occlusion problem is fastly solved so that we know which single voxel or "cluster voxel" of which level we have to sample.
      Supposed,  i am in a dark room that is filled with many boxes of different kind of sizes an i have a pocket lamp e.g. with a pyramid formed light cone
      - i would see some single voxels near or far
      - i would also see many different kind of boxes "clustered voxels" of different sizes which are partly occluded
      How do i make a weighted sum of this ligting area ??
      e.g. if i want to sample a "clustered voxel level 4" i have to take into account how much per cent of the area of this "clustered voxel" is occluded.
      Please be patient with me, i really try to understand but maybe i need some more explanation than others
      best regards evelyn
       
       
    • By Endemoniada

      Hi guys, when I do picking followed by ray-plane intersection the results are all wrong. I am pretty sure my ray-plane intersection is correct so I'll just show the picking part. Please take a look:
       
      // get projection_matrix DirectX::XMFLOAT4X4 mat; DirectX::XMStoreFloat4x4(&mat, projection_matrix); float2 v; v.x = (((2.0f * (float)mouse_x) / (float)screen_width) - 1.0f) / mat._11; v.y = -(((2.0f * (float)mouse_y) / (float)screen_height) - 1.0f) / mat._22; // get inverse of view_matrix DirectX::XMMATRIX inv_view = DirectX::XMMatrixInverse(nullptr, view_matrix); DirectX::XMStoreFloat4x4(&mat, inv_view); // create ray origin (camera position) float3 ray_origin; ray_origin.x = mat._41; ray_origin.y = mat._42; ray_origin.z = mat._43; // create ray direction float3 ray_dir; ray_dir.x = v.x * mat._11 + v.y * mat._21 + mat._31; ray_dir.y = v.x * mat._12 + v.y * mat._22 + mat._32; ray_dir.z = v.x * mat._13 + v.y * mat._23 + mat._33;  
      That should give me a ray origin and direction in world space but when I do the ray-plane intersection the results are all wrong.
      If I click on the bottom half of the screen ray_dir.z becomes negative (more so as I click lower). I don't understand how that can be, shouldn't it always be pointing down the z-axis ?
      I had this working in the past but I can't find my old code
      Please help. Thank you.
    • By turanszkij
      Hi,
      I finally managed to get the DX11 emulating Vulkan device working but everything is flipped vertically now because Vulkan has a different clipping space. What are the best practices out there to keep these implementation consistent? I tried using a vertically flipped viewport, and while it works on Nvidia 1050, the Vulkan debug layer is throwing error messages that this is not supported in the spec so it might not work on others. There is also the possibility to flip the clip scpace position Y coordinate before writing out with vertex shader, but that requires changing and recompiling every shader. I could also bake it into the camera projection matrices, though I want to avoid that because then I need to track down for the whole engine where I upload matrices... Any chance of an easy extension or something? If not, I will probably go with changing the vertex shaders.
  • Advertisement
  • Advertisement
Sign in to follow this  

DX11 Rendering depth complexity (luna d3d11 ch10 ex8)

This topic is 866 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,

I've been struggling to do one of the exercises of the d3d11 book I'm working my way through.

The goal:

 

1 - render a scene first only to the stencil buffer, using STENCIL_OP_INCR and COMPARISON_ALWAYS, that way for each pixel I count the number of times something is written to that pixel on the stencil buffer

(i.e. when a specific pixel is increased 3 times, that pixel would have been 'overdrawn' 2 times)

2 - render the depth complexity of the scene to the render target, using the data on the stencil buffer.

By using a depthstencilstate with STENCIL_OP_KEEP, so the stencil buffer isn't modified anymore.

Using COMPARISON_EQUAL should enable me to draw the different levels of complexity, using colored quads.
I.e.: a red quad for all pixels with stencil ref/ depth complexity 1

green quad for stencil ref/ depth complexity 2 etc.

 

In the end it should look something like the screenshot below.

 

So far, I managed to render the scene only to the stencil buffer (not to render target) and create a depthstencil state that takes care of the 'counting'. After that I've set back the renderstate and depth stencil state to render to the render target again.

 

From here I'm stuck, how should I proceed to render the 'quads' using the depthstencilstate and the 'content' currently on the stencil bufer?

 

The code:

// the different states
	// BLEND state: Transparent
	D3D11_BLEND_DESC transparentDesc = {0};
	transparentDesc.AlphaToCoverageEnable = false;
	transparentDesc.IndependentBlendEnable = false;

	transparentDesc.RenderTarget[0].BlendEnable		= true;								// PRACTICE: EXERCISE 2
	transparentDesc.RenderTarget[0].SrcBlend		= D3D11_BLEND_SRC_ALPHA;		
	transparentDesc.RenderTarget[0].DestBlend		= D3D11_BLEND_INV_SRC_ALPHA;		
	transparentDesc.RenderTarget[0].BlendOp			= D3D11_BLEND_OP_ADD;				
	transparentDesc.RenderTarget[0].SrcBlendAlpha		= D3D11_BLEND_ONE;			
	transparentDesc.RenderTarget[0].DestBlendAlpha		= D3D11_BLEND_ZERO;
	transparentDesc.RenderTarget[0].BlendOpAlpha		= D3D11_BLEND_OP_ADD;			
	transparentDesc.RenderTarget[0].RenderTargetWriteMask	= D3D11_COLOR_WRITE_ENABLE_ALL;

	HR(device->CreateBlendState(&transparentDesc, &mTransparentBS));

	// BLEND state: Transparent => NO WRITING TO RENDER TARGET
	D3D11_BLEND_DESC transparentNoWriteDesc = {0};
	transparentNoWriteDesc.AlphaToCoverageEnable = false;
	transparentNoWriteDesc.IndependentBlendEnable = false;

	transparentNoWriteDesc.RenderTarget[0].BlendEnable	= true;								// PRACTICE: EXERCISE 2
	transparentNoWriteDesc.RenderTarget[0].SrcBlend		= D3D11_BLEND_SRC_ALPHA;
	transparentNoWriteDesc.RenderTarget[0].DestBlend	= D3D11_BLEND_INV_SRC_ALPHA;
	transparentNoWriteDesc.RenderTarget[0].BlendOp		= D3D11_BLEND_OP_ADD;
	transparentNoWriteDesc.RenderTarget[0].SrcBlendAlpha	= D3D11_BLEND_ONE;
	transparentNoWriteDesc.RenderTarget[0].DestBlendAlpha	= D3D11_BLEND_ZERO;
	transparentNoWriteDesc.RenderTarget[0].BlendOpAlpha	= D3D11_BLEND_OP_ADD;	
	transparentNoWriteDesc.RenderTarget[0].RenderTargetWriteMask	= 0;

	HR(device->CreateBlendState(&transparentNoWriteDesc, &mTransparentNoWriteBS));

	// BLEND STATE: NO WRITING TO THE RENDER TARGET
	D3D11_BLEND_DESC noRenderTargetDesc = {0};
	noRenderTargetDesc.AlphaToCoverageEnable = false;
	noRenderTargetDesc.IndependentBlendEnable = false;

	noRenderTargetDesc.RenderTarget[0].BlendEnable    = false;
	noRenderTargetDesc.RenderTarget[0].SrcBlend       = D3D11_BLEND_ONE;
	noRenderTargetDesc.RenderTarget[0].DestBlend      = D3D11_BLEND_ZERO;
	noRenderTargetDesc.RenderTarget[0].BlendOp        = D3D11_BLEND_OP_ADD;
	noRenderTargetDesc.RenderTarget[0].SrcBlendAlpha  = D3D11_BLEND_ONE;
	noRenderTargetDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
	noRenderTargetDesc.RenderTarget[0].BlendOpAlpha   = D3D11_BLEND_OP_ADD;
	noRenderTargetDesc.RenderTarget[0].RenderTargetWriteMask = 0;

	HR(device->CreateBlendState(&noRenderTargetDesc, &mNoRenderTargetWriteBS));

	// DEPTH STENCIL STATE: FOR REFERENCE COUNTING OF DEPTH COMPLEXITY THROUGH STENCIL BUFFER
	D3D11_DEPTH_STENCIL_DESC stencilOnlyDesc;
	stencilOnlyDesc.DepthEnable      = true;
	stencilOnlyDesc.DepthWriteMask   = D3D11_DEPTH_WRITE_MASK_ZERO;
    	stencilOnlyDesc.DepthFunc        = D3D11_COMPARISON_LESS; 
    	stencilOnlyDesc.StencilEnable    = true;
    	stencilOnlyDesc.StencilReadMask  = 0xff;
    	stencilOnlyDesc.StencilWriteMask = 0xff;

    	stencilOnlyDesc.FrontFace.StencilFailOp      = D3D11_STENCIL_OP_KEEP;
	stencilOnlyDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
	stencilOnlyDesc.FrontFace.StencilPassOp      = D3D11_STENCIL_OP_INCR;		// counter for depth complexity per pixel
	stencilOnlyDesc.FrontFace.StencilFunc        = D3D11_COMPARISON_ALWAYS;		// count all pixels

		// these don't matter, because rendering only frontfacing polys
   	stencilOnlyDesc.BackFace.StencilFailOp       = D3D11_STENCIL_OP_KEEP;
	stencilOnlyDesc.BackFace.StencilDepthFailOp  = D3D11_STENCIL_OP_KEEP;
	stencilOnlyDesc.BackFace.StencilPassOp       = D3D11_STENCIL_OP_REPLACE;
	stencilOnlyDesc.BackFace.StencilFunc         = D3D11_COMPARISON_ALWAYS;

	HR(device->CreateDepthStencilState(&stencilOnlyDesc, &mComparisonAlwaysDSS));

	// DEPTH STENCIL STATE: FOR RENDERING THE DEPTH COMPLEXITY 
	D3D11_DEPTH_STENCIL_DESC stencilEqualsDesc;
	stencilEqualsDesc.DepthEnable      = true;
	stencilEqualsDesc.DepthWriteMask   = D3D11_DEPTH_WRITE_MASK_ZERO;
    	stencilEqualsDesc.DepthFunc        = D3D11_COMPARISON_EQUAL; 
    	stencilEqualsDesc.StencilEnable    = true;
    	stencilEqualsDesc.StencilReadMask  = 0xff;
    	stencilEqualsDesc.StencilWriteMask = 0xff;

    	stencilEqualsDesc.FrontFace.StencilFailOp      = D3D11_STENCIL_OP_KEEP;
	stencilEqualsDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
	stencilEqualsDesc.FrontFace.StencilPassOp      = D3D11_STENCIL_OP_KEEP;		// no changes needed
	stencilEqualsDesc.FrontFace.StencilFunc        = D3D11_COMPARISON_EQUAL;	// only the matching ones

		// these don't matter, because rendering only frontfacing polys
    	stencilEqualsDesc.BackFace.StencilFailOp       = D3D11_STENCIL_OP_KEEP;
	stencilEqualsDesc.BackFace.StencilDepthFailOp  = D3D11_STENCIL_OP_KEEP;
	stencilEqualsDesc.BackFace.StencilPassOp       = D3D11_STENCIL_OP_REPLACE;
	stencilEqualsDesc.BackFace.StencilFunc         = D3D11_COMPARISON_ALWAYS;

	HR(device->CreateDepthStencilState(&stencilEqualsDesc, &mComparisonEqualsDSS));

// the rendering part
void BlendApp::DrawScene()
{
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};

	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Black));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(InputLayouts::mBasic32);
    	md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	//DrawSceneNormal();

	/**** 1: RENDER THE SCENE FIRST ONLY TO THE STENCIL BUFFER *****/
	md3dImmediateContext->OMSetDepthStencilState(RenderStates::mComparisonAlwaysDSS, 0);
	md3dImmediateContext->OMSetBlendState(RenderStates::mNoRenderTargetWriteBS, blendFactor, 0xffffffff);

	DrawSceneToStencil();
	HR(mSwapChain->Present(0, 0));

	/**** 2: RENDER SCENE TO RENDER TARGET USING STENCIL D3DOP_COMPARISON_EQUAL ****/
	/**** ONE QUAD PER DEPTH COMPLEXITY, DIFFERENT COLORS *****/
	md3dImmediateContext->OMSetDepthStencilState(RenderStates::mComparisonEqualsDSS, 0);
	md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);

	DrawSceneDepthComplexity();

	HR(mSwapChain->Present(0, 0));
}

// render only to the stencil buffer
void BlendApp::DrawSceneToStencil()
{
	XMMATRIX view  = XMLoadFloat4x4(&mMatView);
	XMMATRIX proj  = XMLoadFloat4x4(&mMatProj);
	XMMATRIX viewProj = view*proj;

	// per frame constants - update
	Effects::mBasicFX->SetDirLights(mDirLights);
	Effects::mBasicFX->SetEyePosW(mEyePosW);
	Effects::mBasicFX->SetFogColor(Colors::Silver);
	Effects::mBasicFX->SetFogStart(15.0f);
	Effects::mBasicFX->SetFogRange(175.0f);
	
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};

	UINT stride = sizeof(Vertex::Basic32);
    	UINT offset = 0;
	
	ID3DX11EffectTechnique* boxTech = Effects::mBasicFX->mLight3TexAlphaClipTech;
	ID3DX11EffectTechnique* landAndWavesTech = Effects::mBasicFX->mLight3TexTech;

	D3DX11_TECHNIQUE_DESC techDesc;

	// draw box with alpha clipping
	boxTech->GetDesc(&techDesc);
	for(UINT p=0;p<techDesc.Passes;++p)
    	{
		md3dImmediateContext->IASetVertexBuffers(0, 1, &mBoxVtxBuffer, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(mBoxIndexBuffer, DXGI_FORMAT_R32_UINT, 0);

		// per object constants - update
		XMMATRIX world = XMLoadFloat4x4(&mMatWorldBox);
		XMMATRIX worldInvTranspose = CMathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;
		
		Effects::mBasicFX->SetWorld(world);
		Effects::mBasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::mBasicFX->SetWorldViewProj(worldViewProj);
		Effects::mBasicFX->SetTexTransform(XMMatrixIdentity());
		Effects::mBasicFX->SetMaterial(mMatBox);
		Effects::mBasicFX->SetDiffuseMap(mBoxMapSRV);

		// render state: no culling (inside and outside!)
		md3dImmediateContext->RSSetState(RenderStates::mNoCullRS);
		boxTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(36, 0, 0);

		// restore default render state
		md3dImmediateContext->RSSetState(0);
	}

	// draw hills and waves (no alpha clipping)
	landAndWavesTech->GetDesc(&techDesc);
    	for(UINT p=0;p<techDesc.Passes;++p)
    	{
		// hills
		md3dImmediateContext->IASetVertexBuffers(0, 1, &mLandVtxBuffer, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(mLandIndexBuffer, DXGI_FORMAT_R32_UINT, 0);

		// per object constants - update
		XMMATRIX world = XMLoadFloat4x4(&mMatWorldLand);
		XMMATRIX worldInvTranspose = CMathHelper::InverseTranspose(world);
		XMMATRIX worldViewProj = world*view*proj;
		
		Effects::mBasicFX->SetWorld(world);
		Effects::mBasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::mBasicFX->SetWorldViewProj(worldViewProj);
		Effects::mBasicFX->SetTexTransform(XMLoadFloat4x4(&mGrassTexTransform));
		Effects::mBasicFX->SetMaterial(mMatLand);
		Effects::mBasicFX->SetDiffuseMap(mGrassMapSRV);

		landAndWavesTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(mLandIndexCount, 0, 0);

		// waves
		md3dImmediateContext->IASetVertexBuffers(0, 1, &mWavesVtxBuffer, &stride, &offset);
		md3dImmediateContext->IASetIndexBuffer(mWavesIndexBuffer, DXGI_FORMAT_R32_UINT, 0);

		// per object constants - update
		world = XMLoadFloat4x4(&mMatWorldWaves);
		worldInvTranspose = CMathHelper::InverseTranspose(world);
		worldViewProj = world*view*proj;
		
		Effects::mBasicFX->SetWorld(world);
		Effects::mBasicFX->SetWorldInvTranspose(worldInvTranspose);
		Effects::mBasicFX->SetWorldViewProj(worldViewProj);
		Effects::mBasicFX->SetTexTransform(XMLoadFloat4x4(&mWaterTexTransform));
		Effects::mBasicFX->SetMaterial(mMatWaves);
		Effects::mBasicFX->SetDiffuseMap(mWavesMapSRV);

		// blending state: transparent	=> no render target writing
		md3dImmediateContext->OMSetBlendState(RenderStates::mTransparentNoWriteBS, blendFactor, 0xffffffff);

		landAndWavesTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);
		md3dImmediateContext->DrawIndexed(3*mWaves.TriangleCount(), 0, 0);

		// restore default blending state
		md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);

		// RESTORE STATES
		md3dImmediateContext->OMSetDepthStencilState(0, 0);	
		md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);
	}

}

?

void BlendApp::DrawSceneDepthComplexity()
{
	// defining the colors for visualizing depth complexity
	XMVECTORF32 Colors[5]	=	{1.0f, 0.0f, 0.0f, 1.0f},		// RED
								{0.0f, 1.0f, 0.0f, 1.0f},		// GREEN
								{0.0f, 0.0f, 1.0f, 1.0f},		// BLUE
								{1.0f, 1.0f, 0.0f, 1.0f},		// YELLOW
								{0.0f, 1.0f, 1.0f, 1.0f};		// CYAN

	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Black));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);

	md3dImmediateContext->IASetInputLayout(InputLayouts::mBasic32);
    md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	for(int i=0;i<5;++i)
	{
		md3dImmediateContext->OMSetDepthStencilState(RenderStates::mComparisonAlwaysDSS, i);
		
		// draw the quad using stencil buffer data?

	}
}

Any input is appreciated.

The end result should be something like this:

Fig10-13.jpg

Edited by cozzie

Share this post


Link to post
Share on other sites
Advertisement

Yes, looping over all colors/values, incrementing the stencil reference value and using a simple pixel shader where you can set the output color.

 

It should be noted that with the appropriate formats one can sample the stencil like a texture directly  (e.g. R24G8_TYPELESS for depth/stencil texture, D24_UNORM_S8_UINT for the depth stencil view and X24_TYPELESS_G8_UINT for the stencil shader resource view), so this can be done drawing one full-screen quad/triangle only.

Share this post


Link to post
Share on other sites

Thanks. I think I understand what you mean, but don't understand how I would achieve that.

I've updated the thread with how far I've gotten.

 

I can create a new technique calling a new pixel shader that will render a pixel to a specified color, which I can change with a extern color variable in the CBuffer (shader constant). Do I have to create an 'object' with 4 vertices to draw the fullscreen quad, or is there a better/ easier way for this purpose?

cbuffer cbPerColor
{
	float4	gColor;
}; 

float4 PScolorOnly(VertexOut pin) : SV_Target
{
	float4 Color = gColor;
    return Color;
}


technique11 ColorSpecified
{
    pass P0
    {
        SetVertexShader(CompileShader( vs_5_0, VS()));
		SetGeometryShader( NULL );
        SetPixelShader(CompileShader(ps_5_0, PScolorOnly()));
    }
}


Edited by cozzie

Share this post


Link to post
Share on other sites
You can, but for full-screen drawing (post-process and the like) a vertex shader generated triangle does the job (page 14 of Vertex Shader Tricks). No buffers, no input layout needed. (Edit: You wouldn't even need tex-coords in this case).
 

//draw the quad using stencil buffer data?

 
Not sure if there's a misunderstanding. You don't use the data directly. Pixels will only get drawn where the stencil value is equal to the reference value. By the way: You want to use mComparisonEqualsDSS now. Also: It's probably better to disable depth test and write for that DSS completely. Edited by unbird

Share this post


Link to post
Share on other sites

Thanks, I think I'm getting there.

Things done:

- technique and pixel shader created and tested individually (using DrawSceneNormal), that works fine

- changed the DSS as you said, disabled the depth test/write there

- nearly there with the DrawSceneDepthComplexity function

	// DEPTH STENCIL STATE: FOR RENDERING THE DEPTH COMPLEXITY 
	D3D11_DEPTH_STENCIL_DESC stencilEqualsDesc;
	stencilEqualsDesc.DepthEnable      = false;
	stencilEqualsDesc.DepthWriteMask   = D3D11_DEPTH_WRITE_MASK_ZERO;
    stencilEqualsDesc.DepthFunc        = D3D11_COMPARISON_EQUAL; 
    stencilEqualsDesc.StencilEnable    = true;
    stencilEqualsDesc.StencilReadMask  = 0xff;
    stencilEqualsDesc.StencilWriteMask = 0xff;

    stencilEqualsDesc.FrontFace.StencilFailOp      = D3D11_STENCIL_OP_KEEP;
	stencilEqualsDesc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
	stencilEqualsDesc.FrontFace.StencilPassOp      = D3D11_STENCIL_OP_KEEP;		// no changes needed
	stencilEqualsDesc.FrontFace.StencilFunc        = D3D11_COMPARISON_EQUAL;		// only the matching ones

		// these don't matter, because rendering only frontfacing polys
    stencilEqualsDesc.BackFace.StencilFailOp       = D3D11_STENCIL_OP_KEEP;
	stencilEqualsDesc.BackFace.StencilDepthFailOp  = D3D11_STENCIL_OP_KEEP;
	stencilEqualsDesc.BackFace.StencilPassOp       = D3D11_STENCIL_OP_REPLACE;
	stencilEqualsDesc.BackFace.StencilFunc         = D3D11_COMPARISON_ALWAYS;

	HR(device->CreateDepthStencilState(&stencilEqualsDesc, &mComparisonEqualsDSS));

void BlendApp::DrawSceneDepthComplexity()
{
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dImmediateContext->OMSetDepthStencilState(RenderStates::mComparisonEqualsDSS, 0);
	md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);

	// defining the colors for visualizing depth complexity
	XMVECTORF32 Colors[5]	=	{(1.0f, 0.0f, 0.0f, 1.0f),		// RED
								 (0.0f, 1.0f, 0.0f, 1.0f),		// GREEN
								 (0.0f, 0.0f, 1.0f, 1.0f),		// BLUE
								 (1.0f, 1.0f, 0.0f, 1.0f),		// YELLOW
								 (0.0f, 1.0f, 1.0f, 1.0f)};		// CYAN

	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Black));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);			// DON'T CLEAR THE STENCIL BUFFER

	md3dImmediateContext->IASetInputLayout(InputLayouts::mBasic32);
    md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	ID3DX11EffectTechnique* quadTech = Effects::mBasicFX->mColorOnlyTech;
	D3DX11_TECHNIQUE_DESC techDesc;

    for(UINT p=0;p<techDesc.Passes;++p)
	{
		for(int i=0;i<5;++i)
		{
			md3dImmediateContext->OMSetDepthStencilState(RenderStates::mComparisonAlwaysDSS, i);
	
			XMVECTORF32 tstColor =	Colors[i];
			Effects::mBasicFX->SetQuadColor(tstColor);


			quadTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);

			// draw the quad using stencil buffer data?
			// ....
		}
	}
}

The 'only' thing I don't understand yet I have to actually 'draw'

Share this post


Link to post
Share on other sites
Use that vertex shader I linked to and call md3dImmediateContext->Draw(3,0). Again: No vertex/index buffers bound to the input assembler stage (explicitly set them to null), set input layout to null and topology to triangle list. (Code is on page 13 by the way). Edited by unbird

Share this post


Link to post
Share on other sites

Just a short update, after introducing the new VS.

- I understand the principle and approach

- new VS added and technique changed to use the new VS

-- two things not solved yet

 

1. the new VS needs a "uint id: SV_VERTEXID" as input, what should I pass as parameter in the technique?

(I tried '0', but that didn't work out/ compile)

2. my currect vertex output structure has a float3 for position (world pos) and has no color component.

So I've removed the . w value from the VS and the assignment of the color. Is this OK or should I make a new definition for the VS output for this specific case?

 

Here's the code so far.

Rendering the depth complexity:

void BlendApp::DrawSceneDepthComplexity()
{
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dImmediateContext->OMSetDepthStencilState(RenderStates::mComparisonEqualsDSS, 0);
	md3dImmediateContext->OMSetBlendState(0, blendFactor, 0xffffffff);

	// defining the colors for visualizing depth complexity
	XMVECTORF32 Colors[5]	=	{(1.0f, 0.0f, 0.0f, 1.0f),		// RED
								 (0.0f, 1.0f, 0.0f, 1.0f),		// GREEN
								 (0.0f, 0.0f, 1.0f, 1.0f),		// BLUE
								 (1.0f, 1.0f, 0.0f, 1.0f),		// YELLOW
								 (0.0f, 1.0f, 1.0f, 1.0f)};		// CYAN

	md3dImmediateContext->ClearRenderTargetView(mRenderTargetView, reinterpret_cast<const float*>(&Colors::Black));
	md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH, 1.0f, 0);			// DON'T CLEAR THE STENCIL BUFFER

	md3dImmediateContext->IASetInputLayout(NULL);
    md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	ID3DX11EffectTechnique* quadTech = Effects::mBasicFX->mColorOnlyTech;
	D3DX11_TECHNIQUE_DESC techDesc;

    for(UINT p=0;p<techDesc.Passes;++p)
	{
		for(int i=0;i<5;++i)
		{
			md3dImmediateContext->IASetVertexBuffers(0, 0, NULL, NULL, NULL);
			md3dImmediateContext->IASetIndexBuffer(NULL, (DXGI_FORMAT)0, 0);		
			
			md3dImmediateContext->OMSetDepthStencilState(RenderStates::mComparisonAlwaysDSS, i);
	
			XMVECTORF32 tstColor =	Colors[i];
			Effects::mBasicFX->SetQuadColor(tstColor);

			quadTech->GetPassByIndex(p)->Apply(0, md3dImmediateContext);

			md3dImmediateContext->Draw(3, 0);
		}
	}
}

The VS, PS and technique (with now the 2 remaining issues described above):

VertexOut VSfullscreenQuad(uint id:SV_VERTEXID)
{
	VertexOut output;
	
	// generate clip space position
	output.PosW.x = (float)(id / 2) * 4.0 - 1.0f;
	output.PosW.x = (float)(id % 2) * 4.0 - 1.0f;
	output.PosW.z = 0.0f;
	//output.PosW.w = 1.0f;

	// texture coordinates
	output.Tex.x = (float)(id / 2) * 2.0f;
	output.Tex.x = 1.0f - (float)(id % 2) * 2.0f;
	
	// color
	//output.color = float4(1, 1, 1, 1);

	return output;
}

float4 PScolorOnly(VertexOut pin) : SV_Target
{
	float4 Color = gColor;
    return Color;
}


technique11 ColorSpecified
{
    pass P0
    {
        SetVertexShader(CompileShader(vs_5_0, VSfullscreenQuad()));
		SetGeometryShader( NULL );
        SetPixelShader(CompileShader(ps_5_0, PScolorOnly()));
    }
}

Any thoughts?

Share this post


Link to post
Share on other sites


Just a short update, after introducing the new VS.
- I understand the principle and approach
- new VS added and technique changed to use the new VS
-- two things not solved yet
 
1. the new VS needs a "uint id: SV_VERTEXID" as input, what should I pass as parameter in the technique?
(I tried '0', but that didn't work out/ compile)
2. my currect vertex output structure has a float3 for position (world pos) and has no color component.
So I've removed the . w value from the VS and the assignment of the color. Is this OK or should I make a new definition for the VS output for this specific case?

 

1. You don't pass in an argument for the id parameter, it just comes to you from the gpu like magic.

2. SV_Position is always a float4. The most basic way to do this is to leave z as 0 and w as 1. The gpu is going to divide xyz by w, and if w is 1 then it's not doing anything.

Share this post


Link to post
Share on other sites

Update: stupid, I was doing .X twice, instead of .X and .Y (in the VS), post updated.

 

Thanks for the quick response, I think I've solved problem 2.

Problem one though I didn't manage yet, thanks to your answer I now know I don't have to pass anything when calling the VS.

 

Result so far:

struct VSout
{
	float4 Pos     : SV_POSITION;
	float2 Tex     : TEXCOORD;
};


VSout VSfullscreenQuad(uint id:SV_VERTEXID)
{
	VSout output;
	
	// generate clip space position
	output.Pos.x = (float)(id / 2) * 4.0 - 1.0f;
	output.Pos.y = (float)(id % 2) * 4.0 - 1.0f;
	output.Pos.z = 0.0f;
	output.Pos.w = 1.0f;

	// texture coordinates
	output.Tex.x = (float)(id / 2) * 2.0f;
	output.Tex.y = 1.0f - (float)(id % 2) * 2.0f;
	
	// color
	//output.color = float4(1, 1, 1, 1);

	return output;
}

float4 PScolorOnly(VSout pin) : SV_Target
{
	float4 Color = gColor;
    return Color;
}


technique11 ColorSpecified
{
    pass P0
    {
        SetVertexShader(CompileShader(vs_5_0, VSfullscreenQuad()));
		SetGeometryShader( NULL );
        SetPixelShader(CompileShader(ps_5_0, PScolorOnly()));
    }
}

No errors and warnings remaining in the compilation of the PS/ VS/ technique.

 

I don't see visible result yet, but the program runs, now I'll have to dig and find what I'm doing wrong.

Edited by cozzie

Share this post


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

  • Advertisement