• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Migi0027

DX11
DX11 - Tessellation - Something is wrong

5 posts in this topic

Hi guys!

 

I recently just started implementing tessellation for my terrain system, but it isn't quite working as I expected, nothing shows up. Further down I am going to give you some code which includes the tessellation, nothing fancy, as I said, I just got started. I don't expect you to read it all, just that if you spot something you find weird/wrong, please say so as it may help me.

 

Without implementing the tessellation, the terrain renders perfectly, but when trying to implement the tessellation, nothing is shown. PS. One interesting thing is that when rendering without tessellation, I use: D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, but when tessellating, I understood that I had to use D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST, well according to my shader file.

 

Shader (Simple):

cbuffer ConstantObjectBuffer : register (b0)
{
	matrix worldMatrix;
};

cbuffer ConstantFrameBuffer : register (b1)
{
	matrix viewMatrix;
	matrix projectionMatrix;

	float3 eyepos;
	float cppad;

	float4 lightvec;
	float4 lightcol;

	float FogStart;
	float FogEnd;
	float2 __space;

	float3 FogColor;
	float shadows;

	float SpecularIntensity;
	float3 pad3;
	float4 SpecularColor;
}


//***************************************************//
//                 VERTEX SHADER                     //
//***************************************************//

struct VOut
{
    float4 position : SV_POSITION;
	float2 texcoord : TEXCOORD;
	float access : ACCESS;
	
	float3 NormalW : NORMWORLD;
	float4 depthPosition : TEXTURE0;
};

struct GlobalIn
{
	float4 position : POSITION;
	float4 normal : NORMAL;
	float2 texcoord : TEXCOORD;
};

Texture2D t_map : register(t0);
SamplerState ss;

VOut VShader(GlobalIn input)
{
    VOut output;

    input.position.w = 1.0f;
	output.texcoord = input.texcoord;

	// Calculate the position of the vertex against the world, view, and projection matrices.
    output.position = mul(input.position, worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);

    output.NormalW = mul(float4(input.normal.xyz,0), mul(worldMatrix, viewMatrix));

	// Store the position value in a second input value for depth value calculations.
	output.depthPosition.xyz = mul(float4(input.position.xyz,1), mul(worldMatrix, viewMatrix)).xyz;

	// Per Vertex lighting
	float4 norm = normalize(input.normal);
	output.access = saturate(dot(norm, lightvec));
	
    return output;
}

//***************************************************//
//                 HULL SHADER                       //
//***************************************************//

struct HOutput
{
    float edges[3] : SV_TessFactor;
    float inside : SV_InsideTessFactor;
};

#define tessellationAmount 12.0f

HOutput ColorPatchConstantFunction(InputPatch<VOut, 3> inputPatch, uint patchId : SV_PrimitiveID)
{    
    HOutput output;

    // Set the tessellation factors for the three edges of the triangle.
    output.edges[0] = 12.0f;
    output.edges[1] = 12.0f;
    output.edges[2] = 12.0f;

    // Set the tessellation factor for tessallating inside the triangle.
    output.inside = 12.0f;

    return output;
}

[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("ColorPatchConstantFunction")]

VOut HShader(InputPatch<VOut, 3> patch, uint pointId : SV_OutputControlPointID, uint patchId : SV_PrimitiveID)
{
    VOut output;

    // Set the x for this control point as the output x.
    output.position = patch[pointId].position;

    output.texcoord = patch[pointId].texcoord;
    output.access = patch[pointId].access;
    output.NormalW = patch[pointId].NormalW;
    output.depthPosition = patch[pointId].depthPosition;

    return output;
}

//***************************************************//
//                 DOMAIN SHADER                     //
//***************************************************//

[domain("tri")]

VOut DShader(HOutput input, float3 uvwCoord : SV_DomainLocation, const OutputPatch<VOut, 3> patch)
{
    float3 vertexPosition;
    VOut output;
 
    // Determine the position of the new vertex.
    vertexPosition = uvwCoord.x * patch[0].position + uvwCoord.y * patch[1].position + uvwCoord.z * patch[2].position;
    
    // Calculate the position of the new vertex against the world, view, and projection matrices.
    output.position = mul(float4(vertexPosition, 1.0f), worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);

    // Send the input color into the pixel shader.
    output.texcoord = patch[0].texcoord;
    output.access = patch[0].access;
    output.NormalW = patch[0].NormalW;
    output.depthPosition = patch[0].depthPosition;

    return output;
}

//***************************************************//
//                 PIXEL SHADER                      //
//***************************************************//

struct POut
{
	float4 Diffuse  : SV_Target0;
	float4 Depth    : SV_Target1;
	float4 Normals  : SV_Target2;
	float4 Lighting : SV_Target3;
};

POut PShader(VOut input)
{
	POut output;

	// Depth
	output.Depth = float4(input.depthPosition.xyz, 1.0f);

	// Normals
	output.Normals = float4(normalize(input.NormalW), 1);

	output.Diffuse = float4(1, 1, 1, 1);
	output.Lighting = float4(lightcol.rgb * input.access, 1.0f);

	output.Lighting = float4(1, 1, 1, 1);

	return output;
}

C++:

 

Before Rendering:

devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST);

Shader Creation:

D3DX11CompileFromFile(finals.c_str(), 0, 0, "VShader", "vs_5_0", CE_DBG, 0, 0, &VS, &vserrors, &HR);
D3DX11CompileFromFile(finals.c_str(), 0, 0, "PShader", "ps_5_0", CE_DBG, 0, 0, &PS, &pserrors, &HR);
D3DX11CompileFromFile(finals.c_str(), 0, 0, "HShader", "hs_5_0", CE_DBG, 0, 0, &HS, &hserrors, &HR);
D3DX11CompileFromFile(finals.c_str(), 0, 0, "DShader", "ds_5_0", CE_DBG, 0, 0, &DS, &dserrors, &HR);

// Error Checking

dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);
dev->CreateHullShader(HS->GetBufferPointer(), HS->GetBufferSize(), NULL, &pHS);
dev->CreateDomainShader(DS->GetBufferPointer(), DS->GetBufferSize(), NULL, &pDS);
 
D3D11_INPUT_ELEMENT_DESC ied[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
 
if (dev->CreateInputLayout(ied, 3, VS->GetBufferPointer(), VS->GetBufferSize(), &pLayout) != S_OK)
CE_WARNING("Input Layout Creation", "Input Layout creation in terrain shader has failed!");

Applying Shader:

devcon->VSSetShader(pVS, 0, 0);
devcon->HSSetShader(pHS, 0, 0);
devcon->DSSetShader(pDS, 0, 0);
devcon->PSSetShader(pPS, 0, 0);
devcon->IASetInputLayout(pLayout);

Rendering: 

// Set constant buffers

devcon->DrawIndexed(bf.IndexCount, 0, 0);

PIX:

2cqldzc.png

 

 

I hope that I have supplied you with enough information, as I haven't found the solution yet, but is still trying. happy.png

 

Thank you, as always GameDev.

Edited by Migi0027
0

Share this post


Link to post
Share on other sites

I know this problem because it happened to me when I first implemented tessellation! You can't use SV_Position to pass values between VS/HS and HS/DS. You can only use it for outputting from your domain shader. For other shader stages, you should use a non-SV semantic for passing position.

2

Share this post


Link to post
Share on other sites

So is this the correct way?:

cbuffer ConstantObjectBuffer : register (b0)
{
	matrix worldMatrix;
};

cbuffer ConstantFrameBuffer : register (b1)
{
	matrix viewMatrix;
	matrix projectionMatrix;

	float3 eyepos;
	float cppad;

	float4 lightvec;
	float4 lightcol;

	float FogStart;
	float FogEnd;
	float2 __space;

	float3 FogColor;
	float shadows;

	float SpecularIntensity;
	float3 pad3;
	float4 SpecularColor;
}


//***************************************************//
//                 VERTEX SHADER                     //
//***************************************************//

struct VOut
{
    float4 position : POSITION;
	float2 texcoord : TEXCOORD;
	float access : ACCESS;
	
	float3 NormalW : NORMWORLD;
	float4 depthPosition : TEXTURE0;
};

struct GlobalIn
{
	float4 position : POSITION;
	float4 normal : NORMAL;
	float2 texcoord : TEXCOORD;
};

Texture2D t_map : register(t0);
SamplerState ss;

VOut VShader(GlobalIn input)
{
    VOut output;

    input.position.w = 1.0f;
	output.texcoord = input.texcoord;

	// Calculate the position of the vertex against the world, view, and projection matrices.
    output.position = mul(input.position, worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);

    output.NormalW = mul(float4(input.normal.xyz,0), mul(worldMatrix, viewMatrix));

	// Store the position value in a second input value for depth value calculations.
	output.depthPosition.xyz = mul(float4(input.position.xyz,1), mul(worldMatrix, viewMatrix)).xyz;

	// Per Vertex lighting
	float4 norm = normalize(input.normal);
	output.access = saturate(dot(norm, lightvec));
	
    return output;
}

//***************************************************//
//                 HULL SHADER                       //
//***************************************************//

struct HOutput
{
    float edges[3] : SV_TessFactor;
    float inside : SV_InsideTessFactor;
};

#define tessellationAmount 12.0f

HOutput ColorPatchConstantFunction(InputPatch<VOut, 3> inputPatch, uint patchId : SV_PrimitiveID)
{    
    HOutput output;

    // Set the tessellation factors for the three edges of the triangle.
    output.edges[0] = 12.0f;
    output.edges[1] = 12.0f;
    output.edges[2] = 12.0f;

    // Set the tessellation factor for tessallating inside the triangle.
    output.inside = 12.0f;

    return output;
}

[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("ColorPatchConstantFunction")]

VOut HShader(InputPatch<VOut, 3> patch, uint pointId : SV_OutputControlPointID, uint patchId : SV_PrimitiveID)
{
    VOut output;

    // Set the x for this control point as the output x.
    output.position = patch[pointId].position;

    output.texcoord = patch[pointId].texcoord;
    output.access = patch[pointId].access;
    output.NormalW = patch[pointId].NormalW;
    output.depthPosition = patch[pointId].depthPosition;

    return output;
}

//***************************************************//
//                 DOMAIN SHADER                     //
//***************************************************//

struct DOut
{
    float4 position : SV_Position;
	float2 texcoord : TEXCOORD;
	float access : ACCESS;
	
	float3 NormalW : NORMWORLD;
	float4 depthPosition : TEXTURE0;
};

[domain("tri")]

DOut DShader(HOutput input, float3 uvwCoord : SV_DomainLocation, const OutputPatch<VOut, 3> patch)
{
    float3 vertexPosition;
    DOut output;
 
    // Determine the position of the new vertex.
    vertexPosition = uvwCoord.x * patch[0].position + uvwCoord.y * patch[1].position + uvwCoord.z * patch[2].position;
    
    // Calculate the position of the new vertex against the world, view, and projection matrices.
    output.position = mul(float4(vertexPosition, 1.0f), worldMatrix);
    output.position = mul(output.position, viewMatrix);
    output.position = mul(output.position, projectionMatrix);

    // Send the input color into the pixel shader.
    output.texcoord = patch[0].texcoord;
    output.access = patch[0].access;
    output.NormalW = patch[0].NormalW;
    output.depthPosition = patch[0].depthPosition;

    return output;
}

//***************************************************//
//                 PIXEL SHADER                      //
//***************************************************//

struct POut
{
	float4 Diffuse  : SV_Target0;
	float4 Depth    : SV_Target1;
	float4 Normals  : SV_Target2;
	float4 Lighting : SV_Target3;
};

POut PShader(VOut input)
{
	POut output;

	// Depth
	output.Depth = float4(input.depthPosition.xyz, 1.0f);

	// Normals
	output.Normals = float4(normalize(input.NormalW), 1);

	output.Diffuse = float4(1, 1, 1, 1);
	output.Lighting = float4(lightcol.rgb * input.access, 1.0f);

	output.Lighting = float4(1, 1, 1, 1);

	return output;
}

Well, that fixed one issue, now the other, still can't see anything. biggrin.png

 

But thanks MJP.

0

Share this post


Link to post
Share on other sites
You're transforming your vertices twice, once in the vertex, once in the domain shader. You rather e.g. use a pass-through vertex shader - or transform to view or world space only. Depends on what you're doing. I recommend using view space if you later going to determine the tesselation factors according to (view) distance.

Projection transform should only happen at the last stage (before the pixel shader). In particular, sub-tesselation in clip space is probably very wrong (domain shader).

You also should interpolate the other attributes (normal, texcoord, etc.) otherwise you get wrong results.

Since PIX is quite reluctant concerning the tesselation stage you can use a pass-through geometry shader to inspect the attributes more easily.
2

Share this post


Link to post
Share on other sites

Thank you both MJP and unbird for correcting me.

 

It Works!

 

And it looks like I forgot to send the matrices to the domain shader as well.

 

Best Regards

Migi0027

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • By YixunLiu
      Hi,
      I have a surface mesh and I want to use a cone to cut a hole on the surface mesh.
      Anybody know a fast method to calculate the intersected boundary of these two geometries?
       
      Thanks.
       
      YL
       
    • By hiya83
      Hi, I tried searching for this but either I failed or couldn't find anything. I know there's D11/D12 interop and there are extensions for GL/D11 (though not very efficient). I was wondering if there's any Vulkan/D11 or Vulkan/D12 interop?
      Thanks!
    • By lonewolff
      Hi Guys,
      I am just wondering if it is possible to acquire the address of the backbuffer if an API (based on DX11) only exposes the 'device' and 'context' pointers?
      Any advice would be greatly appreciated
    • By MarcusAseth
      bool InitDirect3D::Init() { if (!D3DApp::Init()) { return false; } //Additional Initialization //Disable Alt+Enter Fullscreen Toggle shortkey IDXGIFactory* factory; CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast<void**>(&factory)); factory->MakeWindowAssociation(mhWindow, DXGI_MWA_NO_WINDOW_CHANGES); factory->Release(); return true; }  
      As stated on the title and displayed on the code above, regardless of it Alt+Enter still takes effect...
      I recall something from the book during the swapChain creation, where in order to create it one has to use the same factory used to create the ID3D11Device, therefore I tested and indeed using that same factory indeed it work.
      How is that one particular factory related to my window and how come the MakeWindowAssociation won't take effect with a newly created factory?
      Also what's even the point of being able to create this Factories if they won't work,?(except from that one associated with the ID3D11Device) 
    • By ProfL
      Can anyone recommend a wrapper for Direct3D 11 that is similarly simple to use as SFML? I don't need all the image formats etc. BUT I want a simple way to open a window, allocate a texture, buffer, shader.
  • Popular Now