Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Transparency\ghost shader with alphamap

Author
Message
GrumpyOne
16
Years of Service
User Offline
Joined: 27th Nov 2007
Location: London, UK
Posted: 30th Nov 2010 00:44
Dear All,

In return for answering my occasional dumb questions here is a shader that gives full control of object transparency using an alphamap. This gets around the annoying aspect of ghosting where black is always completely transparent, and the annoying aspect of transparency with png images with an alpha channel that have sharp edges. The object to which the shader is applied does not have ghost on or transparency set.

Shader code


DBP Code


For those who are interested in the details this shader also facilitates coloured distance fog and generates diffuse lighting depending on a light vector. The global light is specified in the shader as a default but can be overridden by passing as effect variables. The transparency is very simply controlled by setting the alpha of the color output from the pixel shader to the R bit of the alphamap texture, then setting alpha blending in the technique.

The attached screen shot shows one application, a ground texture around an RTS building generated on an object just above the terrain. I've got around 1000 of these objects on which the shader is running with no noticeable slow down. Notice that DBP's stencil shadows cast nicely on the object.

If you wanted to have transparency that changes with time (e.g. an object that fades away) you could always pass a float variable for the current total transparency and multiply it to the alphamap.x in the pixel shader.

Best,
Mr Grumpy

GrumpyOne - the natural state of the programmer

Attachments

Login to view attachments
gwheycs62egydws
14
Years of Service
User Offline
Joined: 17th Aug 2009
Location: The World
Posted: 26th Feb 2011 09:23
hi

I've been looking at code though out the forum for more than a year
now and it seems in the last couple of months more examples
have been appearing but once in a wile I find some thing new
from the olden days of 2006

for some reason things fell off after that and now DBP is
taking off

umm any chance of uploading the full code with the media ?

If a thought is Just a thought ~ so whats the main thought ?
sadsack
20
Years of Service
User Offline
Joined: 27th Nov 2003
Location: here
Posted: 26th Feb 2011 18:37
Yes if we could that would be nice
renny

Life is not fair, so deal with it.
http://www.gusroundtable.com/

Login to post a reply

Server time is: 2024-04-16 11:35:11
Your offset time is: 2024-04-16 11:35:11