First part: “vbomb.fx”

12 07 2007

At first download this shader from the NVIDIA Shader Library:
http://developer.download.nvidia.com/shaderlibrary/packages/vbomb.zip

This it what it looks like in NVIDIA FX Composer and how it should look, when we are done:
vbomb NVIDIA Image

Okay, lets start!!!

-Create a new folder for this project and extract the files out of the .zip file into it.
Delete the “CgFX”-folder because it only includes the same shader written in glsl wich is used for OpenGL. We don´t need it.

-Open WED, create a new empty level and save it into the new created projectfolder.

-Create a new folder called “Models” in your projectfolder, open MED, create a simple sphere model and save it into the

“Models” folder.

-Create a new folder called “Scripts”

-Load the just created sphere model into the empty level.

-In WED, go to file -> Map Properties, click at the “New Script” button and choose “Empty Script”. Now open the new created

scriptfile, wich has the same name as the level but with .wdl as filetype and wich is in your projectfolder.

-On top of that file, add the paths to the subfolders:

// Tutorial.wdl <—This is the name of my Scriptfile

path “Scripts”;
path “HLSL”;
path “Textures”;
path “Models”;

-Create a new scriptfile and save it with the name “Shader.wdl” into the “Scripts”-folder.

-Go back to the other Script and include the new created file there:

include <Shader.wdl>;

-Now add the main function to that script:

function main()
{

level_load(“levelname.wmb”); //<—Replace levelname with the name of your level
wait(3);

}

-On the bottom of that script, add this action for the cameramovement:

action free_camera
{

var camera_force[3];
my.invisible = on;
my.passable = on;camera_force.z = 0;
vec_set(camera.x,my.x);
vec_set(camera.pan,my.pan);

while(1)
{

camera_force.x = (key_w – key_s)*26*time_step;
camera_force.y = (key_a – key_d)*26*time_step;c_rotate(me,vector(-mouse_force.x*10*time_step,mouse_force.y*10*time_step,0),ignore_passable);
c_move(my,camera_force,nullvector,glide+ignore_passable+ignore_passents+ignore_push);

vec_set(camera.x,my.x);
vec_set(camera.pan,my.pan);

wait(1);

}

}

-Now load a second spheremodel into your level and place it a bit distanced to the first. Save ans reload the level,

rightclick it, click on “Behavior” and choose the action “free_camera”.

-Open the “Shader.wdl” and write the folloing lines into it:

///////////////////////////////////
/////////////Shader.wdl////////////
///////////////////////////////////

//////Textures///////
bmap vbomb_skin1_bmap = “FireGrade.bmp”;

//////Materials//////

material vbomb_mat
{

skin1 = vbomb_skin1_bmap;

flags = tangent;
effect = “vbomb.fx”;

}

///////Actions///////

action vbomb_act()
{

my.material = vbomb_mat;

}

-Save the file, save and reload the level in WED and assign the action “vbomb_act” to the first added spheremodel.

-Now open the vbomb.fx file wich is at the “HLSL”-folder and the “vnoise-table.fxh”, wich is at the “include”-folder inside of the “HLSL”-folder.

-Copy the whole content from the “vnoise-table.fxh” and past it into the “vbomb.fx” at the position of this line, wich has to be deleted:

#include <include\\vnoise-table.fxh>

-Clean the file through deleting this:

float Script : STANDARDSGLOBAL <

string UIWidget = “none”;
string ScriptClass = “object”;
string ScriptOrder = “standard”;
string ScriptOutput = “color”;
string Script = “Technique=Main;”;

> = 0.8;

and through shortening things like this:

float Displacement <

string UIWidget = “slider”;
float UIMin = 0.0;
float UIMax = 2.0;
float UIStep = 0.01;

> = 1.6f;

to this:

float Displacement = 1.6f;

at the bottom of the file, you´ll find this:

technique Main <

string Script = “Pass=p0;”;
> {
pass p0 <
string Script = “Draw=geometry;”;
> {

VertexShader = compile vs_2_0 mainVS();
ZEnable = true;
ZWriteEnable = true;
ZFunc = LessEqual;
CullMode = None;
PixelShader = compile ps_2_a hotPS();

}

}

you can shorten it to this:

technique Main
{

pass p0
{

VertexShader = compile vs_2_0 mainVS();
ZEnable = true;
ZWriteEnable = true;
ZFunc = LessEqual;
CullMode = None;
PixelShader = compile ps_2_a hotPS();

}

}

-In the middle of the file, you´ll find (after shortening) this:

texture GradeTex;

sampler2D GradeSampler = sampler_state
{

Texture = <GradeTex>;
MinFilter = Linear;
MipFilter = Point;
AddressU = Clamp;
AddressV = Clamp;

};

A6 and A7 passes the entities and the materialtextures to the shader.
The entitytextures are called entSkin1, entSkin2, …
and the materialskins are called mtlSkin1, mtlSkin2, …

If you have a look at the “Shader.wdl”, you can see, that we assign a texture to the material as material.skin1.
In our case we have to rename “GradeTex” to “mtlSkin1” :

texture mtlSkin1;

sampler2D GradeSampler = sampler_state
{

Texture = <mtlSkin1>;
MinFilter = Linear;
MipFilter = Point;
AddressU = Clamp;
AddressV = Clamp;

};

-Change this line:

float Timer : TIME;

to:

float4 vecTime;

and replace every use of “Timer” with “vecTime.w” using the replace function of SED (Ctrl+h).

Do the same with:

float4x4 WvpXf : WORLDVIEWPROJECTION;

wich has to be changed to:

float4x4 matWorldViewProj;

Replace every use of “WvpXf” with “matWorldViewProj”.

-If you now have a look at the pixelshader wich is the function called at the end of this line:

PixelShader = compile ps_2_a hotPS();

you´ll see, that it is very short and simple.
Change this:

PixelShader = compile ps_2_a hotPS();

to this:

PixelShader = compile ps_2_0 hotPS();

Now you only need a graphicscard with support for shadermodel 2.0 and not for 2.a wich is supported by much less graphicscards. But if you get an error message now, change it back.

-If you save this file and run the level, you´ll see, that the mesh is getting deformed but is rendered completly black.

-To fix a texture problem, you should look at the pixelshader at first:

float4 hotPS(vbombVertexData IN) : COLOR
{

float2 nuv = float2(IN.Color0.x,0.5);
float4 nc = tex2D(GradeSampler,nuv);
// return float4(IN.Color0.xxx,1.0);
return nc;

}

This line:

float4 hotPS(vbombVertexData IN) : COLOR

means that the output of the pixelshader, wich is set by return, is the color of the pixel (usually every Pixelshader should do so…).

now we should have a look at this line:

float4 nc = tex2D(GradeSampler,nuv);

tex2D sets the nc variable to the color of the pixel wich is at the position “nuv” of the texture given to “GradeSampler”.
Because we would get an error message, if there were a problem with the Texture, something with “nuv” should be wrong.

float2 nuv = float2(IN.Color0.x,0.5);

I just tried several values instead of the 0.5 wich gives the y-position on the texture. For my understanding, this shouldn´t

change anything but after I set it to 0 there was at least a first sign of colors on the texture.

-Now play around with the values of the global variables on top of the file under the “TWEAKEBLES”-Comment.

I think, that these values are looking similar to the original:

//////////////////////////////////////////////////////////////
// TWEAKABLES ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

float Displacement = 80.6f;
float Sharpness = 1.90f;
float ColorSharpness = 0.2f;
float Speed = 0.03f;
float TurbDensity = 2.27f;
float ColorRange = -0.6f;
float4x4 NoiseMatrix = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};

This is what I got in the end:
vbomb 3DGS Final

With a sphere with more faces and some more changes to the “TWEAKABLES” it should get very similar to the original.

I hope, that this short introduction helped you a bit to understand the convertionprocess.
I will try to create tutorial of a more complex convertation, wich is going to be based on this one. That means, that we´ll

also use the same files but an other shader.
After that, I hope to create a small listing with the keywords wich has to be changed to wich 3DGS keywords.
If that is done for NVIDIA shaders I´ll may create one for ATI as well…
But that are just my ideas on how I want to go on. I can´t promise that it will all happen, but I hope so 😛

Nils Daumann (Slin)

If you want to try yourself wih an other shader now, have a look at the NVIDIA Shader Library.


Actions

Information

Leave a Reply




%d