Jump to content

  • Log In with Google      Sign In   
  • Create Account

Using Vertex Paint in DirectX and C++


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Medo3337   Members   -  Reputation: 680

Like
0Likes
Like

Posted 04 June 2012 - 04:28 PM

I have made a terrain in 3Ds Max, added "Vertex Paint" modifier and exported the mesh as .x file.

I imported the .x file in DirectX/C++, what I am trying to do now is to set the main texture as stone and and "Vertex Paint" texture as grass.

How can I do that?

Sponsor:

#2 Nik02   Crossbones+   -  Reputation: 2923

Like
0Likes
Like

Posted 05 June 2012 - 01:29 AM

If the exporter writes the vertex paint channel as vertex colors (though I doubt it), you can write a pixel shader that gets the interpolated vertex color and does texture mixing with the color data.

In general, Max-specific modifiers are poorly supported in file exporters. This may have changed in the past years, I haven't used Max for a while.

One option, though time-consuming, is to define your own file format and write an exporter that does export the channel generated by the modifier. The Max SDK used to have a comprehensive sample about this.

Niko Suni


#3 Medo3337   Members   -  Reputation: 680

Like
0Likes
Like

Posted 09 June 2012 - 04:35 PM

Can you give example on the the Shader code that I can use to mix textures?

#4 Nik02   Crossbones+   -  Reputation: 2923

Like
0Likes
Like

Posted 09 June 2012 - 10:59 PM

You'd just use the interpolated vertex color components as weights by which you apply the textures. The vertex shader would pass thru the vertex colors, and the pixel shader would look something like this:

// compile with < SM4
// vertex shader not illustrated here, but it should produce the VS_OUT
struct VS_OUT
{
float4 pos : POSITION; // ordinary position
float4 tc : TEXCOORD0; // ordinary texture coordinate
float4 textureWeights : COLOR; // vertex color represents texture weights; r component = rock weight and g = grass weight
};
Texture2D rockTexture;
Texture2D grassTexture;
sampler rockSampler = sampler_state
{
Texture = <rockTexture>;
// set filters here as needed
};
sampler grassSampler = sampler_state
{
Texture = <grassTexture>;
};

float4 ps(VS_OUT input) : COLOR
{
float4 ret = float4(0,0,0,0); // or whatever your "base" color is
ret = lerp (ret, tex2D (rockSampler, input.tc), input.textureWeights.r); // add the contribution of the rock texture
ret = lerp (ret, tex2D (grassSampler, input.tc), input.textureWeights.g); // add the contribution of the grass texture
// you'd still have blue and alpha free for two more textures
return ret;
}

Of course, the actual PS logic would depend on how you author the textures and vertex colors.

Niko Suni


#5 Medo3337   Members   -  Reputation: 680

Like
0Likes
Like

Posted 10 June 2012 - 02:04 AM

Texture = <rockTexture>;
Texture = <grassTexture>;

Since the textures will be encrypted image files, is it possible that I use the textures that I assigned using Device->SetTexture(0, ...); and Device->SetTexture(, ...);

#6 Nik02   Crossbones+   -  Reputation: 2923

Like
0Likes
Like

Posted 10 June 2012 - 06:20 AM

If you use shaders in D3D9 without using the Effect framework, your approach is the only one anyway Posted Image

You can find the sampler indices of named sampler variables from compiled shader by using the ID3DXConstantTable interface. Note that in D3D9, a given texture is always bound to a given sampler index; in D3D10 and up, textures and sampler states are more separated.

Alternatively, you can force the texture variables to slots of your choice, by declaring them in the shader file as follows:

rockTexture : register(t0)
grassTexture : register(t1)

Then, SetTexture(0, ...) would set the rock texture, and SetTexture(1, ...) would set the grass texture.

Edited by Nik02, 10 June 2012 - 06:22 AM.

Niko Suni





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS