• Advertisement
Sign in to follow this  

Pixel Shaded Meshes

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

I am attempting to blend two textures together using a very simple HLSL Pixel Shader and apply it to a Mesh (ID3DXMesh). The texture output by the pixel shader is currently being applied to both a quad created with IDirect3DVertexBuffer9 and the Mesh (ID3DXMesh) wich is loaded with D3DXLoadMeshFromX. During the rendering process, I set the textures, then render the quad and the mesh. The texture output by the pixel shader gets applied to the quad just fine, but the mesh will only have the base texture applied to it. Is there something else I am supposed to do to the mesh before it can have the pixel shaded texture applied to it? -Chris

Share this post


Link to post
Share on other sites
Advertisement
How are you rendering the mesh? Are you looping through all materials and calling ID3DXMesh::DrawSubset or are you using some of the helper functions for .x meshes? I ask because some of these helper functions may just set the first texture to whatever was loaded from the .x file and then set all the other textures to NULL. That could explain the behavior you're seeing.

neneboricua

Share this post


Link to post
Share on other sites
Quote:
Original post by neneboricua19
How are you rendering the mesh? Are you looping through all materials and calling ID3DXMesh::DrawSubset or are you using some of the helper functions for .x meshes? I ask because some of these helper functions may just set the first texture to whatever was loaded from the .x file and then set all the other textures to NULL. That could explain the behavior you're seeing.

I recommend that while using HLSL and ID3DXMesh that you make your own DrawIndexedPrimitive() call, instead of using ID3DXMesh::DrawSubset(). This is easy because ID3DXMesh has all of the appropriate accessor functions.

I suppose that it gets more complicated when you have multiple, independent materials and subsets. However, you can use the attribute table to extract that information.

Share this post


Link to post
Share on other sites
On the off chance, what are your vertex formats/declarations?

Does your quad, being manually created, have two sets of texture coordinates (one for each "layer") ?? By default, an ID3DXMesh loaded using D3DX/From a .X file will contain the basic XYZ/NORMAL/TEX1 setup.

Maybe you should try ID3DXMesh::CloneFVF( ) to make sure that your mesh has 2 sets of coordinates?

As I said - just a long shot [wink]
Jack

Share this post


Link to post
Share on other sites
I was doing the rendering with the DrawSubset function so maybe the mesh only has one set of texture cooridinates. I will try changing it and see what happens.

-Chris

Share this post


Link to post
Share on other sites
You don`t need two sets of texture coordinets... If you are using PS<1.4, you can clone texture coordinates in VS. PS>=1.4 can reuse same texture coordinates anyway...
Can you show your PS/VS code?

Share this post


Link to post
Share on other sites
Ok, here is the code for the pixel shader. It is very simple, it just blends two textures using a third texture as the blending map.

sampler Texture1;
sampler Texture2;
sampler TextureBlend;

struct PS_INPUT
{
float2 tex1 : TEXCOORD0;
float2 tex2 : TEXCOORD1;
float2 texb : TEXCOORD2;
};

struct PS_OUTPUT
{
vector diffuse : COLOR0;
};

PS_OUTPUT Main(PS_INPUT input)
{
PS_OUTPUT output = (PS_OUTPUT)0;

vector b = tex2D(Texture1, input.tex1);
vector s = tex2D(Texture2, input.tex2);
vector t = tex2D(TextureBlend, input.texb);

vector c = (b * t.g) + (s * t.b);

output.diffuse = c;

return output;
}

Share this post


Link to post
Share on other sites
If you are not using vertex shader, probably you are missing second (and third) texture coordinate sets...
If you are using Visual Studio, don`t forget that you can also use shader debugger to check values of texcoords...

Share this post


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

  • Advertisement