• Advertisement
Sign in to follow this  

Shader Program & passing variables using FVF

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

Im trying to pass variables using the TEXCOORD's into a shader program from a vertexbuffer. I have the following vertexformat: private struct Vertex { public Vector3 Position; public float Tu; public float Tv; public float angle; public float radius; public float colorA; public float colorB; public float colorG; public float colorR; public static readonly VertexFormats Format = VertexFormats.Position | VertexFormats.Texture4; } and the following struct in the fx file: struct VS_INPUT { float4 Pos: POSITION0; float2 Tex: TEXCOORD0; float2 AR: TEXCOORD1; float2 Col1: TEXCOORD2; float2 Col2: TEXCOORD3; }; The Pos, Tex & AR values are passing through correctly and rendering exactly what i want. Although i cant get the last 4 color vales to pass into Col1 & Col2, when i debug the shader program it says "* no storage" next to those 2 vars. Anyone have an idea - cus im running out of hair to pull. Cheers

Share this post


Link to post
Share on other sites
Advertisement
If it's anything like Cg, you'll want COLOR0, rather than other texture coordinates.

[EDIT]
By the way, it's a float4 (incase you were wondering).

Share this post


Link to post
Share on other sites
Thanks for the reply.

Ive tried using COLOR0 as a float4 and using NORMAL0 as a float3 - i get "(* no storage)" on both.

Share this post


Link to post
Share on other sites
This is D3D, right? Are you specifying the color/normal data in your FVF? I noticed you have Format = VertexFormats.Position | VertexFormats.Texture4;, so I would assume that to add color and normal information you would need it to be Format = VertexFormats.Position | VertexFormats.Texture4 | VertexFormats.Normal | VertexFormats.Color;. (You've probably alread done that, but it never hurts to try. ^_^)

Alos, I've noticed my D3D programs in the past were very picky about the order I had my vertex information in. (I believe it had to be POSITION-NORMAL-COLOR-TEXTURE) so you may want to double check that too.

Share this post


Link to post
Share on other sites
Yeah, if you are using FVF you have to have the information in a specific order (which is not well documented). I'd _strongly_ suggest using vertex declarations instead, which let you specify exactly the format you want with less potential for error. I don't think there's any good reason to use FVF in new programs at this time.

Share this post


Link to post
Share on other sites
just changed the code to use a vertexdeclerations initialised it and changed the - device.VertexDeclaration = Vertexdecl;

but still getting the same result, the last variable COLOR shows (* no storage).

any other ideas?

Share this post


Link to post
Share on other sites
In D3D, colors are 32 bit long values. Each byte in thet number holds a color component. (like AARRGGBB),

Those values ranged from 0 to 255 are transformed into float valoes in the 0-1 range inside the shader.

So, try changing your color floats in your structure. Maybe that helps.

Luck!
Guimo

Share this post


Link to post
Share on other sites
Ive tried using TEXCOORD and POSITION types instead of COLOR - and im still getting (* no storage).

Share this post


Link to post
Share on other sites
Sure:

VertexElement[] velem = new VertexElement[]
{
new VertexElement(0, 0, DeclarationType.Float3,
DeclarationMethod.Default,
DeclarationUsage.Position, 0),

new VertexElement(0, 12, DeclarationType.Float2,
DeclarationMethod.Default,
DeclarationUsage.TextureCoordinate, 0),

new VertexElement(0, 20, DeclarationType.Float2,
DeclarationMethod.Default,
DeclarationUsage.TextureCoordinate, 1),

new VertexElement(0, 28, DeclarationType.Float4,
DeclarationMethod.Default,
DeclarationUsage.Position, 1),

VertexElement.VertexDeclarationEnd
};
Vertexdecl = new VertexDeclaration(device, velem);

using this struct:

private struct Vertex
{
public Vector3 Position;
public float Tu;
public float Tv;
public float angle;
public float radius;
public float colorA;
public float colorB;
public float colorG;
public float colorR;
}

using this VB:

vb = new VertexBuffer(typeof(Vertex), pcount * 4, device, Usage.WriteOnly, VertexFormats.None, Pool.Default);

this is the input struct on the vertex shader:

struct VS_INPUT
{
float4 Pos: POSITION0;
float2 Tex: TEXCOORD0;
float2 AR: TEXCOORD1;
float4 C: POSITION1;
};

id appreciate any thoughts

Share this post


Link to post
Share on other sites
Just in case anyone else has the same problem - it seems that unless you actually use the variable in the function, the shader dosnt load the values. So debugging to see which values are passed before writing the shader code will result in "unable to evaluate the expression" or "(* no storage)" if you use a struct to pass in the values.

Share this post


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

  • Advertisement