• ### Popular Now

• 15
• 15
• 11
• 9
• 10

This topic is 4866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
What you need to do is basically as follows. This is mostly from memory, but I'm fairly confident it's correct.

"texture texCar;\n"

You will need to bind this with a SetTexture() call (as you do the spheremap) with your car texture, in your application.

In your vertex shader, you need to get yourself some texture coordinates for your car texture, you can output them to oT1. The simplest way to do this would be just to pass them through from texture coordinates which are on the mesh, something like:

// at the beginning of the vertex shader next to the other dcl_ statements"dcl_texcoord0 v2\n"// at the end of the vertex shader"mov oT1, v2\n"

Then you use your texture coordinates to look up your regular car texture.

This means changing the following:

// Pixel state"Texture[0] = <texSphereMap>;\n""AddressU[0] = Wrap;\n""AddressV[0] = Wrap;\n""MinFilter[0] = Linear;\n""MagFilter[0] = Linear;\n""ColorOp[0] = SelectArg1;\n""ColorArg1[0] = Texture;\n"

To something like
// Pixel state"Texture[0] = <texSphereMap>;\n""AddressU[0] = Wrap;\n""AddressV[0] = Wrap;\n""MinFilter[0] = Linear;\n""MagFilter[0] = Linear;\n"// car texture sampler states"Texture[1] = <texCar>;\n""AddressU[1] = Wrap;\n""AddressV[1] = Wrap;\n""MinFilter[1] = Linear;\n""MagFilter[1] = Linear;\n"// blend the two textures"ColorOp[0] = SelectArg1;\n""ColorArg1[0] = Texture;\n""ColorOp[1] = Modulate;\n""ColorArg1[1] = Current;\n""ColorArg2[1] = Texture;\n"

This should multiply the spheremap by the car's texture map, combining them. However, I'm not sure what kind of result you'd get with this, it's just the easiest way to get it working. For a better result you could linearly interpolate between the two textures. How do you do that? Well, here's a quick explanation:

Use the Lerp command, which has the following equation:

SRGBA = (Arg1) * Arg2 + (1 - Arg1) * Arg3

You want to interpolate between texSphereMap and texCar, based on some parameter value. Setting up the interpolation is quite easy.

// the last part of the texture stage state setup"ColorOp[0] = SelectArg1;\n""ColorArg1[0] = Texture;\n""ColorOp[1] = Lerp;\n""ColorArg1[1] = Current;\n""ColorArg2[1] = Texture;\n""ColorArg0[1] = TFactor;\n"

You can see we've added this "TFactor" item which acts as the parameter for the Lerp equation. You set this inside your effect too using the following:

"TextureFactor = 0x00000000;\n"

It takes DWORD values, the same as D3DCOLOR types infact. Tweak it all you like :)

Hope some of that helped.

-Mezz

##### Share on other sites
Sweet! Thanks a million, you're a godsend :) I will try this out, it looks like it should work, or at least from here I can figure out the rest hopefully!

##### Share on other sites
Cool, I got it working using the code you posted (thanks so much again!) It looks awesome, the only thing is I'm not sure if using "lerp" is accurate for modeling reflections, since real reflections are additive (I think). So, I tried simply changing "lerp" to "add", as in:

This ignores TextureFactor though, it seems to be doing simply tex0 + tex1 instead of tex0 + (tex1 * TextureFactor) which is what I am aiming to do.

Anyone know if it's possible to control the amount of additive blending going on?

Thanks,
roos

##### Share on other sites
Post up a picture;)

##### Share on other sites
Yeah, you're right reflections are additive. I was getting ahead of myself with the lerp - typically that is what is used to account for fresnel as I recall. To control the amount of adding, well, you could set it up so you do something like this (pseudocode):

(spheremapTexture * someValue) + diffuseTexture

If you put someValue in the TextureFactor, and set up the pixel state appropriately that should give you control over how much is added on easily :)

Hope that helps.

EDIT

Sorry, I see you already decided this is what you want. Well, here is the way to go about it:

// texture stage 0, multiply spheremap by tfactor"ColorOp[0] = Modulate;\n""ColorArg1[0] = Texture;\n""ColorArg2[0] = TFactor;\n"// texture stage 1, add on previous stage output to this texture"ColorOp[1] = Add;\n""ColorArg1[1] = Current;\n""ColorArg2[1] = Texture;\n"

-Mezz

##### Share on other sites
Ahh I see now.. It seems very easy when you explain it like that, thanks again for taking the time to spell things out to a noob like me!

Heh I'm going on vacation now for 2 days but when I get back in town I can post up a shot...

thanks,
roos