Jump to content

Transparency Shader Not Working


Botdra
Go to solution Solved by scp_chaos1,

Recommended Posts

I have this basic transparency shader I'm trying to get working in my map, with no success. I have an image file with a candle and a transparent background, saved as a PNG in Photoshop with the "Transparency" box checked, which I assume means it exports with an alpha channel. However, when I apply the texture to a brush and compile, I get a completely blank image. I got the shader from this tutorial.

textures/kb_map/candlesprites
{
	{
		map textures/kb_map/candlesprites
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		depthWrite
		rgbGen lightingDiffuse
	}
}

I have tried messing with different blending modes and using a black background instead, but that makes some of the shadow areas of my sprites transparent which is not the desired result.

Link to comment

Here's what I would do.....

I would make the candle flames a separate texture on a pure black background, add them as a separate stage to your shader, and use blendFunc GL_ONE GL_ONE on them so they blend properly with the environment.

For the candlesticks, remove the blendFunc, and use an alphaFunc to mask them.

I haven't written shaders in forever, so I can't write an example, but if memory serves, the landing pad texture at the center of mp/ffa5 is a great example of alphaFunc in action if you need it.

Link to comment
6 hours ago, Botdra said:

I have this basic transparency shader I'm trying to get working in my map, with no success. I have an image file with a candle and a transparent background, saved as a PNG in Photoshop with the "Transparency" box checked, which I assume means it exports with an alpha channel. However, when I apply the texture to a brush and compile, I get a completely blank image. I got the shader from this tutorial.

textures/kb_map/candlesprites
{
	{
		map textures/kb_map/candlesprites
		blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
		depthWrite
		rgbGen lightingDiffuse
	}
}

I have tried messing with different blending modes and using a black background instead, but that makes some of the shadow areas of my sprites transparent which is not the desired result.

Hey man, I think I can help, I have several shaders for that and I see that it's a map texture, so, if your current goal is to make them transparent, try this shader (Note: It also includes other features (shadow casting), but it's just what you're looking for):

textures/kb_map/candlesprites
{
    qer_editorimage textures/kb_map/candlesprites
    surfaceparm nonopaque
    surfaceparm trans
    surfaceparm alphashadow
    qer_trans 1.0
     {
    map textures/kb_map/candlesprites
    alphaFunc GE128
    blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
    depthWrite
     }
     {
    map $lightmap
    rgbGen identity
    blendFunc GL_DST_COLOR GL_ZERO
    depthFunc equal
     }
}

If your goal is to make only the flames and the candle outline glow (of course, you'll have to use a candlesprites_glow texture), try this:

textures/kb_map/candlesprites
{ 
	qer_editorimage textures/kb_map/candlesprites
	qer_trans 1.0   
	surfaceparm nonopaque 
	surfaceparm trans
	polygonOffset
    { 
	map textures/kb_map/candlesprites
	alphaFunc GE128 
	depthWrite 
    } 
    { 
	map $lightmap 
	depthFunc equal 
    } 
    {
	map textures/kb_map/candlesprites
	blendFunc GL_DST_COLOR GL_ZERO 
	depthFunc equal 
    } 
    {
	map textures/kb_map/candlesprites_glow
        blendFunc GL_ONE GL_ONE
        glow
	rgbGen identity 
    }
}

If either one doesn't work for you let me know so I can work on it in more detail.

Botdra and mjt like this
Link to comment
2 hours ago, scp_chaos1 said:

If either one doesn't work for you let me know so I can work on it in more detail.

Thank you, both of them work as you described. I just need to tweak it a bit and could use a hand.

The glow kind of works, but doesn't actually give off any light. It applies my glow texture properly with the correct blend mode, but doesn't actually give off any light/glow. If I have the brush outside in direct sunlight, then it looks like it glows properly. But if it's inside or in shade it doesn't glow, just looks flat. I changed "rgbGen identity" to vertex, and added cull twoSided, otherwise I left the shader as-is.

scp_chaos1 likes this
Link to comment
  • Solution

I don't use shader lighting, however I found what does that, in assets1, in imperial.shader I found this:

textures/kejim/flatwhite
{
	q3map_surfacelight	3000
	q3map_nolightmap
    {
        map textures/kejim/flatwhite
    }
}

What generates the light is "q3map_surfacelight 3000", so it should look like this:

textures/kb_map/candlesprites
{ 
	qer_editorimage textures/kb_map/candlesprites
	qer_trans 1.0   
	surfaceparm nonopaque 
	surfaceparm trans
	q3map_surfacelight	3000
	polygonOffset
	cull	twosided
    { 
	map textures/kb_map/candlesprites
	alphaFunc GE128 
	depthWrite 
    } 
    { 
	map $lightmap 
	depthFunc equal 
    } 
    {
	map textures/kb_map/candlesprites
	blendFunc GL_DST_COLOR GL_ZERO 
	depthFunc equal 
    } 
    {
	map textures/kb_map/candlesprites_glow
        blendFunc GL_ONE GL_ONE
        glow
	rgbGen identity 
    }
}

I created the glow file, it looks ugly but it serves its purpose (Note: This is a .jpg file)

image.jpeg.42b9fd7a9144d405ac9f40fff8d920aa.jpeg

This is the result: 

image.jpeg.cf688141609224d31c099ce91769d05d.jpeg

Smoo likes this
Link to comment
13 hours ago, scp_chaos1 said:

What generates the light is "q3map_surfacelight 3000", so it should look like this:

Thank you! This does in fact add light emission, but I notice your result is much more "clean" than mine. Here's what mine looks like in-game:

Screenshot2023-09-26102350.png.a3af1ff25838073a27ef2e8e9f1ea58e.png

My glow map is the same as yours, minus the top of the candles, so it's just a copy/paste of the flames themselves on a black background.

scp_chaos1 likes this
Link to comment

I don't know if it's because of the ambient of my worldspawn, but I see that there is no lighting on the texture side in your screenshot.

So, In base/shaders, did you add your .shader in shaderlist.txt?

Here's how I put it in my GTK Radiant: 

image.png.56e15a543e8f2e26a0d1a35502761548.png

My worldspawn configuration is next:

worldspawn
_color		0.2 0.4 1.0
ambient 	400
classname	worldspawn

 

Link to comment
48 minutes ago, scp_chaos1 said:

I don't know if it's because of the ambient of my worldspawn, but I see that there is no lighting on the texture side in your screenshot.

So, In base/shaders, did you add your .shader in shaderlist.txt?

Here's how I put it in my GTK Radiant: 

image.png.56e15a543e8f2e26a0d1a35502761548.png

My worldspawn configuration is next:

worldspawn
_color		0.2 0.4 1.0
ambient 	400
classname	worldspawn

 

That could be. Here's my worldspawn:

_color 1 0.71667 0.402228
classname worldspawn
light 25


Yes, my shader is in the shaderlist, I've got other custom shaders in my shader file that are working in-game.

My brush looks the same as yours in radiant, although it has nodraw instead of caulk, but I don't imagine that would be the problem.

scp_chaos1 likes this
Link to comment
4 hours ago, scp_chaos1 said:

I'm running out of alternatives, maybe my build configuration might work for you:

[bsp] -meta"[MapFile]"
[vis] -saveprt "[MapFile]"
[light] -lomem"[MapFile]"

 

I'm not sure how to use this info - is this just referencing the Build setting you select in Radiant or do I have to manually input this somewhere?

Link to comment
2 hours ago, scp_chaos1 said:

You have to enter that manually in Build, but I'll confirm in a while, I'm on another computer.  I'm not sure if it will work the same as me, because I use GTK Radiant 1.5

For some reason the candles and another shader I was tweaking randomly decided to start working. Well, alright then. Thanks for your help!

scp_chaos1 likes this
Link to comment
On 9/26/2023 at 8:45 PM, scp_chaos1 said:

Well, I'm back. Sorry for replying late, what exactly did you do, what was the last shader you used?

No clue, honestly. Don't you just love that? I think it may be because I was editing the shader then loading the .bsp again, instead of fully exiting JA. Here's the final shader file.

textures/kb_map/candlesprites
{ 
	qer_editorimage textures/kb_map/candlesprites
	qer_trans 1.0   
	surfaceparm nonopaque 
	surfaceparm trans
	q3map_surfacelight	3000
	polygonOffset
	cull	twosided
    { 
	map textures/kb_map/candlesprites
	alphaFunc GE128 
	depthWrite 
    } 
    { 
	map $lightmap 
	depthFunc equal 
    } 
    {
	map textures/kb_map/candlesprites
	blendFunc GL_DST_COLOR GL_ZERO 
	depthFunc equal
    } 
    {
	map textures/kb_map/candlesprites_glow
        blendFunc GL_ONE GL_ONE
        glow
	rgbGen identity
    }
}

 

scp_chaos1 likes this
Link to comment
2 hours ago, Botdra said:

I think it may be because I was editing the shader then loading the .bsp again, instead of fully exiting JA.

Actually, that's okay to do for most edits.

Certain things like lightmaps have to be compiled, so recompile your map and reload the level in-game, and you should see the changes. That's probably why it suddenly started working for you.

Link to comment
18 minutes ago, NAB622 said:

Actually, that's okay to do for most edits.

Certain things like lightmaps have to be compiled, so recompile your map and reload the level in-game, and you should see the changes. That's probably why it suddenly started working for you.

Yes, I noticed things like a missing bracket, changing deformVertexes etc. all can be change on the fly, but not things like environment maps or certain lighting related changes. Very confusing at first! 😅

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...