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!


Nicholas1991

Member Since 08 Jun 2010
Offline Last Active Apr 30 2013 01:38 PM

Topics I've Started

Vertextypes with Array of unknown size during compiletime for VertexBuffer

06 April 2013 - 05:15 PM

Hi Folks,

 

This is some kind of beginner question, but I couldn't find the answer anywhere.

I have successfully used the following Vertex-Type until now for simple textured geometry. An array of these vertices is then passed via IASetVertexBuffers(...):

struct
VERTEXPOSITIONNORMALTEXTURED
{

	D3DXVECTOR3 position;
	D3DXVECTOR3 normal; 
	D3DXVECTOR2 texcoord;


	static D3D11_INPUT_ELEMENT_DESC* GetVertexLayout()
	{
		static D3D11_INPUT_ELEMENT_DESC layout[] =
		{
			{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 
				0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 
				0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
			{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 
				0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		};

		return layout; 
	}

	static UINT GetNumElements(){ return 3; }
};
 

Now I would like to use more than one map on certain objects. I could of course now create lots of VertexTypes with one to ten UV-Coordinates for example to deal with objects that have one to ten UV-Coordinates. However that is not really an elegant solution. Of course I don't want to use an array of fixed size ten because then most of the time I store almost ten times as much data for each vertex than is necessary (most objects ingame only have a texture and no other maps, and most objects that use more than one map will probably not use all ten map slots).

But if I want to create an array with unkown size during compiletime I would use pointers.

 

 

 

...
D3DXVECTOR3 position;
D3DXVECTOR3 normal;
D3DXVECTOR2* texcoords;
UINT numTexCoords;
...





 

 

The layout[] would also be created during runtime. But what about the pointer? How do I Access this array in my HLSL VertexShader Method?

 

 

Thanks in advance

Nicholas


Specular Highlight - fx-File - Vertexshader only

06 September 2012 - 12:36 PM

Hi guys,

I had to stop working on my Game for quiete some time but now I am continuing with Susanne Wigard's Book on how to programm a basic game engine.

Now I copied the fx-File from the CD that came with the book but for some reason my specular-light-dot is not behaving as planned (see pictures below).
The fx-File:
//--------------------------------------------------------------------------------------
// Datei: Glanzlicht.fx
//
// Glanzlicht
//
// Susanne Wigard 2009
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Global variables
//--------------------------------------------------------------------------------------
cbuffer cb0							 //Standardshader
{
float4 g_MaterialAmbientColor;	  // Material's ambient color
float4 g_MaterialDiffuseColor;	  // Material's diffuse color
float3 g_vLightDir;				  // Light's direction in world space, normalized
float4 g_LightDiffuse;			  // Light's diffuse color
float	g_fTime;				   // App's time in seconds
float4x4 g_mWorld;				  // World matrix for object
float4x4 g_mWorldViewProjection;	// World * View * Projection matrix
}
cbuffer cb1							 //Für Glanzlicht
{
	float4 g_LightSpecular = float4(1, 1, 1, 1);
	float g_SpecularPower;
  
	float4x4 g_mView;
	float4x4 g_mProj;
}
//--------------------------------------------------------------------------------------
// Vertex shader output structure
//--------------------------------------------------------------------------------------
struct VS_OUTPUT
{
	float4 Position   : SV_Position;   // vertex position
	float4 Diffuse	: COLOR0;		// vertex diffuse color (note that COLOR0 is clamped from 0..1)
	float2 TextureUV  : TEXCOORD0;	 // vertex texture coords
};
//--------------------------------------------------------------------------------------
// Vertexshader mit Glanzlicht
//--------------------------------------------------------------------------------------
VS_OUTPUT RenderMitGlanzlichtVS( float4 vPos	   : POSITION,
								 float3 vNormal	: NORMAL)
{
	VS_OUTPUT Output;
	float4 worldPos  = mul(vPos,	  g_mWorld);
	float4 cameraPos = mul(worldPos,  g_mView); //Position im Koordinatensystem der Kamera
	Output.Position  = mul(cameraPos, g_mProj);
	float3 vNormalWorldSpace;
	vNormalWorldSpace = normalize(mul(vNormal, (float3x3)g_mWorld)); // normal (world space)
	float3 halfAngle = normalize(normalize(-cameraPos) + g_vLightDir);
	float NDotH = max(0, dot(halfAngle, vNormalWorldSpace));
	Output.Diffuse.rgb = g_MaterialDiffuseColor * g_LightDiffuse *
						 max(0,dot(vNormalWorldSpace, g_vLightDir))
						 + g_LightSpecular * pow(NDotH, g_SpecularPower)
						 + g_MaterialAmbientColor;
	Output.Diffuse.a = 1.0f;
  
	return Output;  
}
//--------------------------------------------------------------------------------------
// Standard-Pixelshader ohne Textur
//--------------------------------------------------------------------------------------
float4 SimplePS( VS_OUTPUT In ) : SV_Target
{
	return In.Diffuse;
}
//--------------------------------------------------------------------------------------
// Rendern mit Glanzlicht ohne Textur
//--------------------------------------------------------------------------------------
fxgroup Glanzlicht
{
technique11 RenderMitGlanzlicht
{
  pass P0
  {	  
   SetVertexShader( CompileShader(vs_4_0, RenderMitGlanzlichtVS()));
   SetGeometryShader( NULL );
   SetPixelShader( CompileShader(ps_4_0, SimplePS()));
  }
}
}


What happens is.... strange. The diffuse and the ambient light work as intended. The specular lighting however screws up.
Lets say the Sphere is always centered around (0,0,0) and has a radius of 2.0f.
The Camera starts at (0.0f, 0.0f, 5.0f) and is directed towards (0,0,0).
The light source ist at (0,0,10.0f) and it's direction vector is (0,0,1.0f).

Then I see the following:
(pictures attached with 1_ prefix)
Attached File  1_beginning.png   49.47KB   22 downloads
Attached File  1_looking_up_slightly.PNG   45.79KB   18 downloads
Attached File  1_moving_to_the_right_looking_down_slightly.png   25.32KB   19 downloads

However, if I change the light source to (10.0f, 0, 0) pointing at (1.0f,0,0) I see the following:
(pictures attached with 2_ prefix)
Attached File  2_beginning.png   38.37KB   20 downloads
Attached File  2_moving_to_the_left.png   35.8KB   21 downloads
Attached File  2_moving_to_the_left_and_up.png   40.93KB   21 downloads

As you can see in the second setup the white spot is not moving at all.

I mean the view matrix is used for the specular highlight but also for the calculation of the output position, so I assume it is correctly set. Maybe something went wrong during vector conversions (3 and 4 entries)? Or is it something more obvious? Posted Image

Yours,
Nicholas


P.S.: I've only started working with different rendering techniques. Up until now I always used a default fx-file so please keep it simple ;).

templates and default values by default?

19 July 2010 - 07:08 AM

Hello everyone,

with the help of a book and online tutorials I try to get into game programming. However, I'm still new to C++ so while reading and programming a little with C++ I had some trouble with templates.

That's what I find in the book I'm reading:


template <class blub, bool bSomething, typename someType>
class MyClass {
public:
MyClass();
~MyClass();
};

template <class blub, bool bSomething, typename someType>
MyClass::MyClass()
{
}


And then later:


class NewClass : public MyClass<SOMECLASS>
{
//...
};


Now the compiler obviously complains about missing template arguments, so I just fill in some values and everything works fine. However, it bothers me that throughout the entire book the author leaves out template arguments without defining default ones. I'm a bit worried that my app might show unexpected behaviour because of that. Thus my question wheter or not there is a way that the code as printed in the book works.

Trouble with Templates and error C2039

18 July 2010 - 01:01 AM

Hello everyone,

I'm having some trouble with my application. Using the book "Spieleprogrammierung mit DirectX 11 und C++" I try to get startet with game programming. However, I must say that I have already found some mistakes in the book (Is it possible that Visual Studio Express 2008 (recommended by the author) and 2010 differ so much? I don't think so). Until now I could solve them myself with a bit of Internet research. But since I'm new to C++ (used Java before) this time I can't make out how to cange my application to make it run.


"error C2039: '{ctor}': Ist kein Element von" (Is no element of)
This is the part the compiler complains about:
The code is in DynamicEntity.h, the definition of the constructor is in OctreeNode.h

template<class VertexType, bool bIndexed, typename IndexType>
OctreeNode::OctreeNode(const DynamicEntity<VertexType, bIndexed, IndexType> *pEntity) :
m_bbMin(pEntity->m_bbMin), m_bbMax(pEntity->m_bbMax)
{
for (UINT64 idx = 0; idx < pEntity->m_nIndices; idx += 3)
{
D3DXVECTOR3 p[3];
for(int i = 0; i < 3; i++)
{
p[i] = ((VertexType*)pEntity->m_pVertices +
pEntity->m_pIndices[idx + i])->position;
m_Points.Add(p[i]);
}
}
CreateChildNodes();
}

This might also be important:
In DynamicEntity.h

template<class VertexType, bool bIndexed, typename IndexType>
class DynamicEntity : public Visual {

friend class OctreeNode;
//....

And in OctreeNode.h

template<class VertexType, bool bIndexed=true, typename IndexType = UINT16>
class DynamicEntity;

class OctreeNode {
//...

Since the project is already pretty extensive I don't want to post all of the code here. But if you need further information I will post some more.

BTW: Why is there no preview Button? I would like to see how my post looks like before actually posting it.

PARTNERS