Jump to content
  • Advertisement
Sign in to follow this  
geniass

Multiple textures in a single model

This topic is 3182 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 have a .fbx model that uses several textures, eg. one for the head, one for the arm etc... But I am also using a custom shader: // Maximum number of bone matrices we can render using shader 2.0 in a single pass. // If you change this, update SkinnedModelProcessor.cs to match. #define MaxBones 59 // Input parameters. float4x4 View; float4x4 Projection; float4x4 Bones[MaxBones]; float3 Light1Direction = normalize(float3(1, 1, -2)); float3 Light1Color = float3(0.9, 0.8, 0.7); float3 Light2Direction = normalize(float3(-1, -1, 1)); float3 Light2Color = float3(0.1, 0.3, 0.8); float4 AmbientColor = float4(0.2,0.2,0.2,1); float4 Color; /////////////////////////////////////////////////////////////////////////////////// ////Picking // ////////////////////////////////////////////////////////////////////////////////// // Vertex shader input structure. struct P_VS_INPUT { float4 Position : POSITION0; float4 BoneIndices : BLENDINDICES0; float4 BoneWeights : BLENDWEIGHT0; }; // Vertex shader output structure. struct P_VS_OUTPUT { float4 Position : POSITION0; }; // Vertex shader program. P_VS_OUTPUT P_VertexShader(P_VS_INPUT input) { P_VS_OUTPUT output; // Blend between the weighted bone matrices. float4x4 skinTransform = 0; skinTransform += Bones[input.BoneIndices.x] * input.BoneWeights.x; skinTransform += Bones[input.BoneIndices.y] * input.BoneWeights.y; skinTransform += Bones[input.BoneIndices.z] * input.BoneWeights.z; skinTransform += Bones[input.BoneIndices.w] * input.BoneWeights.w; // Skin the vertex position. float4 position = mul(input.Position, skinTransform); output.Position = mul(mul(position, View), Projection); return output; } // Pixel shader program. float4 P_PixelShader(P_VS_OUTPUT input) : COLOR0 { return Color; } technique SkinnedModelPickingTechnique { pass SkinnedModelPass { VertexShader = compile vs_2_0 P_VertexShader(); PixelShader = compile ps_2_0 P_PixelShader(); } } //////////////////////////////////////////////////////////////////////// //////Scene /////////////////////////////////////////////////////////////////////// texture Texture; sampler Sampler = sampler_state { Texture = (Texture); MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; }; // Vertex shader input structure. struct VS_INPUT { float4 Position : POSITION0; float3 Normal : NORMAL0; float2 TexCoord : TEXCOORD0; float4 BoneIndices : BLENDINDICES0; float4 BoneWeights : BLENDWEIGHT0; }; // Vertex shader output structure. struct VS_OUTPUT { float4 Position : POSITION0; float3 Lighting : COLOR0; float2 TexCoord : TEXCOORD0; }; // Vertex shader program. VS_OUTPUT VertexShader(VS_INPUT input) { VS_OUTPUT output; // Blend between the weighted bone matrices. float4x4 skinTransform = 0; skinTransform += Bones[input.BoneIndices.x] * input.BoneWeights.x; skinTransform += Bones[input.BoneIndices.y] * input.BoneWeights.y; skinTransform += Bones[input.BoneIndices.z] * input.BoneWeights.z; skinTransform += Bones[input.BoneIndices.w] * input.BoneWeights.w; // Skin the vertex position. float4 position = mul(input.Position, skinTransform); output.Position = mul(mul(position, View), Projection); // Skin the vertex normal, then compute lighting. float3 normal = normalize(mul(input.Normal, skinTransform)); float3 light1 = max(dot(normal, Light1Direction), 0) * Light1Color; float3 light2 = max(dot(normal, Light2Direction), 0) * Light2Color; output.Lighting = light1 + light2 + AmbientColor; output.TexCoord = input.TexCoord; return output; } // Pixel shader input structure. struct PS_INPUT { float3 Lighting : COLOR0; float2 TexCoord : TEXCOORD0; }; // Pixel shader program. float4 PixelShader(PS_INPUT input) : COLOR0 { float4 color = tex2D(Sampler, input.TexCoord); color.rgb *= input.Lighting; return color; } technique SkinnedModelSceneTechnique { pass SkinnedModelPass { VertexShader = compile vs_2_0 VertexShader(); PixelShader = compile ps_2_0 PixelShader(); } } So I assume that the Texure variable in the shader is undefined, and is therefor rendering a black model without textures. This happens even if the model only uses one texture. So how can I give the shader the appropriate textures for each model?

Share this post


Link to post
Share on other sites
Advertisement
Change this part of the shader as follows:

Original:

////////////////////////////////////////////////////////////////////////
//////Scene
///////////////////////////////////////////////////////////////////////

texture Texture;

sampler Sampler = sampler_state
{
Texture = (Texture);

MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};


New:


////////////////////////////////////////////////////////////////////////
//////Scene
///////////////////////////////////////////////////////////////////////

uniform extern texture Texture;

sampler Sampler = sampler_state
{
Texture = (Texture);

MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
};


Now in C++ do the following:


// Init
D3DXHANDLE m_hTex = mFX->GetParameterByName(0, "Texture");

// Per draw
LPDIRECT3DTEXTURE9 pTex = MyTexture;
mFX->SetTexture( m_hTex, pTex );

Share this post


Link to post
Share on other sites
I don't think this helps with setting multiple textures for a model, setting one texture I can do, it is a certain model that uses 2 that is a problem.

Share this post


Link to post
Share on other sites
You need to set a texture then draw the tris associated with that texture. Swap to the different texture then draw those tris. How you split your model up is going to dictate how you give the tris to the card. You can't just give it a list of textures and expect it to figure out what goes where.

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!