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!


neeker

Member Since 11 Jul 2013
Offline Last Active Mar 26 2015 09:48 AM

#5100344 HLSL 2.0 vs 3.0

Posted by neeker on 10 October 2013 - 04:23 PM

It was fog getting enabled.  The weird part was that line of code was buried way down in my camera set up code and I have no idea how it got there because I do my fog in shaders.  It must have been part of a bad copy-paste at some point.




#5084459 DrawIndexedPrimitive and texcoords

Posted by neeker on 09 August 2013 - 02:01 PM

The vertex decl is:

   D3DVERTEXELEMENT9 decl[MAX_VERTEXDECL];
   size_t uDeclCount = 1;

   // Position declaration
   decl[0].Stream = 0;
   decl[0].Offset = 0;
   decl[0].Type = D3DDECLTYPE_FLOAT3;
   decl[0].Method = D3DDECLMETHOD_DEFAULT;
   decl[0].Usage = D3DDECLUSAGE_POSITION;
   decl[0].UsageIndex = 0;

   // Normal declaration
   if ((FVF & D3DFVF_NORMAL) != 0) {

      decl[uDeclCount].Stream = 0;
      decl[uDeclCount].Offset = sizeof(float) * 3;
      decl[uDeclCount].Type = D3DDECLTYPE_FLOAT3;
      decl[uDeclCount].Method = D3DDECLMETHOD_DEFAULT;
      decl[uDeclCount].Usage = D3DDECLUSAGE_NORMAL;
      decl[uDeclCount].UsageIndex = 0;
      uDeclCount++;
   }
   
   // Texture declaration
   if ((FVF & D3DFVF_TEX1) != 0) {
      decl[uDeclCount].Stream = 0;
      decl[uDeclCount].Offset = sizeof(float) * 3 * uDeclCount;
      decl[uDeclCount].Type = D3DDECLTYPE_FLOAT2;
      decl[uDeclCount].Method = D3DDECLMETHOD_DEFAULT;
      decl[uDeclCount].Usage = D3DDECLUSAGE_TEXCOORD;
      decl[uDeclCount].UsageIndex = 0;
      uDeclCount++;
   }

   // End of declarations
   decl[uDeclCount].Stream = 0xFF;
   decl[uDeclCount].Offset = 0;
   decl[uDeclCount].Type = D3DDECLTYPE_UNUSED;
   decl[uDeclCount].Method = 0;
   decl[uDeclCount].Usage = 0;
   decl[uDeclCount].UsageIndex = 0;

The values for the vertex buffer are procedurally generated, so posting those exactly would just be noisy.  But, you can imagine a cuboid:


          v4    v5
           +---+
          /|  /|
         / | / |
        /  |/  |
       /   /   |
      /   /|   |
  v2 +---+v3   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | |   |
     |   | +---+v7
     |   |/v6 /
     |   |   /
     |  /|  /
     | / | /
     |/  |/
     +---+
    v0   v1

 

With indices: 

4, 2, 0 
0, 6, 4
1, 3, 7
5, 7, 3
1, 2, 0
1, 3, 2
5, 6, 4
5, 7, 6
3, 2, 4
3, 4, 5
 

The shaders are extremely simple:

struct VS_INPUT {
    float4 position : POSITION;
    float3 normal : NORMAL;
    float2 Texture : TEXCOORD0;
};

struct VS_OUTPUT {
	float4 position : POSITION;
	float2 Texture : TEXCOORD0;
	float3 normal : TEXCOORD1;
	float4 color : COLOR;
};

float4x4 matWVP;
float4x4 matWorld;
bool bIsSelected;

VS_OUTPUT vs_main(in VS_INPUT input)
{
	VS_OUTPUT output;
	
	output.position = mul(float4(input.position.xyz, 1.0f), matWVP);
	output.Texture = input.Texture;
	output.normal = normalize(mul(input.normal, matWorld));
	output.color = float4(1.0f, 1.0f, 1.0f, 1.0f);
	
	return output;
}


struct PS_INPUT {
	float4 position : VPOS;
	float2 Texture : TEXCOORD0;
	float3 normal : TEXCOORD1;
	float4 color : COLOR0;
};

struct PS_OUTPUT {
	float4 color : COLOR0;
};

sampler2D Tex0;

PS_OUTPUT ps_main(in PS_INPUT input)
{
	PS_OUTPUT output;

	output.color = tex2D(Tex0, input.Texture);

	return output;
}



PARTNERS