Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


using effect shader on RHW vertices


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Anddos   Members   -  Reputation: 520

Like
0Likes
Like

Posted 11 February 2012 - 08:20 PM

I cant seem to render the triangle that rendering as RHW ,pretransformed vertices, here is the render code

LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
struct CUSTOMVERTEXRHW {FLOAT X, Y, Z, RHW; DWORD COLOR;};
#define CUSTOMFVFRHW (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

[code]
CUSTOMVERTEXRHW vertices[] =
	{
		{ 400.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
		{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
		{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
	};
	

	// create a vertex buffer interface called v_buffer
	d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEXRHW),
							   0,
							   CUSTOMFVFRHW,
							   D3DPOOL_MANAGED,
							   &v_buffer,
							   NULL);

	VOID* pVoid;	// a void pointer

	// lock v_buffer and load the vertices into it
	v_buffer->Lock(0, 0, (void**)&pVoid, 0);
	memcpy(pVoid, vertices, sizeof(vertices));
	v_buffer->Unlock();

D3DXCreateEffectFromFile(d3ddev, "simple.fx", 0, 0, 0, 0, &g_effect, &errorlog);
     g_effect->FindNextValidTechnique(NULL, &technique);
[/code]


[code]
in rendering

	D3DXMATRIX matWorld;
	D3DXMatrixIdentity(&matWorld);
  
	p_effect->SetMatrix("Projection", &matProjection);
	p_effect->SetMatrix("View", &matView);
	p_effect->SetMatrix("World", &(matWorld));

	d3ddev->SetFVF(CUSTOMFVFRHW);
	d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEXRHW));
	d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

	p_effect->EndPass();	// end the pass
	p_effect->End();	// end the effect
[/code]

[code]
//shader .fx

float4x4 World;
float4x4 View;
float4x4 Projection;

struct VertexOut
{
	float4 Pos : POSITION;
	float4 Color : COLOR;
};

VertexOut VShader(float4 Pos : POSITION)
{
	VertexOut Vert = (VertexOut)0;
	float4x4 Transform;
	

	Transform = mul(World, View);
	Transform = mul(Transform, Projection);
	Vert.Pos = mul(Pos, Transform);
	Vert.Color = float4(1, 0, 0, 0); //returns red
	return Vert;
}

technique FirstTechnique
{
	pass FirstPass
	{
	  VertexShader = compile vs_2_0 VShader();
	}
}


what am i doing wrong?
:)

Sponsor:

#2 iedoc   Members   -  Reputation: 1060

Like
0Likes
Like

Posted 12 February 2012 - 03:55 AM

you don't have a pixel shader, and you are not passing the color component of your vertices into your shaders, so i would assume it would be being rendered black.

i just realized your setting the color in your vertex shader. but still, I think you need a pixel shader to specifically return that color you are making. the semantic "COLOR" is not a recognized semantic in the shaders, it is a custom semantic, which means that it is used to pass data between shaders, but the shaders themselves wouldn't know what to do with it.

try making a simple pixel shader like this:

float4 PShader(VertexOut input) : SV_Target

{

return input.Color;

}


in your technique and pass, do this:


SetVertexShader( CompileShader( vs_4_0, VShader() ) );

SetPixelShader( CompileShader( ps_4_0, PShader() ) );


also, do this:

struct VertexOut
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
};

This will tell the rasterizer stage that Pos is the position of the vertex (notice the "SV_" prefix, this means it is a system value. system values are understood by pipeline stages, while other semantics like "COLOR" are custom, and used to pass data between programmable shaders like the vertex, geometry, and pixel shaders for example)
Braynzar Soft - DirectX Lessons & Game Programming Resources!

#3 Anddos   Members   -  Reputation: 520

Like
0Likes
Like

Posted 12 February 2012 - 04:13 AM

should it not be ?

VertexShader = compile vs_2_0 VShader();
PixelShader = compile ps_2_0 PShader();
:)

#4 iedoc   Members   -  Reputation: 1060

Like
0Likes
Like

Posted 12 February 2012 - 04:30 AM

oh yeah, if your graphics card can't handle anything above version 2, then just use version 2. that's just the shader version, and i've only ever used version 4 and 5. just use whatever works i guess
Braynzar Soft - DirectX Lessons & Game Programming Resources!

#5 Anddos   Members   -  Reputation: 520

Like
0Likes
Like

Posted 12 February 2012 - 04:58 AM

this dosent seem to be working with the SV stuff, not sure what todo now
:)

#6 iedoc   Members   -  Reputation: 1060

Like
0Likes
Like

Posted 12 February 2012 - 05:50 AM

well, what exactly is your problem. is there an error? or is it compiling but your just not seeing what you expect to see? if your not seeing what you want, what are you seeing?
Braynzar Soft - DirectX Lessons & Game Programming Resources!

#7 Hodgman   Moderators   -  Reputation: 31926

Like
0Likes
Like

Posted 12 February 2012 - 05:55 AM

What are the values of your view/projection matrices?

if your graphics card can't handle anything above version 2, then just use version 2. that's just the shader version, and i've only ever used version 4 and 5. just use whatever works i guess

this dosent seem to be working with the SV stuff, not sure what todo now

D3D9 only supports up to version 3. "The SV stuff" doesn't exist in version 3 (or has different names).
On shader model 2, it is valid to have an effect that only has a vertex shader with no pixel shader - the fixed function shading/texture-combiner functionality will be used.

#8 Anddos   Members   -  Reputation: 520

Like
0Likes
Like

Posted 12 February 2012 - 06:09 AM

here is my code

if(g_effect)
    {
        g_effect->SetMatrix("Projection", &matProjection);
   	 g_effect->SetMatrix("View", &matView);
	    g_effect->SetMatrix("World", &(matFinale));
        g_effect->Begin(NULL, NULL);    // begin using the effect
        g_effect->BeginPass(0);    // begin the pass
        
        d3ddev->SetFVF(CUSTOMFVFRHW);
        d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEXRHW));
        d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
        
        g_effect->EndPass();    // end the pass
	    g_effect->End();    // end the effect
    }
    else
    {
        //d3ddev->SetFVF(CUSTOMFVF);
        //d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
        //d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
    }

shader.fx
float4x4 World;
float4x4 View;
float4x4 Projection;
float BoundingBoxColor; //float passed by param...
bool setmode;

struct VertexOut
{
    float4 Pos : POSITION;
    float4 Color : COLOR;
};

VertexOut VShader(float4 Pos : POSITION)
{
    VertexOut Vert = (VertexOut)0;
    float4x4 Transform;
    

    Transform = mul(World, View);
    Transform = mul(Transform, Projection);
    Vert.Pos = mul(Pos, Transform);
    Vert.Color = float4(1, 0, 0, 0);
    return Vert;
}

float4 PShader(VertexOut input) : COLOR
{
    return input.Color;
}

technique FirstTechnique
{
    pass FirstPass
    {
	    //Lighting = FALSE;
	    //ZEnable = TRUE;
	    //FillMode = WireFrame;   
	    //FillMode = Solid;
	    
	    VertexShader = compile vs_2_0 VShader();
	    PixelShader = compile ps_2_0 PShader();

    }
}

:)

#9 Anddos   Members   -  Reputation: 520

Like
0Likes
Like

Posted 12 February 2012 - 06:15 AM

its just rendering normal

Posted Image
:)

#10 mhagain   Crossbones+   -  Reputation: 8282

Like
0Likes
Like

Posted 12 February 2012 - 07:22 AM

It's been a long time since I've used FVF codes, but I'm reasonably certain that using D3DFVF_XYZRHW will bypass the vertex shader entirely (D3DFVF_XYZRHW maps to D3DUSAGE_POSITIONT which specifies that vertex processing is skipped). In particular it makes no sense to be applying transforms to your position as the purpose of XYZRHW is to output untransformed vertex positions. So you should switch to D3DFVF_XYZ and seriously consider switching to vertex declarations too (there's a handy D3DXDeclaratorFromFVF which will help in the initial transition).

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#11 Evil Steve   Members   -  Reputation: 1987

Like
0Likes
Like

Posted 14 February 2012 - 11:25 AM

What mhagain said. D3DFMV_XYZRHW means "Here is a vertex is screen space, don't run the vertex shader". And I'd strongly second getting away from FVF codes - Declarations are much easier to map with vertex shaders, and FVF codes don't even exist in DX10+.

Steve Macpherson
Systems Programmer

Rockstar North





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS