Making Semi-transparent textures: Difference between revisions
Nbohr1more (talk | contribs) New Translucency Details |
Nbohr1more (talk | contribs) No edit summary |
||
Line 37: | Line 37: | ||
== New Findings == | == New Findings == | ||
Real Translucency | === Real Translucency === | ||
Rich_is_Bored discovered that a technique for translucent lighting discussed on Polygon forums could be implemented in Doom 3 | Rich_is_Bored discovered that a technique for translucent lighting discussed on Polygon forums could be implemented in Doom 3 | ||
Line 98: | Line 98: | ||
} | } | ||
} | |||
</pre> | |||
=== Lit Transparency === | |||
The HeatHaze Glass materials can be made to react to Transparency by including lit stages before the HeatHaze shader. | |||
The lighting is only passed to the stages after the HeatHaze so your will need to choose an OpenGL blend mode to | |||
capture the lighting. This essentially acts like the albedo color of the diffuse stage. | |||
<pre> | |||
translucent/pumpkin | |||
{ | |||
noshadows | |||
twoSided | |||
translucent | |||
forceoverlays | |||
sort decal | |||
forceOpaque | |||
qer_editorimage example_editor_image.jpg | |||
description "transparent lit material" | |||
{ | |||
blend bumpmap | |||
map normalmap.tga | |||
} | |||
{ | |||
blend diffusemap | |||
map _white | |||
red 1.0 // tune red illumination | |||
blue 1.0 // tune blue illumination | |||
green 1.0 // tune green illumination | |||
} | |||
{ | |||
blend specularmap | |||
map specularmap.tga | |||
rgb 0.5 // tone down specular | |||
} | |||
{ | |||
vertexProgram HeatHazewithMaskAndDepth.vfp | |||
vertexParm 0 0 , 0 // texture scrolling | |||
vertexParm 1 2 // magnitude of the distortion | |||
fragmentProgram HeathazeWithMaskAndDepth.vfp | |||
fragmentMap 0 _currentRender | |||
fragmentMap 1 _flat | |||
fragmentMap 2 _currentDepth | |||
} | |||
//-------------------------------------------------------------------------------------------------------- | |||
// add our texture on top | |||
{ | |||
blend blend | |||
maskalpha | |||
map diffusemap.tga | |||
alpha 0.8 // tune transparency | |||
rgb 0.4 | |||
} | |||
// TDM Ambient Method Related | |||
{ | |||
if (global5 == 1) | |||
blend add | |||
map diffusemap.tga | |||
scale 1, 1 | |||
red global2 | |||
green global3 | |||
blue global4 | |||
} | |||
} | } | ||
Revision as of 19:26, 25 July 2016
written by Springheel
I don't know if people already know about this, but it's news to me.
When I was working on the lantern textures, I noticed that if I used the following shader the texture turned out to be transparent.
textures/darkmod/metal/flat/lamp_glass_lit_transparent //glass is partially transparent { glass translucent // avoids implicit opaque black stage used for filling the depth buffer { blend add map models/darkmod/props/textures/lamp_glass_lit } }
Better yet, it wasn't totally transparent--you could still see the texture itself, but you could see through it. The effect was pretty neat, so I tried it on a simple brush in a map. Here's the result.
You can clearly see the texture, but you can also nicely see through it. Imagine this as a window. And no vertex shaders necessary, so it shouldn't have conflicts with water (though I haven't tested it). With the "translucent" keyword, you can also add a specular and bumpmap to the texture if you wish. I think this might be a cool way to provide transparent windows but still keep the warm glowy effect. You wouldn't be able to use it for all window textures (since any frame or crosspiece in the texture would also become transparent unless they were straight black) but it will be very effective for some models, and might be useful in other places I haven't thought of yet (an underwater overlay comes to mind).
An example of it in models (the two outside ones).
Pinkdot pointed out that the "blend add" effect will brighten whatever the player sees through the texture. This would work well for looking into well-lit homes or for stained glass. By using the same technique, but replacing "add" with "filter" you can get semi-transparent textures that darken what you see through them, perfect for looking outside or into unlit homes.
It's possible to put the lit texture on one side of a brush and the unlit on the other and have both work, so windows could have the proper appearance depending on whether you are looking inside or outside.
New Findings
Real Translucency
Rich_is_Bored discovered that a technique for translucent lighting discussed on Polygon forums could be implemented in Doom 3 by setting the vertex color gray and using an inverted normalmap for the inversevertexcolor.
Rebb found that you could use the scale keyword to programmatically invert the normalmap.
Finally, Rich_is_Bored found that all surfaces can use the effect if you simply set the diffuses stage to rgb 0.5 which is essentially the same as gray vertex color.
Final example:
translucent/example { // first pass { blend bumpmap map normalmap.tga } { blend diffusemap map diffusemap.tga rgb 0.5 } { blend specularmap map specularmap.tgs } // second pass // the scale function here is "inverting" the normal map so that it catches light from the opposite side. { blend bumpmap map scale(normalmap.tga, 1, 1, 0, 1) } { blend diffusemap map diffusemap.tga rgb 0.5 } // TDM Ambient Method Related { if (global5 == 1) blend add map diffusemap.tga scale 1, 1 red global2 green global3 blue global4 } }
Lit Transparency
The HeatHaze Glass materials can be made to react to Transparency by including lit stages before the HeatHaze shader. The lighting is only passed to the stages after the HeatHaze so your will need to choose an OpenGL blend mode to capture the lighting. This essentially acts like the albedo color of the diffuse stage.
translucent/pumpkin { noshadows twoSided translucent forceoverlays sort decal forceOpaque qer_editorimage example_editor_image.jpg description "transparent lit material" { blend bumpmap map normalmap.tga } { blend diffusemap map _white red 1.0 // tune red illumination blue 1.0 // tune blue illumination green 1.0 // tune green illumination } { blend specularmap map specularmap.tga rgb 0.5 // tone down specular } { vertexProgram HeatHazewithMaskAndDepth.vfp vertexParm 0 0 , 0 // texture scrolling vertexParm 1 2 // magnitude of the distortion fragmentProgram HeathazeWithMaskAndDepth.vfp fragmentMap 0 _currentRender fragmentMap 1 _flat fragmentMap 2 _currentDepth } //-------------------------------------------------------------------------------------------------------- // add our texture on top { blend blend maskalpha map diffusemap.tga alpha 0.8 // tune transparency rgb 0.4 } // TDM Ambient Method Related { if (global5 == 1) blend add map diffusemap.tga scale 1, 1 red global2 green global3 blue global4 } }