• Advertisement
Sign in to follow this  

using effect shader on RHW vertices

This topic is 2169 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)


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);




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



//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?

Share this post


Link to post
Share on other sites
Advertisement
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:

[color=#000088]struct[color=#000000] [color=#660066]VertexOut
[color=#666600]{
[color=#000000] float4 [color=#660066]Pos[color=#000000] [color=#666600]:[color=#000000] SV_POSITION[color=#666600];
[color=#000000] float4 [color=#660066]Color[color=#000000] [color=#666600]:[color=#000000] COLOR[color=#666600];
[color=#666600]};

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)

Share this post


Link to post
Share on other sites
should it not be ?

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
this dosent seem to be working with the SV stuff, not sure what todo now

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Hidden
Never mind got it working :), it didnt need that SV_ stuff

Share this post


Link to post
Hidden
sorry for that, i haven't used d3d9 for a LONG time, and when i did, i never used hlsl, so i was just assuming it could handle the latest version of hlsl

Share this post


Link to post
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();

}
}

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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+.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement