Sign in to follow this  
CodeReaver

Diffuse colour in effect files:

Recommended Posts

I'm trying to use this with an x file, but the object only shows up if I turn off the lighting. (I'm testing with MeshView) I think I just need to specify a diffuse colour and I've tried looking it up, however every example seems to use vertex and pixel shaders and is far more complicated than I need this to be. I just want to use the same diffuse colour (passed in like the texture is) with every polygon that gets rendered using this technique. Not only will vertex shaders take a lot longer to learn, but I imagine they will slow down the rendering a lot as well.
texture texture0;

technique MainTechnique
{
	pass p0
	{
		Texture[0] = <texture0>;
		Lighting = TRUE;
		ColorVertex = FALSE;
		CullMode = NONE;
		ZEnable = TRUE;
		ZWriteEnable = TRUE;
		DitherEnable = TRUE;
		SpecularEnable = FALSE;
		NormalizeNormals = TRUE;
		AlphaTestEnable = TRUE;
		AlphaFunc = GREATER;
		AlphaRef = 0xA0;
		ColorOp[0] = MODULATE;
		ColorArg1[0] = TEXTURE;
		ColorArg2[0] = CURRENT;
		AlphaOp[0] = MODULATE;
		AlphaArg1[0] = TEXTURE;
		AlphaArg2[0] = DIFFUSE;
		MagFilter[0] = LINEAR;
		MinFilter[0] = LINEAR;
		AmbientMaterialSource = MATERIAL;
	}
}

Share this post


Link to post
Share on other sites
I don't think using a pixel shader would necessarily complicate things. It certainly won't slow anything down as they are made to do just this: color pixels. Coloring it a single color is about the simplest use I can imagine. Try something like this:

float4 diffuse = { 1.0f, 0.0f, 0.0f, 1.0f };

float4 PS() : COLOR
{
return diffuse;
}

technique TDefault
{
PixelShader = compile ps_1_1 PS();
}


Greetz,

Illco

Share this post


Link to post
Share on other sites
Not anything anyone (including you) will notice. It might be slower, it might also be faster but the amounts we're talking here are totally insignificant.

Share this post


Link to post
Share on other sites
This seemed to do what I wanted:

float4 diffuse0;

technique TDefault
{
pass p0
{
MaterialDiffuse = <diffuse0>;
}
}


I'd found this (at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/Effect_States.asp) already, but I was given an error no matter where I put these lines:

MaterialDiffuse = float4<0.7f, 0.0f, 0.0f, 1.0f>;
MaterialPower = 3.0f;


And I couldn't see any examples that didn't use vertex/pixel shaders and weren't made up of some complex HLSL code. I'll probably study that in depth at some point, but I wanted to keep it simple for now.

Share this post


Link to post
Share on other sites
Quote:
Original post by CodeReaver
Thanks. Doesn't colouring my mesh per-pixel cost a lot more than colouring it per vertex, polygon or subset?

No. If anything, it is faster.
When you colour the mesh by vertex, the vertex shader (or FFP equivalent) transforms the vertices as usual and passes all the data, including the colour, along the pipeline. The rasteriser then determines which pixels end up on screen and where they came from. Every pixel eventually has to be coloured individually, but if you colour by vertex, the rasteriser has to do the extra work of interpolating the colours of the vertices from which the pixel derived. If, however, the pixel shader returns a constant value then there's no need to pass the colour data from the vertex shader and no need to interpolate per pixel.

The performance difference is completely insignificant, but it's helpful to understand that colouring by vertex doesn't eliminate the need to colour by pixel.

Regards
Admiral

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