Jump to content
  • Advertisement
Sign in to follow this  
GroZZleR

HLSL Newbie - Shader has no effect.

This topic is 4848 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

Hey all, I'm just getting into shader programming and I haven't been able to find much information on HLSL. I've hacked together a program, but it doesn't seem to have any effect on the polygons I'm rendering. This is my shader:
// Output
struct VS_OUTPUT
{
	float4 pos  : POSITION;
	float4 diff : COLOR0;
};

// Shader Operation
VS_OUTPUT TestOp(
    float4 Pos  : POSITION, 
    float4 Diff : COLOR0, 
    float2 Tex  : TEXCOORD0
)
{
	// Return Value
	VS_OUTPUT Out = (VS_OUTPUT)0;

	// Same position we were passed
	//Out.pos = float4(32.0f, 32.0f, 32.0f, 32.0f);
	Out.pos = Pos;

	// Set the colour.
	Out.diff = float4(1.0f, 0.0f, 0.0f, 1.0f);

	// Return
	return Out;
}

technique TestTechnique
{
    pass P0
    {
        VertexShader = compile vs_1_1 TestOp();
        PixelShader  = NULL;
    }
}


Here's the loading routine:
string error = null;
_effect = Direct3D.Effect.FromFile(_device, @"simple.fx", null, null, "", Direct3D.ShaderFlags.None, null, out error);
if(error != null)
	MessageBox.Show(error);


Here's the pass routine:
_effect.Technique = "TestTechnique";

int numPasses = _effect.Begin(0);
for (int pass = 0; pass < numPasses; pass++)
{
	_effect.BeginPass(pass);

	for(int i = 0; i < _drawList.Count; ++i)
		((IDrawable)_drawList).OnDraw(_graphics);

	_effect.EndPass();
}
_effect.End();


It all seems pretty standard from what I've been able to find. I'm using PositionColoredTextured vertices, if that makes a difference. Instead of turning the polygons red, it keeps them all white (the default colour). Like I said at the start, I haven't been able to find much beginner material on HLSL. Hopefully someone can give me some guidance. Thanks guys. EDIT: I'm using an orthographic projection. [Edited by - GroZZleR on August 7, 2005 10:01:08 PM]

Share this post


Link to post
Share on other sites
Advertisement
You are just setting your output position to your input position... You need to mulitply that by the worldViewProjection matrix to put your verticies into "screen space".

in directx do

matWorldViewProj = matWorld * matView * matProj;

effect.SetMatrix("matrixWorldViewProj", &matWorldViewProj);
// ^ this is the name of the matrix inside hlsl
// in the shader you declare it like
// float4x4 matrixWorldViewProj - it needs to be global

inside the shader you do

OUT.position = mul(IN.position, matrixWorldViewProj);

// The order in the mul() function does matter - it is the difference between the
// vector (IN.position in this case) being treated as a row or column vector.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!