• 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 Sprite Like Technique - With a quad

9 posts in this topic

Hi guys,

 

right now I'm having a small quad with a texture on it, and I wan't it to face my camera. The reason for that is because I wan't to mess around with Post Processing, It looks for me right now:

 

if ssao

  Render Normals to TEXTUREN

  Render Position to TEXTUREP

Render Diffuse     to TEXTURED

 

Render Plane with TEXTUREN | TEXTUREP | TEXTURED - To do some post processing

Show it!

 

Now please correct me if this is a wrong way!

 

But how is it possible to rotate and translate a quad to face the player/camera, looking like it's a real 3d scene (with some post processing) ?

 

Thank You

0

Share this post


Link to post
Share on other sites

But how is it possible to rotate and translate a quad to face the player/camera, looking like it's a real 3d scene (with some post processing) ?

There are a number of ways to do a full screen quad.  Typically you just send four vertices with already transformed content (i.e. w=1 already) and their positions are in the clip space corners.  They would be something like this:

 

(-1,1,0,1) for upper left

(1,1,0,1) for upper right

(-1,-1,0,1) for lower left

(1,-1,0,1) for lower right

 

Since these are in clip space, you are guaranteed to cover the entire viewport regardless of the actual size of it.

0

Share this post


Link to post
Share on other sites

But how in terms of HLSL would this be possible?

 

So would i specify those 4 points and directly map them into HLSL, without any use of any Matrices? Sorry, I'm not very familiar with this topic of view space conversions...

0

Share this post


Link to post
Share on other sites

But how in terms of HLSL would this be possible?

 

So would i specify those 4 points and directly map them into HLSL, without any use of any Matrices? Sorry, I'm not very familiar with this topic of view space conversions...

Yup - that's exactly right.  The vertices are already ready to go to the rasterizer, so you just pass them through the vertex shader.  Just make sure your w-values are equal to 1, and it should work fairly easily.  To test it out, you can also try modifying the values to cover half the screen, a quarter of the screen, etc...

0

Share this post


Link to post
Share on other sites

Sorry to take your time, I do understand the concept, but I'm doing it wrong somehow.

 

Post Process Shader file for now: (Where shader stuff and quad is created)

 

#include "stdafx.h"
#include "PostProcess.h"

#include <d3dcompiler.h>
#include <DxErr.h>

#define CE_WARNING(title, message) MessageBoxA(NULL, message, title, 0) 

BOOL PostProcessClass::Create( ID3D11Device *&dev, ID3D11DeviceContext *&devcon )
{
	string finals = string(
		"C:\\Users\\Utilizador\\Documents\\Visual Studio 2012\\Projects\\Cube3D\\Product\\Bin32\\") + string("PostProcessShader.hlsl").c_str();

	ID3D10Blob *vserrors;
	ID3D10Blob *pserrors;
	HRESULT HR;

	D3DX11CompileFromFile(finals.c_str(), 0, 0, "VShader", "vs_5_0", D3DCOMPILE_DEBUG, 0, 0, &VS, &vserrors, &HR);
	D3DX11CompileFromFile(finals.c_str(), 0, 0, "PShader", "ps_5_0", D3DCOMPILE_DEBUG, 0, 0, &PS, &pserrors, &HR);
	
	// create the shader objects
	if (!VS)
	{
		DXTRACE_ERR(TEXT(DXGetErrorDescription(HR)),HR);

		MessageBoxA(NULL, "The Post Process vertex shader creation has failed, program will now exit!", "ERROR", 0);
		exit(0);
	}
	if (!PS)
	{
		DXTRACE_ERR(TEXT(DXGetErrorDescription(HR)),HR);

		MessageBoxA(NULL, "The Post Process pixel shader creation has failed, program will now exit!", "ERROR", 0);
		exit(0);
	}
	
	dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
	dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);

	D3D11_INPUT_ELEMENT_DESC ied[] =
	{
		{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0}
	};
	
	if (dev->CreateInputLayout(ied, 1, VS->GetBufferPointer(), VS->GetBufferSize(), &pLayout) != S_OK)
		CE_WARNING("Input Layout Creation", "Input Layout creation in Post Process has failed!");

	// create the vertex buffer
	D3D11_BUFFER_DESC bd;
	ZeroMemory(&bd, sizeof(bd));

	Vertices[0] = D3DXVECTOR3(-1, 0, 1);
	Vertices[1] = D3DXVECTOR3(1, 0, 1);
	Vertices[2] = D3DXVECTOR3(-1, 0, -1);
	Vertices[3] = D3DXVECTOR3(1, 0, 1);

	Indices[0] = 3;
	Indices[1] = 1;
	Indices[2] = 2;
	Indices[3] = 2;
	Indices[4] = 1;
	Indices[5] = 0;

	bd.Usage = D3D11_USAGE_DYNAMIC;
	bd.ByteWidth = sizeof(D3DXVECTOR3) * 4;
	bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
	bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	
	dev->CreateBuffer(&bd, NULL, &vBFF);

	D3D11_MAPPED_SUBRESOURCE ms;
	// copy the vertices into the buffer
	devcon->Map(vBFF, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms);    // map the buffer
	memcpy(ms.pData, Vertices, sizeof(Vertices));                 // copy the data
	devcon->Unmap(vBFF, NULL);

	//**INDICES**//

	bd.Usage = D3D11_USAGE_DYNAMIC;
	bd.ByteWidth = sizeof(DWORD) * 6;
	bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
	bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
	
	dev->CreateBuffer(&bd, NULL, &iBFF);

	D3D11_MAPPED_SUBRESOURCE msI;
	// copy the vertices into the buffer
	devcon->Map(iBFF, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &msI);    // map the buffer
	memcpy(msI.pData, Indices, sizeof(Indices));                 // copy the data
	devcon->Unmap(iBFF, NULL);
}

void PostProcessClass::ApplyShader(ID3D11Device *&dev, ID3D11DeviceContext *&devcon)
{
	// set the shader objects
	devcon->VSSetShader(pVS, 0, 0);
	devcon->PSSetShader(pPS, 0, 0);
	devcon->IASetInputLayout(pLayout);
}

void PostProcessClass::Render(ID3D11DeviceContext *&devcon, ID3D11Device *&dev)
{
	ApplyShader(dev, devcon);

	UINT stride = sizeof(D3DXVECTOR3);
	UINT offset = 0;

	devcon->IASetVertexBuffers(0, 1, &vBFF, &stride, &offset);
	devcon->IASetIndexBuffer(iBFF, DXGI_FORMAT_R32_UINT, 0);

	devcon->DrawIndexed(6, 0, 0);
}

 

Now the output is a black screen, and heres the reason from debugging:

 

9sw294.png

 

When you look at the vertex shader, the result is a straight line, which isn't exactly what I wanted happy.png

 

Now the question is why?

 

Ohh, almost forgot, my shader (it's simple for now for debugging):

 

struct VOut
{
    float4 position : SV_POSITION;
};

VOut VShader(float3 position : POSITION)
{
    VOut output;

    output.position = float4(position, 1.0f);
	output.position.w = 1.0f;
	
    return output;
}

float4 PShader(VOut input) : SV_TARGET
{
	return float4(1, 0, 0, 1);
}
Edited by Migi0027
0

Share this post


Link to post
Share on other sites

Wait, so what should I do, I'm probably not understanding this then... What's wrong with my code?

Edited by 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 lonewolff
      Hi Guys,
      I am revisiting an old DX11 framework I was creating a while back and am scratching my head with a small issue.
      I am trying to set the pixel shader resources and am getting the following error on every loop.
      As you can see in the below code, I am clearing out the shader resources as per the documentation. (Even going overboard and doing it both sides of the main PSSet call). But I just can't get rid of the error. Which results in the render target not being drawn.
      ID3D11ShaderResourceView* srv = { 0 }; d3dContext->PSSetShaderResources(0, 1, &srv); for (std::vector<RenderTarget>::iterator it = rtVector.begin(); it != rtVector.end(); ++it) { if (it->szName == name) { //std::cout << it->srv <<"\r\n"; d3dContext->PSSetShaderResources(0, 1, &it->srv); break; } } d3dContext->PSSetShaderResources(0, 1, &srv);  
      I am storing the RT's in a vector and setting them by name. I have tested the it->srv and am retrieving a valid pointer.
      At this stage I am out of ideas.
      Any help would be greatly appreciated
       
    • By bowerbirdcn
      hi, guys, how to understand the math used in CDXUTDirectionWidget ::UpdateLightDir 
      the  following code snippet is taken from MS DXTU source code
       
        D3DXMATRIX mInvView;
          D3DXMatrixInverse( &mInvView, NULL, &m_mView );
          mInvView._41 = mInvView._42 = mInvView._43 = 0;
          D3DXMATRIX mLastRotInv;
          D3DXMatrixInverse( &mLastRotInv, NULL, &m_mRotSnapshot );
          D3DXMATRIX mRot = *m_ArcBall.GetRotationMatrix();
          m_mRotSnapshot = mRot;
          // Accumulate the delta of the arcball's rotation in view space.
          // Note that per-frame delta rotations could be problematic over long periods of time.
          m_mRot *= m_mView * mLastRotInv * mRot * mInvView;
          // Since we're accumulating delta rotations, we need to orthonormalize 
          // the matrix to prevent eventual matrix skew
          D3DXVECTOR3* pXBasis = ( D3DXVECTOR3* )&m_mRot._11;
          D3DXVECTOR3* pYBasis = ( D3DXVECTOR3* )&m_mRot._21;
          D3DXVECTOR3* pZBasis = ( D3DXVECTOR3* )&m_mRot._31;
          D3DXVec3Normalize( pXBasis, pXBasis );
          D3DXVec3Cross( pYBasis, pZBasis, pXBasis );
          D3DXVec3Normalize( pYBasis, pYBasis );
          D3DXVec3Cross( pZBasis, pXBasis, pYBasis );
       
       
      https://github.com/Microsoft/DXUT/blob/master/Optional/DXUTcamera.cpp
    • 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
  • Popular Now