Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


PavelB

Member Since 15 Apr 2012
Offline Last Active Mar 16 2014 01:05 PM

Posts I've Made

In Topic: Create Vertices within the HLSL shader

13 May 2012 - 02:37 PM

I don't know. Something wrong with my understanding of what you are saying. Below I show the logic I am using and it works for the triangle, but it doesn't work for square.
As you see below I commented a lot of code and it still consistant. It works, but show only one of the triangles of the square. depends on which one of them are 0,1,2. When I replace the order it shows one triangle or another.

ID3DBlob* pVSBlob = NULL;
hr = CompileShaderFromFile( L"Tutorial02.fx", "vshader", "vs_4_0", &pVSBlob );
if( FAILED( hr ) )
{
  MessageBox( NULL,
	 L"The FX file cannot be compiled.  Please run this executable from the directory that contains the FX file.", L"Error", MB_OK );
  return hr;
}
// Create the vertex shader
hr = g_pd3dDevice->CreateVertexShader( pVSBlob->GetBufferPointer(), pVSBlob->GetBufferSize(), NULL, &g_pVertexShader );
if( FAILED( hr ) )
{
  pVSBlob->Release();
  return hr;
}
//// Define the input layout
//D3D11_INPUT_ELEMENT_DESC layout[] =
//{
// { "SV_VertexId", 0, DXGI_FORMAT_R32G32B32_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
//};
//UINT numElements = ARRAYSIZE( layout );
//// Create the input layout
//hr = g_pd3dDevice->CreateInputLayout( layout, numElements, pVSBlob->GetBufferPointer(),
//		   pVSBlob->GetBufferSize(), &g_pVertexLayout );
//pVSBlob->Release();
//if( FAILED( hr ) )
// return hr;
// Set the input layout
//g_pImmediateContext->IASetInputLayout( NULL );
// Compile the pixel shader
ID3DBlob* pPSBlob = NULL;
hr = CompileShaderFromFile( L"Tutorial02.fx", "PS", "ps_4_0", &pPSBlob );
if( FAILED( hr ) )
{
  MessageBox( NULL,
	 L"The FX file cannot be compiled.  Please run this executable from the directory that contains the FX file.", L"Error", MB_OK );
  return hr;
}
// Create the pixel shader
hr = g_pd3dDevice->CreatePixelShader( pPSBlob->GetBufferPointer(), pPSBlob->GetBufferSize(), NULL, &g_pPixelShader );
pPSBlob->Release();
if( FAILED( hr ) )
  return hr;
//// Create vertex buffer
//SimpleVertex vertices[] =
//{
// XMFLOAT3( 0.0f, 0.5f, 0.5f ),
// XMFLOAT3( 0.5f, -0.5f, 0.5f ),
// XMFLOAT3( -0.5f, -0.5f, 0.5f ),
//};
//D3D11_BUFFER_DESC bd;
//ZeroMemory( &bd, sizeof(bd) );
//bd.Usage = D3D11_USAGE_DEFAULT;
//bd.ByteWidth = sizeof( SimpleVertex ) * 3;
//bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
//bd.CPUAccessFlags = 0;
//D3D11_SUBRESOURCE_DATA InitData;
//ZeroMemory( &InitData, sizeof(InitData) );
//InitData.pSysMem = vertices;
//hr = g_pd3dDevice->CreateBuffer( &bd, &InitData, &g_pVertexBuffer );
//if( FAILED( hr ) )
// return hr;
//// Set vertex buffer
//UINT stride = sizeof( SimpleVertex );
//UINT offset = 0;
//g_pImmediateContext->IASetVertexBuffers( 0, 1, &g_pVertexBuffer, &stride, &offset );
// Set primitive topology
g_pImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

//--------------------------------------------------------------------------------------
// File: Tutorial02.fx
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
float4 VS( float4 Pos : POSITION ) : SV_POSITION
{
return Pos;
}

//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS( float4 Pos : SV_POSITION ) : SV_Target
{
return float4( 1.0f, 1.0f, 0.0f, 1.0f );    // Yellow, with Alpha = 1
}
struct VS_OUT {
  float4 pos : SV_Position;
  // insert other vs output fields here as needed
};
// vertex shader that draws a triangle without vbuffers
VS_OUT vshader(uint idx : SV_VertexId)
{
VS_OUT ret = (VS_OUT)0;
switch (idx)
{
  case 3:
    ret.pos = float4(-0.1,-0.1,1,1);
    break;
  case 4:
   ret.pos = float4(0.1,0.1,1,1);	
    break;
  case 5:	
    ret.pos = float4(0.1,-0.1,1,1);	
   break;
  case 0:
    ret.pos = float4(-0.1,-0.1,1,1);
    break;
  case 1:
   ret.pos = float4(-0.1,0.1,1,1);	
    break;
  case 2:	
    ret.pos = float4(0.1,0.1,1,1);	
   break;
}
return ret;
}

In Topic: Create Vertices within the HLSL shader

13 May 2012 - 08:35 AM

But how does it know how many vertices in model - 3 or 300000.
is it Draw(300000, 0) tell about it?

In Topic: Create Vertices within the HLSL shader

13 May 2012 - 08:27 AM

This is what I try to understand, how do I give the indices to the shader. In regulat way it works this way:
Initialize Buffer:
......................... Code
	// Load the vertex array with data.
	vertices[0].position = ...  // Bottom left.

	vertices[1].position = ...  // Bottom Right
	vertices[2].position = ...  // Top Right		   
    vertices[3].position = ...  // Top Left
		// Load the index array with data.
	 indices[0] = 0; // Bottom left.		  
	 indices[1] = 1; // Bottom Right.		
     indices[2] = 2; // Top right.		
     indices[3] = 0;  // Bottom left.
	 indices[4] = 2;  // Top Right.
	 indices[5] = 3;  // Top Left.

.........   Code
Render Buffer:
[size="2"]deviceContext->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);[/size]
[size="2"]deviceContext->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0); [/size]
[size="2"]deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); [/size]

Now, what am I doing?
From the samples that I found, at least the simpliest one I should do something like this:
m_pD3D11Device->IASetInputLayout( NULL );
m_pD3D11Device->IASetPrimitiveTopology( D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

ID3DX11EffectTechnique * pTech = NULL;
pTech = m_pEffect->GetTechniqueByIndex(0);
pTech->GetPassByIndex(iPass)->Apply(0);
m_pD3D11Device->Draw( 3, 0 );
Where do I set the order of the indices for the triangles? How do I know in shader about it?

In Topic: Create Vertices within the HLSL shader

13 May 2012 - 07:45 AM

Thanks.

It is what I found on SDK, too. Again It has permanent coordinates.

However, I cannot figure out, how I can do complex shader, which includes 2 triangles, as in Square or 400 triangles as for Circle, by sending in only center of those shapes. For instant, here is what I hope to achieve.
struct VS_OUT
{
	 float4 pos: SV_Position;
};
struct VS_IN
{
   float4 origin;
   float4 radius;
   uint idx : SV_VertexId;
};
VS_OUT vsshader(VS_IN in)
{
   VS_OUT ret = (VS_OUT)0;
   float4 inRightTop;
   ...  // Calculation of the Right Top corner
   float4 inLeftTop;
   ....
   float4 inRightBottom;
   ....
   float4 inLeftBottom;
   switch (idx) {
   case 0:
	  ret.pos = inLeftBottom; break;
   case 1:
	  ret.pos = inRightBottom; break;
   case 2:
	  ret.pos = inRightTop; break;
   case 3:
	  ret.pos = inLeftBottom; break;
   case 4:
	  ret.pos = inRightTop; break;
   case 5:
	  ret.pos = inLeftTop; break;
   }
}

In Topic: Create Vertices within the HLSL shader

13 May 2012 - 06:35 AM

I am new at shaders. I can find a lot of examples that would help me with the traditional ways of computing and very little with what I describe above. Could you give me some tutorials to read about this technique or even small working small sample of the example above and I will try using that for what I really want to try (see below)

In ideal variant for the square I'd like to do something like this:
I will send 3 parameters:
- Polar System Coordinate vector from "World Space" origin to the origin of the square's Object Polar Coordinate System;
- Quadrion of the orientation for the origin "unit" vector of the square's Object Polar Coordinate System;
- Polar System Coordinate vector to the point of one of the corners of the square within Object Polar Coordinate System.

It is it and then shader create the vertice buffer by itself.

P.S. As bonus, I'd like to keep the third vector in GPU as long as possible during the time my application is running. Only 2 first parameters will be changed between frames to do some animation.

PARTNERS