Advertisement Jump to content
Sign in to follow this  

HLSL Newbie - Shader has no effect.

This topic is 4914 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
    float4 Pos  : POSITION, 
    float4 Diff : COLOR0, 
    float2 Tex  : TEXCOORD0
	// Return Value

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

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

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

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


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
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!