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

Basic shader file writing tutorial


Rooxon

Did you already model your first weapon? Okay great and I take it you have also tried it in-game, right? Well then I'm sure you noticed some other original sabers or other mods having some kinds of reflection, to show you what I mean, take a look at these two printscreens bellow.

 

Example picture 1: Rooxon's WeaponsHD Stinger a.k.a. Reborn saber 3.0 (included in the Misc sabers pack)

Spoiler

stingerscr.jpg

 

The top picture shows the model via ModView or rather, the way the actual textured model looks. The bottom pic shows with shaders applied. Do you want to be able to add such effects to your weapons? Than this tutorial is meant for YOU!

I'm going to cover two ways you can write shader files, though in this basic tutorial only the first one. And this as I call it, is "by hand" using Notepad, the other is with using ShaderEd2 which quickly and correctly writes your shaders, but to be honest, once you get the grip for it, it's way faster doing it by hand. Also ShaderEd2 is only good to check on errors on such easy shader effects that I'm going to teach you this time.

 

Table of contents:

(1.) Getting Ready...

(2.) Explanation of shaders and the first step: Thinking

(3.) Specular map shader

(3.1.) Additional texture making: specular map

(3.2.) Your first shader file! Specular map shader file template

(4.) Glow map

(4.1.) Additional texture making: glow map

(4.2.) Glow map shader file template

(5.) Enviromental map

(5.1.) To draw or to get it?

(5.2.) Enviromental map shader file template

(6.) Map combination and important facts!

(1.) Getting Ready...

 

NOTE: READ THE TUTORIAL CAREFULLY! It's quite detailed, I explain a lot of things, show some possible errors, what causes them and how to correct them!

 

Here are the tools and assets we are going to need:

- Notepad

- Desired model without shaders

- Photo-editing program (I'm using Photoshop CC, GIMP is a good alternative or nowadays even online image editing programs have all the needed tools)

- (OPTIONALLY) JKA SDK, which contains ShaderEd2

 

NOTE: Mostly we will be doing filters on the textures, so a program with utilities like light levels, saturation and color vibrance are a must!

NOTE 2: I'm not going to cover basic editing tools like resizing a picture in photoshop or what all possible filters do, I say TRY THEM OUT! That's how I learned to use Photoshop and for the info, pretty quickly.

 

For this tutorial, I will use my old Stinger model 2.0, which I also quickly trimmed of unnecessary files and it contains just the model and it's textures. You can find the download link of the finished pk3 file at the bottom!

If you're going to use this saber to learn from this tutorial, just make a "shaders" file directory in the PK3 file where the models directory is located! That's where we have to put our shader files in when we finish!

 

(2.) Explanation of shaders and the first step: Thinking

Shaders are basically text files, which give desired textures the desired effects, to make them look more realistic, but also to get some special effects like glow, transparency, twosided texture drawing, animations, chrome effects... This is done in a rather simple way, you just define which texture you want the effects added and later type the correct desired strings. There's also additional texture making needed, though not drawing, mostly you can do great specualr maps with some good thought-out filters. (depends on what shader you want to do)

 

Actually the possibilities are really WIDE. I'll divide them into two tutorials, with this one explaining the basic ones and later a more advanced shader tutorial which will be a video tutorial and teach you animating textures (like fire), cartoon-like shading, a detailed blendfunction explanation and so on.

 

Now before I say anything else, here comes the most important part of shader making. THINK! And give it a good thought, as now you have to decide what effects you want to add.

The way I think right now: "Let's say I want my saber to have a different reflection when light shines on it (like the one shown in the example above). Also, this plain texture would look great chromatic a bit. Oh and how cool is that, how about the top part of the saber hilt would glow, or the lines, or both? Gotta try it out."

 

So in short, this tutorial will teach you how to write correct shader files and how to do the corresponding texture files in photoshop at the same time.

 

(3.) Specular map shader

(3.1) Additional texture making: specular map

Well now that I know what effects I'm going to add. I also need to make the corresponding texture files.

 

Base texture:

Spoiler

sabern.jpg

Specular map:

This map shows when light shines on the model and ONLY on those parts (see the example picture at the top to see what I mean). With that in mind, I would make a map that shows just how those lit-up parts look like. So, I opened up the texture in Photoshop and went to Image/Adjustments/Levels and made the whole picture a bit lighter with the light shades also enhanced a bit. You find the Image tab up in the left corner of the program. Something like this is good enough:

Spoiler

tutspecmap.jpg

Usually I go much more extreeme regarding these settings, with darknes between 10-15 and lights between 215 and 200,sometimes even further. I slide the middle gray button according to the look itself, I don't want it too dark and not too lit up.

 

Additionally, I want to show a bit more intensive colors when light shines on the hilt, so again I go to Image/Adjustments/Vibrance and set the vibrance to +100 and saturation to 10, like this:

Spoiler

tutspecmap2.jpg

 

Well I'm satisfied with this for now, but the texture is a bit plain, empty. But I will fix this with shaders, and I'll do that by pasting over a nice metal texture and setting it';s blending to either Soft Light or Overlay. I do this by copy-pasting the metal texture to the hilt's texture and resize it to fit the borders. After that I set the blending to Soft Light and it's opacity to 70%. This is the texture I googled up (By Wojack) and this is how the texture looks like after applying it the way I proposed:

 

Wojack's Metal textures:

Spoiler

metaltexture1bywojtarsto.jpgMetal texture 1

 

metaltexture2bywojtarsto.jpg

Metal texture 2 / I used this one in the tutorial!

 

metaltexture4bywojtarsto.jpg

Metal texture 4

 

metaltexture7bywojtarsto.jpg

Metal texture 7

 

 

tutspecmap3.jpg

 

And this is our final look of the specular map. Save it as sabern_spec.jpg and that's it. Now we are going to write the shader file for the specular map.

 

(3.2) Your first shader file! Specular map shader file template

Yes, and you'll be pretty quick about it too. I think this is the easiest way, I'm going to give you what I've written and explain in detail what it means and what it does. At the bottom I'm going to include other interesting choices you might want to try out.

 

So open up notepad and copy-paste the concept you can use as a template for your own shader files (just change the file paths according to your desired textures):

 

models/weapons2/saber_reborn/sabern
{
q3map_onlyvertexlighting
{
map models/weapons2/saber_reborn/sabern
rgbGen lightingDiffuse
}
{
map models/weapons2/saber_reborn/sabern_spec
blendFunc GL_SRC_ALPHA GL_ONE
detail
alphaGen lightingSpecular
}
}

 

 

 

Explanation:

 

models/weapons2/saber_reborn/sabern //First off you define the path to the texture the shader schould be applied to. Note that it must be the first thing written in the file or else the shader won't work.

{

q3map_onlyvertexlighting //This line is something I tried out a long time ago and I think the weapons look nicer this way, it's not needed, but you can leave or delete it.

{

map models/weapons2/saber_reborn/sabern //With this line you define the path to the base map again. It always needs to be the first one

rgbGen lightingDiffuse rgbGen gives the map shading properties. When you use specular maps, ALWAYS set it to lightningDiffuse!

}

{

map models/weapons2/saber_reborn/sabern_spec We define the path to the specular map file, usually give it the same name as the base tex with _spec added at the end.

blendFunc GL_SRC_ALPHA GL_ONE This blending function makes the map shade everything but black and other than the base textures's black parts.

detail This string draws the map more detailed.

alphaGen lightingSpecular Finally, this line is actually responsible for the drawing effect of the map only where light shines on it.

}

}

 

IMPORTANT NOTE: the bracket placement has to be EXACTLY like mine. I press the Tab button to do these quick spaces in between the start of the row and the bracket. Look at the shader file I also included in this tutorial to see how it schould look when finished!

 

So if you've managed to get all of which I just told you, you've written your first shader file! Now all that's left is to save it as any_name_you_want.shader and copy-paste it into the Shader directory you may have created in my included PK3 file at the start and you can try it out! This is the result:

 

WITH SHADERS

shot0024.jpg

 

WITHOUT SHADERS

shot0029.jpg

 

BUT! If something like this happened to you, you probably forgot to copy the needed jpeg files to your pk3 file or haven't named them right:

shot0021.jpg

 

(4.) Glow map

(4.1.) Additional texture making: glow map

This is fairly easy, again let's open up the base texture and take a look. What would we want to see glow? Well let's say the upper part of the hilt and the black lines on the hilt.

 

If you can select the parts you want to make glow, do it. I'm going to select something and also make a new layer and draw red lines where the black ones are on the original map. To do this, I will use the Line tool located inside the Shape tool selection (click and hold on the Shape tool). Also, I make a new layer by pressing Lctrl + Lshift + n on the keyboard.

Spoiler

tutglowmap1.jpg

 

After this, hold ctrl and click on the picture of the layer with the lines to select all of them. After that use the Rectangle selection tool to add-select any other areas of the texture you want to glow (in the upper left corner, click the second button with the overlaping rectangles and filled whole). Once you've done so, you will have this:

Spoiler

tutglowmap2.jpg

Make sure your background layer is selected! Now pres ctrl+j and a new layer schould appear, Merge the two layers we've made, but only them, not to the background. Now once again select the background and fill it totally black.

Spoiler

tutglowmap3.jpg

 

From this point on the shader would already work, but it's better if we make the lights and colors as intensive as can be. Play around with either Image/Adjustments/Levels or Brightness&Contrast or Vibrance. My result is this:

saberng.jpg

If you want, you can use this one, just download the pk3 files down bellow, it's inlcuded together with the enviroment and specular map inside the hilts directory!

 

And that's it for the Glow map work in Photoshop! Well, I resized the glowmap down to 256x512, but honestly, it could be even less as no detail is actually needed for the glow ingame, it all looks blurry either way. Something similiar is the case with enviromental maps also. Well, off to the shader file writing.

 

(4.2) Glow map shader file template

Again, I will give you a concept which you can use, or rather, which you will remember down to every last symbol after 20-30 shader files written. It's the easiest way for you to learn, actually. I'm one of those learn-by-doing-it guys.

Spoiler

 

 

 

models/weapons2/saber_reborn/sabern
{
q3map_onlyvertexlighting
{
map models/weapons2/saber_reborn/sabern
rgbGen lightningDiffuse
}
{
map models/weapons2/saber_reborn/sabern_g
blendFunc GL_ONE GL_ONE
glow
detail
}
}

 

 

 

Explanation:

 

 

models/weapons2/saber_reborn/sabern Again it's the path which declares the texture that you want to apply the shader to.

{

q3map_onlyvertexlighting Again, you may leave this part or delete it.

{

map models/weapons2/saber_reborn/sabern This part inside these two brackets that I colored red ALWAYS needs to be first in any shader! I call it base texture declaration

rgbGen lightningDiffuse

}

{

map models/weapons2/saber_reborn/sabern_g We declare the path to the glow map which would be the texture, but it's also the name for the part colored blue inbetween both brackets.

blendFunc GL_ONE GL_ONE This blending draws anything but black. But there's another effect, the darker the colors on the map are, all the more transparent the map is drawn ingame.

glow It's the line that makes the parts on the glow map actually shine.

detail Again, this line also isn't obligatory, but if you add it to at least ONE map, then you DO have to add it to EACH map after the first one, which is the base texture declaration!

}

}

 

Well if we combine both the specmap and the glowmap, we first write the base texture declaration (the one with rgbGen lightningDiffuse), then the speculation map and then the glow map. Mind how I added "detail" to only the last two maps? That's what I warned you about up above.

 

 

models/weapons2/saber_reborn/sabern
{
q3map_onlyvertexlighting
{
map models/weapons2/saber_reborn/sabern
rgbGen lightingDiffuse
}
{
map models/weapons2/saber_reborn/sabern_spec
blendFunc GL_SRC_ALPHA GL_ONE
detail
alphaGen lightingSpecular
}
{
map models/weapons2/saber_reborn/sabern_g
blendFunc GL_ONE GL_ONE
glow
detail
}
}

 

 

(5.) Enviromental map

(5.1) To draw or to get it?

Yes, the enviromental map is best a screenshot of a level without the hud or even real enviroment pictures are fine, downsized to 256x256 or 512x512 if you really want detail for some reason. Or for chromatic saber, I would make a small new file, 256x256 size. With the standard colors black and white chosen, I would go to Filters/Render/Clouds, after that Filter/Filter Galery (located almost at the top inside the filters tab) and add a chrome filter, which you can find on the Filter Galery window inside the sketch tab on the right. For simple metals, I'd make different shades of black, white, gray and everything inbetween them, but keeping straight lines. Or maybe a gradient blending with 50 shades of gray. Hah biggrin.png I'll just post my finished enviroment maps I use mostly, you're free to download and use them any way you like.

 

env.jpg

 

env2.jpg

 

env3.jpg

 

env4.jpg

 

(5.2) Enviromental map shader file template

 

Well by now we already know the procedure, here's the template:

 

 

models/weapons2/saber_reborn/sabern
{
q3map_onlyvertexlighting
{
map models/weapons2/saber_reborn/sabern
rgbGen lightingDiffuse
}
{
map models/weapons2/saber_reborn/env
blendFunc GL_DST_COLOR GL_SRC_COLOR
detail
tcGen environment
}
}

 

 

The important things you schould mind in this template are only the blendFunc and tcGen lines. GL_DST_COLOR GL_SRC_COLOR enables this special transparent look, which covers the whole texture, but leaves out the darkest and the lightest parts. tcGen enviroment commands the map to move around on the saber according to your movements. This enables the illusion of a reflection.

 

(6.) Map combination and IMPORTANT FACTS!

Well, if I wanted to combine all those kinds of maps that I've taught you today, the shader file would look like this:

 

 

models/weapons2/saber_reborn/sabern
{
q3map_onlyvertexlighting
{
map models/weapons2/saber_reborn/sabern
rgbGen lightingDiffuse
}
{
map models/weapons2/saber_reborn/sabern_spec
blendFunc GL_SRC_ALPHA GL_ONE
detail
alphaGen lightingSpecular
}
{
map models/weapons2/saber_reborn/sabern_g
blendFunc GL_ONE GL_ONE
glow
detail
}
{
map models/weapons2/saber_reborn/env
blendFunc GL_DST_COLOR GL_SRC_COLOR
detail
tcGen environment
}
}

 

 

 

Look ingame:

shot0029.jpg

 

And that's how I've made my old saber a whole lot better!

 

Always mind that the maps are drawn ingame in the same order as you write them. With that said, it's better if you keep the specular map always the second one and the glow map the last one (if you have them both, else you don't need to mind the other, you can have a shader with only a glow map and a specular map, it'll look OK if that's what you want).

 

Okay sheesh, a lot of writting and working behind the computer is now behind me. Now there's a couple more things you need to always be aware of:

- the names of your shader files can be ANYTHING YOU WANT, as long as you don't forget the .shader ending and put it inside the "shaders" map in the root of your pk3 file.

- mind the correct order for the shader maps!

- if you put detail in at least one map after the base one, you have to put it inside each one, like I did!

- if you want to make a part of the model transparent, you have to model the inside and the "covering glass" of some kind also, give it a texture with white borders, a bit of gaussian blur and a few straight diagonal lines to make the effect of glass. Then use the glow template without the "glow" line in it and the model will be transparent.

 

For any further questions, feel free to message me or ask down bellow!

 

That's all, I hope my tutorial will help you learn something new, I also wish you luck modding and bid you farewell!

 

 

 


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