Advertisement Jump to content
Sign in to follow this  

a special case of blending, how to?

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

Hi All, I have an object that is already textured using a pixel shader and 4 textures (+1 for the shading). It’s working perfectly. Now I’m taking a second pass with a different shader, and a different set of 4 textures (+1 shader texture). However, I want to control how much or little of the second pass gets applied to the base pass. If I’m using a pixel shader, do I need to enable this in it? Below is the pixel shader I’m using. I’m currently using the same one for both passes. Alternatively, I’d like to use a diffuse color on each vertex to control the amount of alpha between the base texture and the second pass, but I wasn’t sure I could do that while already using a shader? Any suggestions would be greatly appreciated, thanks. Quad Copy of the shader I’m using

// r0: alphamaps
// r1 - r4: textures

// Sample textures
texld r0, t0
texld r1, t1
texld r2, t1
texld r3, t1
texld r4, t1

// Combine textures together based off of their alphamaps
mul r1, r1, r0.x
lrp r2, r0.y, r2, r1
lrp r3, r0.z, r3, r2
lrp r0, r0.w, r4, r3 

Share this post

Link to post
Share on other sites
Just output the vertex diffuse as part of the pixel shader output color (in r0.a). Enable alphablending, and use srcblend=srcalpha, destblend=one. This will just add alpha*color to the existing framebuffer value from your first pass.

Share this post

Link to post
Share on other sites
I just realized, I don't really know shaders. The one I'm using someone else supplied. How to I set r0.a?


Share this post

Link to post
Share on other sites
You could do a constant, but you want your vertex diffuse, which is in v0.

"mov r0.a, v0.a" at the end

or for a constant
"def c0, 0, 0, 0, 0.5" at the top of the shader, after the version
"mov r0.a, v0.a" at the end of the shader.

Share this post

Link to post
Share on other sites
Thanks, but I still need a little more help.


srcblend=srcalpha, destblend=one

It's only partially working. I don't think this is what I want, but I haven't been able to determine the right combination yet.

I'm setting my diffuse color to one of the following:


The idea is to let 100% of the second pass show for textures that are close, and slowly have them fade out as the texture gets further away, showing more of the underlying color.

However, I don't want drastic color changes. When I use FF, I would expect the second pass to display the full colors of the now opaque texture, but instead it's tinted very heavily in YELLOW.

Any ideas what's going on?


Share this post

Link to post
Share on other sites
I think I got it. It seems that using:

_bothsrcalpha did the trick. Maybe someday I'll understand just what all these mean.

pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE );

Thanks for all the help, I appreciate it.


Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!