Making a Sky Shader


(shazmax) #1

Since we’ve been on this topic for a bit about Skyboxes, Sky-portals…Found a decent tutorial that gives a basic overview on creating a Sky Shader. The Sky Shaders are the ones that you’ll see the clouds passing overhead or a bolt of lighting flashing. Here’s the information off the site along with the link to follow and download the files. I tested them and they work fine, even in wolf.

Offsite link -
http://planetquake.com/qworkshop3/tutorials/starfield/index.html

Example download link -
http://planetquake.com/qworkshop3/tutorials/starfield/starfield-shader.zip

The Beginning
First of all, i’ve put a new directory in the textures folder named starfield and created three simple, well quite poor, but hey they took me like 10 minutes to make :o) starlike looking jpg files.
Next creating a new shader script called starfield.shader and adding this to the shaderlist.txt file.

The start of the shader code looks like this :

textures/starfield/starfield-3p
{
qer_editorimage textures/starfield/starfield-00a.tga
surfaceparm nodlights
surfaceparm noimpact

The name of the texture is starfield-3p and it lives in the textures > starfield directory.
The image we will all see in Radient is starfield-00a.tga.
A surface parameter of nodlights implies this shader will not be affected by dynamic lighting.
A surface parameter of noimpact implies that no projectiles will strike the surface, etc.

Somewhere in the Middle
Now comes the scrolling bit :

{	
		map textures/starfield/starfield-00a.tga
		//      tcmod scroll <sSpeed><tSpeed>
		tcmod scroll 1 0
}

Here we are using the starfield-00a.tga texture.
The tcmod scroll function allows us to scroll out texture around. In this instance right by 1 texture a second.

Almost the End
Thats the basic’s done. Simple eh ?
We can now add as many planes as God will allow, by copying the middle shader stage and adding an add function, just like this :

{
		map textures/starfield/starfield-01a.tga
		//      tcmod scroll <sSpeed><tSpeed>
		tcmod scroll 0.75 0
		blendfunc add
}

First you will notice that we’re using a different texture, this time starfield-01a.tga, cos it would get boring with the same texture.
And also the tcmod scroll speed has been reduced to 0.75.
Not forgetting the blendfunc add, this is responsible for combining all of our starfield images. Because the blendfunc add ‘adds’ the images together, stars passing over each other will appear brighter than they actually are. This gives quite a neat effect in my opinion.

The Final Script
Looks like this for a starfield with 3 planes. I don’t think it’s necessary for more planes, but you can add more it u like.

//
// Moving Starfields by crashmeplease.
// crashmeplease@yahoo.co.uk
//

// This shader came from the Starfield Shader Tutorial from:
// Q-workshop3
// http://qw3.gamedesign.net
//

// A three pass starfield example
//
textures/starfield/starfield-3p
{
qer_editorimage textures/starfield/starfield-00a.tga
surfaceparm nodlights
surfaceparm noimpact
// first pass
{
map textures/starfield/starfield-00a.tga
// tcmod scroll <sSpeed><tSpeed>
tcmod scroll 1 0

}	
// second pass
{
	map textures/starfield/starfield-01a.tga
	//      tcmod scroll &lt;sSpeed&gt;&lt;tSpeed&gt;
	tcmod scroll 0.75 0
	blendfunc add
}	
// third pass
{
	map textures/starfield/starfield-02a.tga
	//      tcmod scroll &lt;sSpeed&gt;&lt;tSpeed&gt;
	tcmod scroll 0.5 0
	blendfunc add
}	

}

Thats all there is to it. You can see that the first pass is the fastest, and the third pass the slowest. Why not play with the scrolling speeds yourself.
One other thing if your feeling brave is to add a little motion blur effect by stretching the texture out a little


(shazmax) #2

BTW - I noticed that this shader didn’t include a depthwrite in it and I’ve heard that you need it in there. This shader still works but I haven’t added the depthwrite in there to verify if there’s was a difference in adding the depthwrite.

Was just curious what the effects of having a depthwrite - or not one…what is it…why is it there. Why does this work without one?

From previous forum - http://www.splashdamage.com/index.php?name=pnPHPbb2&file=viewtopic&t=7685
This shader adds an extra, transparent layer of clouds. It does this by using an additive (GL_ONE GL_ONE) blend. Note that if more than one stage is used the first map must have a depthWrite attribute.


(shazmax) #3

From the Quake 3 shader arena manual - http://www.qeradiant.com/manual/Q3AShader_Manual/ch05/pg5_1.htm#depthwrite

By default, writes to the depth buffer when depthFunc passes will happen for opaque surfaces and not for translucent surfaces. Blended surfaces can have the depth writes forced with this function.

What the heck does that mean? Is this talking about the images themselves and their qualities or how it will alter the qualities of the given images into blends and such?