Jump to content

Jedi Academy turned 20 this year! We celebrated in a ton of different ways: mod contest, server event, podcast, etc. Thank you to all who have been a part of this game for the last two decades. Check out the anniversary content!

Read more

Welcome to JKHub

This community is dedicated to the games Star Wars: Jedi Outcast (2002) and Jedi Academy (2003). We host over 3,000 mods created by passionate fans around the world, and thousands of threads of people showcasing their works in progress and asking for assistance. From mods to art to troubleshooting help, we probably have it. If we don't, request or contribute!

Get started

This game turned 20 years old this year, and it is still one of the greatest Star Wars games of all time. If you're new or returning from a long hiatus, here are the basics of getting started with Star Wars Jedi Knight Jedi Academy in 2023.

Read more

Basics of skinning 05: RBG on Transparent Shaders


Omicron

Skinning Tutorial #5 - RGB on Transparent Textures
This probably would have been more useful four years ago... But better late than never.

Prerequisites:

What we want:
A texture with transparent parts (such as a hole in a cape) and areas which have RGB customisation.

 

"Traditional" RGB:
Apply RGB to entire texture with rgbGen lightingDiffuseEntity, then render the texture on top with transparency applied by blendFunc blend*. This allows the coloured components to show through.

 

*This is shorthand for blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA.

 

The problem:
If you need part of a texture to be transparent (ripped cape, see-through clothing, etc) then how do you selectively apply RGB to the areas you want to change colour? You somehow have to distinguish between which areas in the alpha channel should remain transparent, and which should be rendered and coloured.

 

This will be less of a "how-to" and more like a guide. There are a couple of ways to achieve this.

 

Using a mask:
Pros: Works for all cases, simple.
Cons: Requires at least two textures; bigger file size.

 

The idea behind this is to split a texture into two: One with the parts we want to change colour, the other not. These will be referred to as "tint" and "mask".

 

Tint image:
In your image editing software, make a selection around the areas you want to have RGB customisation. Invert selection and delete/make fully transparent. Save as a new image.

  Hide contents

spacer.png

 

Mask image:
Same as before, but instead delete the areas you want to have RGB (i.e. the selection you made).

  Hide contents

spacer.png

 

Shader:

<path to texture>
{
	{
		map <path to tint>
		blendFunc blend
		rgbGen lightingDiffuseEntity
	}
	{
		map <path to mask>
		blendFunc blend
		rgbGen lightingDiffuse
	}
}

 

In game:

  Hide contents

spacer.png

 

I recommend doing it this way. However, I have also written how to accomplish this using alphaFunc instead.

 

Using alphaFunc:
Pros: One texture required.
Cons: Right faff to do, doesn't cover all use cases.

 

I briefly touched on alphaFunc in an earlier tutorial. It has three possible paramaters: GT0, LT128 and GE128 (greater than, 0, less than 128 and greater or equal to 128). 0 and 128 are referring to the value in the alpha channel: 0 is transparent, 255 is opaque, everything else inbetween. So with that said, this method will only work if your texture has "hard", fully transparent areas; won't work on anything with a slight opacity.

 

If your finished texture satisifies this constraint, then open it in your image editing software and make a layer mask from the alpha channel. The areas you want to be transparent should be black (#000000    ) in the mask. Make a selection of the parts you want to have RGB and colour them #7F7F7F      (or any shade of grey > 0 and < 128 in brightness). Apply layer mask and save.

  Hide contents


White = Non-RGB component of texture
Grey = RGB component of texture
Black = Transparent component of texture

spacer.png

 

Shader:

<path to texture>
{
	{
		map <path to texture>
		blendFunc GL_ONE GL_ZERO
		alphaFunc GT0
		rgbGen lightingDiffuseEntity
	}
	{
		map <path to texture>
		blendFunc GL_ONE GL_ZERO
		alphaFunc GE128
		rgbGen lightingDiffuse
	}
}

 

In game:

  Hide contents

spacer.png

 

The only reason I can see this second method being used is if you require a different blendFunc for your texture, such as forcing a specific RGB value and want to mitigate the lighting issue.

 

Final note:
This is somewhat of a niche problem so take your pick depending on your needs.


User Feedback

Recommended Comments

There are no comments to display.



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...