+ Reply to Thread
Results 1 to 5 of 5

Thread: Shader question (transparency)

  1. #1
    Senior Member muckyman will become famous soon enough muckyman will become famous soon enough muckyman's Avatar
    Join Date
    Aug 2010
    Location
    ingerland,ingerland,ingerland
    Posts
    1,668

    Shader question (transparency)

    I have some texures I made,grates chainlink fence etc....the transparency shows up as black in radiant and game.
    Is there a shader in "common" I can use to make the black transparent ?
    Quote Originally Posted by Stanton Friedman
    All flying saucers are UFO`s not all UFO`s are flying saucers.

  2. #2
    Junior Member jlaw is on a distinguished road
    Join Date
    Aug 2010
    Posts
    10
    For the standard way to tackle this, you need to open the texture back up in your graphics program and give it an alpha channel.

    Then you need to make your own shader that applies that texture to a surface with transparency. There's a good example, and a short discussion of alpha/transparency, here:

    http://icculus.org/gtkradiant/docume...ch06/pg6_1.htm

    Let me copy the example shader here to talk about it a little more:

    Code:
    textures/base_floor/pjgrate1
    {
    	surfaceparm metalsteps
    	cull none
    
    	// A GRATE OR GRILL THAT CAN BE SEEN FROM BOTH SIDES
    	{
    		map textures/base_floor/pjgrate1.tga
    		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
    		alphaFunc GT0
    		depthWrite
    		rgbGen identity
    	}
    	{
    		map $lightmap
    		rgbGen identity
    		blendFunc GL_DST_COLOR GL_ZERO
    		depthFunc equal
    	}
    }
    That is almost just the very most basic shader, which only applies a texture to a surface, with a few twists.

    The lightmap stage of this shader is standard so let's ignore that.

    "cull none" lets the surface be seen from either side, which is something you might want for a basically two-dimensional surface like a fence or a grate.

    The shader stage that applies the pjgrate1.tga texture has an "alphaFunc GT0" instruction that is the magic for transparency. alphaFunc is described at the bottom of the page here: http://icculus.org/gtkradiant/docume...ch05/pg5_1.htm

    If you say "alphaFunc GT0" then you are saying that your texture should be opaque only where its alpha channel is greater than 0. In your case, since you want the black areas of your texture to be transparent, this could be handy. When you create your texture's alpha channel you could just make it a copy of the one of texture's current red/green/blue channels. If your black areas are TRULY black, i.e. they have a 0 value in the channel you copied, then your alpha channel will end up being 0 in the places that you want to be transparent. Then you can use "alphaFunc GT0" in your shader.

    (I'm sure there are lots of tutorials out there for making alpha channels using Photoshop, GIMP, paint.net, etc.)

    The other interesting instruction there is "blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA". This is blending pjgrate1.tga over the current texture on the surface, according to its alpha channel. But since this is the first stage in the shader, there's not any "current texture" on the surface, and the alphaFunc is just going to make the zero-alpha spots of the surface transparent anyway. So this is a little odd.

    In fact if you look in the base_floor.shader script in the final version of Quake 3, the final version of this particular shader just uses the standard "blendFunc GL_ONE GL_ZERO", which simply covers the surface with the texture.

    Anyway, if you can make an appropriate alpha channel for your texture, then you can make a shader for your texture that is like this example. You may not want "surfaceparm metalsteps" of course, if your texture doesn't look metallic. You also probably want to use "blendFunc GL_ONE GL_ZERO" instead of "blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA".
    Last edited by jlaw; 10-20-2013 at 09:24 AM.

  3. #3
    Senior Member muckyman will become famous soon enough muckyman will become famous soon enough muckyman's Avatar
    Join Date
    Aug 2010
    Location
    ingerland,ingerland,ingerland
    Posts
    1,668
    Thanks for the help,i`m new to radiant so just working out how things work...
    I will probably be back with more facepalm questions.
    Quote Originally Posted by Stanton Friedman
    All flying saucers are UFO`s not all UFO`s are flying saucers.

  4. #4
    Junior Member jlaw is on a distinguished road
    Join Date
    Aug 2010
    Posts
    10
    You're welcome. I hope I remembered correctly. It's been a while.

    Actually I do see one thing I said that might not have been quite right. "current texture on the surface" should have been "current pixels in the framebuffer" (I think), meaning that that "blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA" would be another way of doing transparency without using alphaFunc. If that's the case then the difference would be that the blendFunc can be used to do graduated degrees of transparency, while alphaFunc is just a yes/no test where each pixel is either fully transparent or fully opaque.

    (Either way your texture does need to have an alpha channel.)

    Anyway you can experiment with that stuff, and check out those pages of the shader manual.
    Last edited by jlaw; 10-20-2013 at 10:42 AM.

  5. #5
    Member Obsidian is on a distinguished road
    Join Date
    Aug 2010
    Posts
    30
    For reference, you might want to link to the new and updated shader manual. The one linked above is ancient.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts