• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Anddos

using effect shader on RHW vertices

10 posts in this topic

I cant seem to render the triangle that rendering as RHW ,pretransformed vertices, here is the render code
[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();
}
}
[/code]


what am i doing wrong?
0

Share this post


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

[left]float4 PShader(VertexOut input) : SV_Target[/left]
[left]{[/left]
[left] return input.Color;[/left]
[left]}[/left]

[left]in your technique and pass, do this:[/left]

[left]SetVertexShader( CompileShader( vs_4_0, VShader() ) );[/left]
[left]SetPixelShader( CompileShader( ps_4_0, PShader() ) );[/left]

also, do this:

[color=#000088]struct[/color][color=#000000] [/color][color=#660066]VertexOut[/color]
[color=#666600]{[/color]
[color=#000000] float4 [/color][color=#660066]Pos[/color][color=#000000] [/color][color=#666600]:[/color][color=#000000] SV_POSITION[/color][color=#666600];[/color]
[color=#000000] float4 [/color][color=#660066]Color[/color][color=#000000] [/color][color=#666600]:[/color][color=#000000] COLOR[/color][color=#666600];[/color]
[color=#666600]};[/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)
0

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

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
0

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

Share this post


Link to post
Share on other sites
What are the values of your view/projection matrices?
[quote name='iedoc' timestamp='1329042635' post='4912229']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[/quote][quote name='Anddos' timestamp='1329044299' post='4912232']this dosent seem to be working with the SV stuff, not sure what todo now[/quote]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.
0

Share this post


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

Share this post


Link to post
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
0

Share this post


Link to post
here is my code

[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);
}
[/code]

[code]
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();

}
}
[/code]
0

Share this post


Link to post
Share on other sites
its just rendering normal

[img]http://imageshack.us/photo/my-images/854/rhwtriangle.jpg[/img]
0

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).
0

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+.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0