Released! - HLSL Water Code

Posted By: Steempipe

Released! - HLSL Water Code - 11/09/04 09:22

Since it is release time, new thread... This is the HLSL version.

/******************************************************
Water Shader for 3DGameStudio

By: Eric Hendrickson-Lambert (Steempipe)

v11.08.04.1

11/08/04: Cleaned up code for release.

Note: Pixelshader1.1 & DX9.00c Runtimes needed.

It will take experimenting with
scaling, shifting, etc~ depending on
what normalmap is used. The ripple
code is still in very early stages.

-See the main WDL for loading the material effect
and the d3d_shaderversion function.

If used, credit would be nice... these take alot
of time to work out. Thanks.

******************************************************/

Later on, the DX8 / A6.22.0 version will be released. Just gotta
make it friendly.

The d3d_shaderversion will check if your card supports better than pixelshader 1.1... if not, the Engine says "Bye". It is very rude.



Steempipe-WaterShader.zip Approx 3.21 MB
Posted By: Iglarion

Re: Released! - HLSL Water Code - 11/09/04 09:51

Very NICE!
Posted By: Soulzero

Re: Released! - HLSL Water Code - 11/09/04 10:27

Sweet !
Posted By: dleuen

Re: Released! - HLSL Water Code - 11/09/04 12:06

Very nice Eric. Thanks! I know you've put many many hours into this stuff.

Don
Posted By: lekboon

Re: Released! - HLSL Water Code - 11/09/04 12:53

nice steempipe!great work!
thanks!!
Posted By: Josh_Arldt

Re: Released! - HLSL Water Code - 11/09/04 13:50

It looks really nice.
Thanks Steempipe!!!
Posted By: William

Re: Released! - HLSL Water Code - 11/09/04 14:02

*stunned* That looks awsome! Much better than the last one you release, very good job Steempipe. Would this effect possible in FFP as well? Thanks for releasing it and all the work you put into it. Just love that wavy effect.
Posted By: Drew

Re: Released! - HLSL Water Code - 11/09/04 15:29

THANK YOU!! trying it soon..
Posted By: 20BN

Re: Released! - HLSL Water Code - 11/09/04 16:10

Steempipe, thank you! thank you very much!
It's a great code!
Posted By: Zio

Re: Released! - HLSL Water Code - 11/09/04 16:52

What's this? Water on my GeForce3? No wait.. Beautiful water on my GeForce3?! Impossible!

Awesome job Steempipe!
Posted By: Elfi

Re: Released! - HLSL Water Code - 11/09/04 17:10


Posted By: TimeOut

Re: Released! - HLSL Water Code - 11/09/04 18:34

Very good work.
Looks excellent !
Posted By: Steempipe

Re: Released! - HLSL Water Code - 11/09/04 18:58

Glad you're all liking it! Just like Xmas, eh? J/K.
Posted By: RobH

Re: Released! - HLSL Water Code - 11/09/04 19:17

It is Eastern and Xmas together, great work Steempipe!
Posted By: xker2001

Re: Released! - HLSL Water Code - 11/09/04 19:40

Looks GREAT!You are very nice Steempipe,thank you very much~~
Posted By: Alkai

Re: Released! - HLSL Water Code - 11/09/04 22:24

Awesome man!
Posted By: Ahriman

Re: Released! - HLSL Water Code - 11/10/04 00:02

Just like Xmas Looks great Eric Thank you!
Posted By: William

Re: Released! - HLSL Water Code - 11/10/04 11:15

I was wondering - how do I change the ambient(or brightness) of the cube map thats applied to the water? Thanks.
Posted By: Steempipe

Re: Released! - HLSL Water Code - 11/10/04 18:29

William: There are a number of things you can play with. Here are a few ideas.

1). You can add code to lerp with another texture.

2). Alter the pixelshaderconstant like: PixelShaderConstant[0] = {0.60,0.60,0.60,0.50}; x,y,z being RGB. w being transparancy.

3). You could pass info thru diffuse by adding:

float4 vecDiffuse // Add vector to effect ""

PixelShaderConstant[0] = <vecDiffuse>; // Change in Technique Pass

mul r0, t3, c0 // No change in pixelshader fragment

my.Alpha = 60; // Add the amount of trans to your Action

In the material {}; // Make your RGB adjustments
diffuse_blue = 200;
diffuse_green = 200;
diffuse_red = 200;
Posted By: Anonymous

Re: Released! - HLSL Water Code - 11/11/04 04:47

Looks very nice! Does the HLSL Water code requires Professional edition? It looked likt it has a mirror effect to a water. Neat.
Posted By: Steempipe

Re: Released! - HLSL Water Code - 11/11/04 05:16

Pro not needed. It is looking up into a cubemap texture based on a non-constant eye-ray vector.

This example is a static environment mapping, the code could lend itself to specular reflection as well.
Posted By: angel1

Re: Released! - HLSL Water Code - 11/11/04 19:34

Very good work.
Only a question what happened with the nice ripples from the water demo you released (without code)?
Posted By: Steempipe

Re: Released! - HLSL Water Code - 11/11/04 21:07

The ripples are scaled larger in the code release, by the RippleScale var. That's all.
Posted By: TimeOut

Re: Released! - HLSL Water Code - 11/12/04 23:30

What must I change in the code when I add it to my template 6 main Skript ?
Posted By: Thomas_Nitschke

Re: Released! - HLSL Water Code - 11/14/04 20:39

You released it! GREAT!
This is really some kind of christmas for me! And it works on my good old geforce 4
Thanks very much this is a great contribution!
Only one question coming to my mind: Which value did you set for the ripple scale var in the first demo you released and which ripple test did you use there (1,2 or 3) ?
I know it is the same code, but the settings from your demo look even better then those you set here!
Posted By: Steempipe

Re: Released! - HLSL Water Code - 11/14/04 22:14

Thanks!

Try: RippleScale = 0.18;

and use this:
/////////////////////////////////////////////////////////////////////////////
// Ripple Test #1
//
Out.Bump= (IN.Bump.xy * RippleScale) + (IN.Bump.xy += (vecSkill41.x * 0.02));
/////////////////////////////////////////////////////////////////////////////

That might get you in the ballpark.
Posted By: Thomas_Nitschke

Re: Released! - HLSL Water Code - 11/15/04 02:49

Thanks that's exactly what I was after, getting nice results using this!
Posted By: Thomas_Nitschke

Re: Released! - HLSL Water Code - 11/19/04 02:11

Oh well, another question popping up out of nowhere
Where can I adjust the water's flow speed and direction?
Posted By: Steempipe

Re: Released! - HLSL Water Code - 11/19/04 06:13

Try replacing your Out.Bump with this and see what you can do:

Code:
 
///////////////////////////////////////////////////////////////////////////////
float2 WaveDir;
float SpeedComp = {0.02}; // Adjust depending on the
// RippleScale setting

WaveDir.x = IN.Bump.x * RippleScale;
WaveDir.x -= (vecSkill41.x * SpeedComp); // Direction of U (either + or -)

WaveDir.y = IN.Bump.y * RippleScale;
//WaveDir.y += (vecSkill41.x * SpeedComp); // Direction of V (either + or -)

Out.Bump = WaveDir.xy;
///////////////////////////////////////////////////////////////////////////////


Posted By: Thomas_Nitschke

Re: Released! - HLSL Water Code - 11/19/04 20:45

Thanks for your fast help... unfortunately this seems to produce some errors
As usual, a picture saying more than thousand words:

Any idea what could cause this?

Edit:
Hmm I don't know what has caused this... Anyway I got it working now, seems as if it was a rippleScale-issue somehow.
Looks nice now
Posted By: Elitegunner

Bugreport - 12/04/04 06:18

Sorry but:


GeForce FX 5700 Forceware 66.93
A6 Commercial 6.31.4

I give up
Posted By: Steempipe

Re: Bugreport - 12/04/04 06:52

Don't give up..... whats is the code and the textures you're using??

Did the posted demo run for you??
Posted By: Macom

Re: Bugreport - 12/05/04 03:18

I have the same strange bahaviour than MasterChief. The demo runs fine. When i use the shader in my project i get the error : Malfunction W1550, Error in effect: water_fx. I use the cube and the water hmp from the demo. Whats wrong ?
Posted By: Josh_Arldt

Re: Bugreport - 12/05/04 03:31

Make sure that you have the .fx in the right folder. The .fx files don't automatically get published with your project BTW.
Posted By: Macom

Re: Bugreport - 12/05/04 03:51

Thx! That was the reason. I put the .fx in the project main directory and it works. Perhabst .fx-files can not be loaded from sub-directories.
Posted By: Thomas_Nitschke

Re: Bugreport - 12/09/04 01:26

Oh, they can indeed, but you may have forgotten to add the necessary path in your WDL
Anyway, this was a lttile bit offtopic, sorry guys
Posted By: Matt_Aufderheide

To SteemPipe - 12/15/04 15:15

SteemPipe:
would you be able to able to convert the pixel shader to HLSL? that way it would be much easier to add improvements.. such a fresnel term..etc
Posted By: Steempipe

Re: To SteemPipe - 12/15/04 18:02

I hope to... started to and then got side tracked. That needs to be done, though.
Posted By: Matt_Aufderheide

Re: To SteemPipe - 12/15/04 19:08

cool.. i have already put in a cheap pseudo fresnel effect.. but with HLSL would be much easier to tweak..
Posted By: MASTERJUNOJET

Re: To SteemPipe - 12/20/04 11:47

I guess im outta luck

Unless any of you know how to make it work on an

nVidia GeForce FX 5600 256MB v66.93 drivers (Direct X 9c)

The water just shows up black, any thoughts?
Posted By: Red Ocktober

Re: To SteemPipe - 12/21/04 04:40

i've got one of those GeForce 5200s in one of my machines too... an el cheapo eVGA brand... but the demo seems to works fine here. ..

dx9c, latest drivers (i think... does 66.93 sound right) WinXP

--Mike
Posted By: Steempipe

Re: To SteemPipe - 12/21/04 07:54

Quote:

I guess im outta luck

Unless any of you know how to make it work on an

nVidia GeForce FX 5600 256MB v66.93 drivers (Direct X 9c)

The water just shows up black, any thoughts?




Did my published demo run okay for you?? If it did, then there is something that needs to be looked at in your implementation.
The drivers I used for the testing are the ones in my sig below.
Posted By: Rhuarc

Re: To SteemPipe - 12/23/04 13:43

Just curious if I'm the only one that gets a pixelated rendering (look at bottom of image)... I've messed with all the mag/min/mip filtering options and haven't been able to fix it, so I'm stuck here.

Posted By: MASTERJUNOJET

Re: To SteemPipe - 12/23/04 17:22

Quote:

Quote:

I guess im outta luck

Unless any of you know how to make it work on an

nVidia GeForce FX 5600 256MB v66.93 drivers (Direct X 9c)

The water just shows up black, any thoughts?




Did my published demo run okay for you?? If it did, then there is something that needs to be looked at in your implementation.
The drivers I used for the testing are the ones in my sig below.





No the demo is the one that had the black water, so i only assume it would turn out that way in my projects too, i used to have 61.77, but then I upgraded to 66.93, how could that make it any worse? Not to mention I think I had the same problems with the old drivers too.
Posted By: Ranger1

Re: To SteemPipe - 12/23/04 20:09

@Rhuarc,

Nope you're not the only one I get the same 'effect' also

I have a radeon 9200
Posted By: Steempipe

Re: To SteemPipe - 12/23/04 21:23

I have not ran into that since the days of screwing with texbeml instructions. No time right now to reproduce it, but I would focus on the normalmap and it's scaling and not so much the filtering. Maybe email me the WDL and the texture and I can fiddle with it. Eric.
Posted By: Matt_Aufderheide

Re: To SteemPipe - 12/23/04 22:54

yes it looks as though the normal map is scaled much too big.. there is a point that you lose color uniformity in very high-scaled textures, and filtering cant hide it so you get these pixelation artifacts..
Posted By: Rhuarc

Re: To SteemPipe - 12/23/04 23:25

Well, it does the same thing to me in the demo of it too, so it must be too big there. I'll give scaling the texture down a shot. Thanks.

-Rhuarc
Posted By: JvsJGameDesign

Re: To SteemPipe - 01/02/05 05:44

To bad it doesn't work on my videocard...
(NVidia GeForce 4 MX 440)

Shot:

Posted By: old_bill

Water Shader: Exchange the cube_map - 01/04/05 08:11

Hello Steempipe,
thanks for this great shader!

But is there any solution to use it also in a closed room with no visible skycube?
I tried to replace the "water_cube" bmap with one which is generated by this script:
http://www.conitecserver.com/wiki/index.php/RenderCubeScript
but the engine crashed with no error using the script.

Is there any other way to capture the cube_map from the water position?

old_bill
Posted By: Red Ocktober

Re: Water Shader: Exchange the cube_map - 01/04/05 09:02

hey bill... the shader seems to work inside a closed cube for me...

i added a hollow cube and set the player inside... i even commented out the skycube block in the script and the shader still worked.

--Mike
Posted By: old_bill

Re: Water Shader: Exchange the cube_map - 01/04/05 09:16

Hi Mike,
when i remove the skin2 part, the model is completly invisible and sometimes green,
depending on my view.angle .
From my understanding, that's correct, because there is now no bmap to use as mirrored bmap.
What i want is a function, that captures a bmap from the model position and use it as cube_map for the water.

But what was displayed on your level in case you removed the water_cube skin?

old_bill
Posted By: Red Ocktober

Re: Water Shader: Exchange the cube_map - 01/04/05 09:36

i think that that is just what is happening... the shader is using montskysma+6.tga (the statement bmap water_cube=<montskysma+6.tga>;


and then the material is using water_cube as skin1 and the bumpmap texture as skin 2...

don't remove anything from the material code... just comment out the skycube block of code that starts with sky skycube{ ...}

(be right back gotta run to the train station )


--Mike
Posted By: Steempipe

Re: Water Shader: Exchange the cube_map - 01/04/05 09:55

I just now did a copy and paste of the wiki code you referenced (the improved version) and it rendered the cubemap from my camera position when I pressed "c".

I did get an engine crash before I put a blank "render.tga" image in the project directory. Mine was a blank texture, 256x256.
Posted By: Robin

Re: Water Shader: Exchange the cube_map - 01/04/05 14:45

Does water reflect only skycubes? Can it refelect geomatrical enviorment?
Cause, all I see in the examples is that only skycube are reflected.
Posted By: Matt_Aufderheide

Re: Water Shader: Exchange the cube_map - 01/04/05 15:57

in this shader it only relfects the skycube.. however if you own pro you can use render to texture to make it reflect everything.
Posted By: Leon

Re: Water Shader: Exchange the cube_map - 01/04/05 17:49

the exe works fine..
when i use the code in my work folder i got a problem

"parameter unknown d3d_shaderversion"

i'm using 6.30 commercial

ps: the watershader.fx is already included!

??????????????????
Posted By: RobH

Re: Water Shader: Exchange the cube_map - 01/04/05 20:38

Only the Com and Pro Editions have shader support.
Also you should update to version 6.31.4 to have the newest version.
Posted By: Robin

Re: Water Shader: Exchange the cube_map - 01/05/05 00:21

Well I do own the Pro verstion but I don't really know HLSL language to change what I need.
Anyone got a complete version of it?
Posted By: old_bill

Re: Water Shader: Exchange the cube_map - 01/05/05 04:26

Hey,
thanks for the hint Steempipe, that did the trick also for me!

old_bill
Posted By: Steempipe

Re: Water Shader: Exchange the cube_map - 01/05/05 05:22

Quote:

the exe works fine..
when i use the code in my work folder i got a problem

"parameter unknown d3d_shaderversion"

i'm using 6.30 commercial

ps: the watershader.fx is already included!

??????????????????




Update to 6.31+, or remove the IF block in the function load_water_fx in water.wdl and simply have:

effect_load(water_fx,"watershader.fx");
wait(5);
Posted By: Red Ocktober

Re: Water Shader: Exchange the cube_map - 01/05/05 06:35

old bill... i copied the watershader code from the demo (water.wdl) and didn't get any of the problems above...


also...

did you get the watershader working inside an enclosed room yet, without the skycube?

--Mike
Posted By: old_bill

Re: Water Shader: Exchange the cube_map - 01/05/05 06:47

Yes, now the code from ventilator works.
I used it to create a CubeMap from the position of my water (inside a room) and replaced the
sky cube map with the one from the script, and now i have a "real" environment reflection!

old_bill
Posted By: Red Ocktober

Re: Water Shader: Exchange the cube_map - 01/05/05 06:58

great...

hey, i was also playing with it a lil...

the code went in so easily that even i could mod it for custom use... i wound up shading a matrix (.hmp) and applying some undulating water code... and amazingly it worked

click here to see (modem user right click and save target as 662KB)---> Moving Water Using Steem's Shader

verrrrry verrrrry nice resource Steem... THANKS

--Mike
Posted By: Steempipe

Re: Water Shader: Exchange the cube_map - 01/05/05 07:07

Looks good! And; you're welcome.

Glad that the effect is getting tinkered with and expanded upon. There is soooooo much that needs to be done to that code. My wishlist is.... well, just a wishlist at the moment.
Posted By: old_bill

Re: Water Shader: Exchange the cube_map - 01/05/05 07:13

Very nice example of moving water!

I'm currently working on a code which allows to have multiple watersurfaces with a environment cubemap
without having trouble with the cubemap handling...
Will post if succed!

old_bill
Posted By: William

Re: Water Shader: Exchange the cube_map - 01/05/05 16:01

That looks great red! Would you be willing to share the code?
Posted By: Robin

Re: Water Shader: Exchange the cube_map - 01/05/05 22:00

nice m8.
Can you post the code about reflecting hmp?
Posted By: Red Ocktober

Re: Water Shader: Exchange the cube_map - 01/05/05 23:22

... sure guys, after all... i'd be nowhere whithout the generous code sharing of so many others here who are really making the advanced capabilities of the engine accessible.

the code is based on the 'Realistic Water' article from the AUM compilation (AUM 34)...

ok... here it is... for better or worse (sorry for the mixed styles and messy commenting)

basically, all i did was merge the moving water code and Steempipe's water shader code and watershader.fx

you are going to need to make a simple terrain as outlined in the AUM34 Realistic Water article... and you should have Steempipe's demo for the shader file and environment bitmaps... the code simply assigns the material to whatever entity calls the WaterShader action, so assing this action to your water terrain.

also, i am using the version 6 templates, so if you are using the older templates, just pick and choose what you need.



Code:
 



path "C:\\Program Files\\GStudio\\template_6"; // Path to A6 templates directory
path "C:\\Program Files\\GStudio\\template_6\\code"; // Path to A6 template code subdirectory
path "C:\\Program Files\\GStudio\\template_6\\images"; // Path to A6 template image subdirectory
path "C:\\Program Files\\GStudio\\template_6\\sounds"; // Path to A6 template sound subdirectory
path "C:\\Program Files\\GStudio\\template_6\\models"; // Path to A6 template model subdirectory
path "C:\\program files\\gstudio\\work\\text_src";
path "C:\\program files\\gstudio\\work";
path "C:\\program files\\virtuqal sailor\boats\ohio";


include <gid01.wdl>; // global ids
include <display00.wdl>; // basic display settings
include <plSelect.wdl>;
include <cameraTarget.wdl>;
include <miscInput01.wdl>;
include <plBipedInput01.wdl>;
include <bipedPhy01.wdl>;
include <bipedAnim01.wdl>;
include <bipedSnd01.wdl>;
include <plBiped01.wdl>;
include <cameraSelect.wdl>;
include <camera1stPerson01.wdl>;
include <shader_light.wdl>;



bind <watershader.fx>;


string level_str=<movingwatershader.wmb>; // **** THIS IS THE NAME OF THE LEVEL


var video_mode=7;
var video_depth=32;
var video_screen=1;


var index;
var counter;
define amplitude skill1;
define water_speed skill25;
define number_of_vertices 1089;
var vertex_array [1089];

var d3d_automaterial=1;




function init_detail_mapping(){
bmap_to_mipmap(mtl.skin1);
d3d_automaterial=1;
}


sky skycube {
type = <montskya+6.tga>;
flags = cube,visible,overlay;
layer = 1;
}



bmap water_cube=<montskysma+6.tga>;
bmap water_bump=<waterbump5.tga>;


function mtl_water_init()
{

bmap_to_cubemap(bmap_to_mipmap(mtl.skin2));
bmap_to_mipmap(mtl.Skin1);

}

/////////////////////////////////////////////////////////////////////////////////
// The material definition used in the watershader
//
material wave1 {

skin1=water_bump;
skin2=water_cube;

flags=tangent;

event = mtl_water_init;

}



var ShaderCount;

//////////////////////////////////////////////////////////////////////////////////
// The action to assign to the water terrain, basically it is the wave code with
// the material used in the shader assigned to the water terrain
//
Action WaterShader
{
my.material = wave1; /// **** THIS MAKES THE TERRAIN USE STEEMPIPE'S
/// WATER SHADER CODE, THAT'S ALL THERE WAS TO IT

my.scale_x=40; /// **** RESIZE THE WATER TERRRAIN MATRIX IF YOU DESIRE
my.scale_y=40;

my.transparent=on; /// **** SEE THRU IT OR NOT WHATEVER
my.nofog = on; /// **** FOG SEEMS TO WORK WITH THIS SHADER IF U WANT IT... COOL


// **** SETTING UP FOR THE WAVES

if (my.amplitude == 0)
{
my.amplitude = 2.84; // default wave amplitude value
}
if (my.water_speed == 0)
{
my.water_speed =7.4; // default wave speed value
}
while (counter < number_of_vertices)
{
vertex_array[counter] = random(360); // set random values in vertex_array
counter += 1;
}


while(1) // **** MAKE WAVES ALL THE TIME
{
my.skill41=float(ShaderCount);
my.skill42=float(0);
my.skill43=float(0);
my.skill44=float(0);

ShaderCount += 0.00287; // ******* AFFECT SPEED OF WAVE MOVEMENT HERE



index = 0;

my.u += .25*time;
my.v += .25*time;
wait (1);



while (index < number_of_vertices)
{
vec_for_mesh(temp, my, index); // store the vertex coordinates in temp
temp.z = sin(counter + vertex_array[index]) * my.amplitude; // change the z component
vec_to_mesh(temp, my, index); // deform the terrain entity
index += 1;
}
counter += my.water_speed * time;
//wait(1);



wait(1);}


}


//////////////////////////////////////////////////////////////////////////////////////
// **** Load the effect file if pixelshader version
// is better then 1.1.
// If not, then exit the Engine.

function load_water_fx() {

if (d3d_shaderversion >= 1111)
{
effect_load(wave1,"watershader.fx");
wait(5);
return;
}
else
{
wait(5);
exit;
}

}


/////////////////////////////////////////////////////////////////
// Desc: The main() function is started at game start
function main()
{
// set some common flags and variables
// freeze all entity functions
freeze_mode = 1;
// no level has been loaded yet...
gid01_level_state = gid01_level_not_loaded;

// entry: Warning Level (0,1, or 2)
// entry_help: Sets sensitivity to warnings (0 = none, 1 = some, 2 = all).
warn_level = 2; // announce bad texture sizes and bad wdl code


// entry: Starting Mouse Mode (0, 1, or 2)
mouse_mode = 0;

// wait 3 frames (for triple buffering) until it is flipped to the foreground
wait(3);

// now load the level
level_load(level_str); // **** LOADS THE LEVEL YOU SET ABOVE


wait(2); // let level load
// level should be loaded at this point...
gid01_level_state = gid01_level_loaded;

load_water_fx(); // **** CALLS THE FUNCTION THAT LOADS THE WATER SHADER


wait(5);




//
// **** MAIN GAME LOOP
while(1)
{
if(gid01_level_state != gid01_level_loaded)
{
// pause the game
freeze_mode = 1;
}
else
{
// un-freeze the game
freeze_mode = 0;
}
wait(1);
}
}


// Desc: this is the function used to restart the game.
function main_restart_game()
{
// wait 3 frames (for triple buffering) until it is flipped to the foreground
wait(3);

// now load the level
level_load(level_str);
// freeze the game
freeze_mode = 1;

load_water_fx();
// fog_color = 1; // use the first fog color
// d3d_fogcolor1.red = 133; // your values here
// d3d_fogcolor1.green =175; // your values here
// d3d_fogcolor1.blue = 255; // your values here
// camera.fog_start = 100; // your values here
// camera.fog_end = 1500; // your values here

wait(2); // 1-level loads, 2-entities load

//+++ load starting values

// un-freeze the game
freeze_mode = 0;
}


// Desc: this is the function used to quit the game.
function main_quit()
{
//+++ // save global skills & strings
exit;
}

/////////////////////////////////////////////////////////////////
// The following definitions are for the pro edition window composer
// to define the start and exit window of the application.
WINDOW WINSTART
{
TITLE "3D GameStudio";
SIZE 480,320;
MODE IMAGE; //STANDARD;
BG_COLOR RGB(240,240,240);
FRAME FTYP1,0,0,480,320;
// BUTTON BUTTON_START,SYS_DEFAULT,"Start",400,288,72,24;
BUTTON BUTTON_QUIT,SYS_DEFAULT,"Abort",400,288,72,24;
TEXT_STDOUT "Arial",RGB(0,0,0),10,10,460,280;
}

/* no exit window at all..
WINDOW WINEND
{
TITLE "Finished";
SIZE 540,320;
MODE STANDARD;
BG_COLOR RGB(0,0,0);
TEXT_STDOUT "",RGB(255,40,40),10,20,520,270;

SET FONT "",RGB(0,255,255);
TEXT "Any key to exit",10,270;
}*/


/////////////////////////////////////////////////////////////////
//INCLUDE <debug.wdl>;








--Mike
Posted By: Robin

Re: Water Shader: Exchange the cube_map - 01/06/05 03:42

Thanks a lot!
Posted By: William

Re: Water Shader: Exchange the cube_map - 01/06/05 15:42

Thanks!
Posted By: Matt_Aufderheide

Re: Water Shader: Exchange the cube_map - 01/14/05 16:29

Hey... Steempipe did you ever convert the pixel shader to HLSL? i have tried but i dont really get the theory here.. I know you have to use a higher PS version, at probably 1.4 or 2.0 becuase 1.1 doesnt support dependent reads..
Posted By: muralist

. - 01/17/05 03:58

.
Posted By: muralist

HLSL Water Code and Day-Night transitions - 01/19/05 08:04

The water looks terrific. Is there any way to change the water's cubemap so it changes along with this day night script? I have a level with nice dawn, noon, dusk, and midnight cubemaps, with the following script. I would like to tie it to the water so the whole environment changes over time.



var ticks_u_minuti = .16; // 1 min ingame time = 1 sec = 16 ticks

var minuta = 0; // starting game minutes

var sat = 17; // starting game hour

var dan = 1; // starting game day

var mjesec = 1; // starting game month

var godina = 1000; // starting game year

var dan_u_tjednu = 1; // starting day of the week

var brojac = 0;

var vrijeme1 = 0;



font standard_font = <ackfont.pcx>, 6, 9; // uncomment this if you're not using the templates



// months in a year

string 1_mjesec = "January";

string 2_mjesec = "February";

string 3_mjesec = "March";

string 4_mjesec = "April";

string 5_mjesec = "May";

string 6_mjesec = "June";

string 7_mjesec = "July";

string 8_mjesec = "August";

string 9_mjesec = "September";

string 10_mjesec = "October";

string 11_mjesec = "November";

string 12_mjesec = "December";



// days in a week

string 1_dan = "Monday";

string 2_dan = "Tuesday";

string 3_dan = "Wednesday";

string 4_dan = "Thursday";

string 5_dan = "Friday";

string 6_dan = "Saturday";

string 7_dan = "Sunday";



// temp strings

string temp_sat_str[8];

string temp_min_str[2];

string temp_dan_str;

string temp_mjesec_str;

string temp_godina_str;

string temp_day_nmb;

string day_title[2];





// string array for months

text MjesecUGodini

{

strings = 12;

string = 1_mjesec, 2_mjesec, 3_mjesec, 4_mjesec, 5_mjesec, 6_mjesec, 7_mjesec, 8_mjesec, 9_mjesec, 10_mjesec, 11_mjesec, 12_mjesec;

}



//string array for days

text DanUTjednu

{

strings = 7;

string = 1_dan,2_dan,3_dan,4_dan,5_dan,6_dan,7_dan;

}



// display date text object

text PrikaziDatum

{

pos_x = 20;

pos_y = 40;

font = standard_font;

strings = 1;

string = temp_dan_str;

}



// display clock text object

text PrikaziSat

{

pos_x = 20;

pos_y = 80;

font = standard_font;

strings = 1;

string = temp_sat_str;

}



// put this function in Main() if you want the Time Manager only

function init_time()

{

pass_time();

get_datetime();

PrikaziSat.visible = on;

PrikaziDatum.visible = on;

}



// this is time calculation function

function pass_time()

{

while(1)

{

// wait for the given number of ticks (16 ticks = 1 second)

waitt(ticks_u_minuti);

// then increase minute counter by 1

minuta += 1;

IF (minuta > 59)

{ // if one hour has passed

minuta = 0;

sat += 1;

}

if (sat > 23)

{ // ome day has passed

sat = 0;

dan += 1;

dan_u_tjednu += 1;

}

if (dan_u_tjednu > 7)

{ // we check the day of the week, if the number is bigger than 7 then it's Monday again

dan_u_tjednu = 1;

}

// we check what month it is

if ((mjesec == 1) || (mjesec == 3) || (mjesec == 5) || (mjesec == 7) || (mjesec == 8) || (mjesec == 10) || (mjesec == 12))

{

brojac = 31;

}

if ((mjesec == 4) || (mjesec == 6) || (mjesec == 9) || (mjesec == 11))

{

brojac = 30;

}

// if it's February

if (mjesec == 2)

{

brojac = 28;

}

if (dan > brojac)

{ // one month has passed

dan = 1;

mjesec += 1;

}

if (mjesec > 12)

{ // one year has passed

godina += 1;

mjesec = 1;

}

// date check

if (dan == 1)

{

str_cpy(day_title, "st");

}

if (dan == 2)

{

str_cpy(day_title, "nd");

}

if (dan == 3)

{

str_cpy(day_title, "rd");

}

if (dan >= 4)

{

str_cpy(day_title, "th");

}

}

}



// this function creates the apropriate panels for time/date panels

function get_datetime()

{

while(1)

{

// date panel

str_cpy(temp_dan_str, DanUTjednu.string[dan - 1]);

str_cpy(temp_mjesec_str, MjesecUGodini.string[mjesec - 1]);

str_for_num(temp_godina_str,godina);

str_for_num(temp_day_nmb,dan);

str_cat(temp_dan_str, " ");

str_cat(temp_dan_str, temp_day_nmb);

str_cat(temp_dan_str, day_title);

str_cat(temp_dan_str, ", ");

str_cat(temp_dan_str, temp_mjesec_str);

str_cat(temp_dan_str, ", ");

str_cat(temp_dan_str, temp_godina_str);

str_cat(temp_dan_str, " NR");

// clock panel

str_for_num(temp_sat_str, sat);

str_cat(temp_sat_str, " : ");

str_for_num(temp_min_str,minuta);

str_cat(temp_sat_str, temp_min_str);

wait(1);

}

}



//////////////////////////////////////////////////////////////////////////////////////////

// Day/Night change


sky jutro // this is the noon skycube
{
type = <Sky_MexicaNoon+6.tga>;
flags = cube,visible;
layer = 1;
flags = cube, visible, transparent;
alpha = 100;
layer = 2;
}

sky sumrak // this is the sunset skycube
{
type = <Sky_MexicaSunset+6.tga>;
flags = cube,visible;
layer = 1;
flags = cube, visible, transparent;
alpha = 100;
layer = 2;
}

sky noc // night skycube
{
type = <Sky_MexicaMidnight+6.tga>;
flags = cube,visible;
layer = 1;
flags = cube, visible, transparent;
alpha = 100;
layer = 2;
}

sky podne // morning skycube
{
type = <Sky_MexicaDawn+6.tga>;
flags = cube,visible;
layer = 1;
flags = cube, visible, transparent;
alpha = 100;
layer = 2;
}

// state vars

var dan_ili_noc = 1; // 0 - Night, 1 - Noon, 3 - Sunset, 4 - Morning, 0.5 - transition



// noon to sunset transition function

function podne_u_sumrak(duration)

{

var trans;

if(dan_ili_noc != 1) { return(-1); }

sumrak.visible = on;

if(duration > 0)

{

dan_ili_noc = 0.5;

trans = duration;

while(trans > 0)

{

jutro.alpha = 100*(trans/duration);

trans -= time;

wait(1);

}

dan_ili_noc = 3;

}

jutro.alpha = 0;

jutro.visible = off;

}



// sunset to night transition function

function sumrak_u_noc(duration)

{

var trans;

if(dan_ili_noc != 3) { return(-1); }

noc.visible = on;

if(duration > 0)

{

dan_ili_noc = 0.5;

trans = duration;

while(trans > 0)

{

sumrak.alpha = 100*(trans/duration);

trans -= time;

wait(1);

}

dan_ili_noc = 0;

}

sumrak.alpha = 0;

sumrak.visible = off;

}



//night to morning transition function

function noc_u_zoru(duration)

{

var trans;

if(dan_ili_noc != 0) { return(-1); }

podne.visible = on;

if(duration > 0)

{

dan_ili_noc = 0.5;

trans = duration;

while(trans > 0)

{

noc.alpha = 100*(trans/duration);

trans -= time;

wait(1);

}

dan_ili_noc = 4;

}

noc.alpha = 0;

noc.visible = off;

}



// morning to noon transition function

function zora_u_podne(duration)

{

var trans;

if(dan_ili_noc != 4) { return(-1); }

jutro.visible = on; //

if(duration > 0)

{

dan_ili_noc = 0.5; // transition flag

trans = 0;

while(trans < duration)

{

jutro.alpha = 100 * (trans/duration);

trans += time;

wait(1);

}

dan_ili_noc = 1; //

}

jutro.alpha = 100;

podne.visible = off;

}



// state changing function, put this into the Main() function if you want the Day/Night Manager only

function change_sky()

{

while(1)

{

if (sat == 5) // if it's 6 AM then change the sky from night to morning

{

noc_u_zoru(128 * ticks_u_minuti); // change the number 16 to a higher number if you want a longer transition

}

if (sat == 11) // if it's 12 PM then change the sky from morning to noon

{

zora_u_podne(128 * ticks_u_minuti);

}

if (sat == 17) // if it's 6 PM then change the sky from noon to sunset

{

podne_u_sumrak(128 * ticks_u_minuti);

}

if (sat == 19) // if it's 8 PM then change the sky from sunset to night

{

sumrak_u_noc(128 * ticks_u_minuti);

}

wait(1);

}

}


// put this function in your main() function if you want both features

function daytime_manager()

{

init_time();

change_sky();

}
Posted By: muralist

Waves! - 01/19/05 08:21

I still want to make the environment map cycle through day and night but have to say thanks for the waves code -- got it to work on the first try and its very nice. Thanks!!
Posted By: Red Ocktober

Re: Waves! - 01/20/05 08:00

my pleasure... and hey, if you get that real time day night thing working... give a hooler, would ya

that would really be a nice effect...

i am looking at some ideas along this line of thought as well... seeing as this is using static bmps i'm not sure as which way to proceed initially, but modifying the color to coincide with the 'ambient' color might be the solution...

... unless there is a way to change the bmp that is being used in the cubemapping on the fly. to be honest, i don't know enough about 3DGS and cscripting to do that just yet.

gimme a lil time though...

--Mike
Posted By: Matt_Aufderheide

Re: Waves! - 01/20/05 10:25

You can just use a differnt cubemap depending on what "time" it is.. this is easy enough. Make a function with a while loop like so:

function change_cubemap()
{
while(1)
{

if (timeofday==noon)
{
if (mat_water.skin1<>noon_cube)
{
mat_water.skin1=noon_cube;
}
}

//and so on
wait(10);
}

}
Posted By: XNASorcerer

Re: Water Shader: Exchange the cube_map - 01/23/05 18:54

Quote:

in this shader it only relfects the skycube.. however if you own pro you can use render to texture to make it reflect everything.




How can I do that? Can you give me a code example?
Thank you.
Posted By: XNASorcerer

Re: Water Shader: Exchange the cube_map - 01/23/05 19:00

Quote:

Yes, now the code from ventilator works.
I used it to create a CubeMap from the position of my water (inside a room) and replaced the
sky cube map with the one from the script, and now i have a "real" environment reflection!





old_bill,

Can you should me how to do that? Thanks
Posted By: inFusion

Re: Released! - HLSL Water Code - 01/24/05 05:52

Can I somehow tile the normal-map to make the waves smaller to use this code for a huge ocean?
Posted By: XNASorcerer

Re: Released! - HLSL Water Code - 01/24/05 19:39

Steempipe, how can I make the shader to showa terrain also, like you did in your demo?
Posted By: old_bill

Re: Water Shader: Exchange the cube_map - 01/25/05 02:14

Quote:

Quote:

Yes, now the code from ventilator works.
I used it to create a CubeMap from the position of my water (inside a room) and replaced the
sky cube map with the one from the script, and now i have a "real" environment reflection!





old_bill,

Can you should me how to do that? Thanks




Yes, its quiet simple:

Copy this script into your wdl file:

Code:
 var_nsave fh;
bmap* canvas;
bmap* b_render1;
bmap* b_render2;
bmap* b_render3;
bmap* b_render4;
bmap* b_render5;
bmap* b_render6;
var cubenumber = 0;
var directions[18] = 180, 0, 0, 90, 0, 0, 0, 0, 0, -90, 0, 0, 90, -90, 0, 90, 90, 0;
string tempstring1;
string tempstring2;
string _ts_;

//----------------------------------------------------------------------------- write_cubemap
function write8(byte) // write char
{
file_asc_write(fh, byte);
}

function write16(short) // write unsigned short
{
file_asc_write(fh, short&255);
file_asc_write(fh, (short>>8)&255);
}

function str_padding(str, number, padding)
{
str_for_num(_ts_, number);
var i = 0;
i = padding - str_len(_ts_);
while(i > 0)
{
str_cat(str, "0");
i-=1;
}
str_cat(str, _ts_);
}

function write_cubemap()
{
var i;
var xx;
var yy;
var format;
var pixel;
var pixelalpha;
var canvas_size[2];

canvas_size.x = bmap_width(b_render1);
canvas_size.y = bmap_height(b_render1);
format = bmap_lock(b_render1, 0);
bmap_lock(b_render2, 0);
bmap_lock(b_render3, 0);
bmap_lock(b_render4, 0);
bmap_lock(b_render5, 0);
bmap_lock(b_render6, 0);

str_cpy(tempstring1, "cubemap");
str_padding(tempstring1, cubenumber, 4);
str_cat(tempstring1, "+6.tga");
fh = file_open_write(tempstring1);
cubenumber+=1;
//--------------------------------------------------------write header
write8(0);
write8(0);
write8(2); // image type
write16(0);
write16(0);
write8(0);
write16(0);
write16(0);
write16(canvas_size.x * 6); // width
write16(canvas_size.y); // height
write8(24); // color depth
write8(0);
//--------------------------------------------------------write image data
yy = canvas_size.y - 1;
while(yy >= 0)
{
i = 0;
while(i < 6)
{
if(i==0){canvas=b_render1;}
if(i==1){canvas=b_render2;}
if(i==2){canvas=b_render3;}
if(i==3){canvas=b_render4;}
if(i==4){canvas=b_render5;}
if(i==5){canvas=b_render6;}
xx = 0;
while(xx < canvas_size.x)
{
pixel = pixel_for_bmap(canvas, xx, yy);
pixel_to_vec(temp, pixelalpha, format, pixel);
write8(temp.x); // b
write8(temp.y); // g
write8(temp.z); // r
xx+=1;
}
i+=1;
}
yy-=1;
}
file_close(fh);
bmap_unlock(b_render1);
bmap_unlock(b_render2);
bmap_unlock(b_render3);
bmap_unlock(b_render4);
bmap_unlock(b_render5);
bmap_unlock(b_render6);
}

//----------------------------------------------------------------------------- capture_cubemap
function capture_cubemap
{
var old_arc;
var old_x;
var old_y;
var old_screen;

b_render1 = bmap_create("render.tga"); // use a 256x256 tga for example -> determines cube map size
b_render2 = bmap_create("render.tga");
b_render3 = bmap_create("render.tga");
b_render4 = bmap_create("render.tga");
b_render5 = bmap_create("render.tga");
b_render6 = bmap_create("render.tga");

old_arc = camera.arc;
old_x = screen_size.x;
old_y = screen_size.y;
old_screen = video_screen;

camera.arc = 90;
video_set(256, 256, 32, 2); // should be same resolution as render.tga

freeze_mode = on;
vec_set(camera.pan, directions[0]); wait(1); bmap_for_screen(b_render1,1,0);
vec_set(camera.pan, directions[3]); wait(1); bmap_for_screen(b_render2,1,0);
vec_set(camera.pan, directions[6]); wait(1); bmap_for_screen(b_render3,1,0);
vec_set(camera.pan, directions[9]); wait(1); bmap_for_screen(b_render4,1,0);
vec_set(camera.pan, directions[12]); wait(1); bmap_for_screen(b_render5,1,0);
vec_set(camera.pan, directions[15]); wait(1); bmap_for_screen(b_render6,1,0);
freeze_mode = off;

wait(1);
write_cubemap();

wait(1);
camera.arc = old_arc;
video_set(old_x, old_y, 32, old_screen);
}

on_h=capture_cubemap;


Make sure that an empty tga file named "render" is in your save folder.

Then go to the position where the water is and move with the cam to the ground and look to the sky (tilt 90°).
Press h and the screen will become black for some seconds.
Close the engine and search for "cubemap0000+6.tga" in your save folder.

Assign this file to the water shader as "water_cube".
It looks nice, but remember it will not display the player and it only works for small planes.
Realtime reflection would require the pro edition.

But try it!

old_bill
Posted By: XNASorcerer

Re: Water Shader: Exchange the cube_map - 01/25/05 05:48

Quote:

Realtime reflection would require the pro edition




Thank you for answering so fast.
I have the Pro version. How can I do that with the shader?
Posted By: Matt_Aufderheide

Re: Water Shader: Exchange the cube_map - 01/25/05 06:16

To do real reflections with a shader and render targets, i dont recommend using cubic environment mapping. You are better off rendering the scene to a texture with a user clipping plane at the water surface. Then map this texture projectively on to the water, and you should have real reflections.. this method works better because you only need one render-to-texture, not 6.
Posted By: Alexander Esslinger

Re: Water Shader: Exchange the cube_map - 01/25/05 06:35

...though there are no user-defined clipping planes in GameStudio

Well, we have the mirrows, but they clip levelgeometry only, which prevents entitys to walk in the water...
Posted By: XNASorcerer

Re: Water Shader: Exchange the cube_map - 01/25/05 06:51

Thanks, but I don't make any idea of how to use render-to-texture. Can you haelp me with that?
Posted By: inFusion

Re: Water Shader: Exchange the cube_map - 01/26/05 05:18

Please don't overgo my question:
Can I somehow tile the normal-map to make the waves much smaller to use this code for a huge ocean?
Posted By: Steempipe

Re: Water Shader: Exchange the cube_map - 01/26/05 05:29

Maybe you can monkey with code like this for scaling the texture. Browse way back in this thread and there may be some more info.

Code:

//////////////////////////////////////////////
float2 WaveDir;
float SpeedComp = {0.02}; // Adjust depending on the
// RippleScale setting

WaveDir.x = IN.Bump.x * RippleScale;
WaveDir.x -= (vecSkill41.x * SpeedComp); // Direction of U (either + or -)

WaveDir.y = IN.Bump.y * RippleScale;
//WaveDir.y += (vecSkill41.x * SpeedComp); // Direction of V (either + or -)

Out.Bump = WaveDir.xy;
////////////////////////////////////////////


Posted By: Matt_Aufderheide

Re: Water Shader: Exchange the cube_map - 01/26/05 11:26

Quote:

...though there are no user-defined clipping planes in GameStudio

Well, we have the mirrows, but they clip levelgeometry only, which prevents entitys to walk in the water...




Yes but couldnt it somehow be done in the vetex shader? I believe i've seen such code before..There is a brute force way to do it in any case, just use two different terrains, one with the top half of the map, one with the parts under water, then when you render the reflection view make the water and the lower terain invisible.

The best thing of course would be to have a user clip plane implemented by JCL..
Posted By: Steempipe

Re: Water Shader: Exchange the cube_map - 01/27/05 10:39

Quote:

Hey... Steempipe did you ever convert the pixel shader to HLSL? i have tried but i dont really get the theory here.. I know you have to use a higher PS version, at probably 1.4 or 2.0 becuase 1.1 doesnt support dependent reads..




It's pretty close...... However, I'm Side-tracked into terrain FX.
Posted By: beegee

Re: Water Shader: Exchange the cube_map - 01/27/05 21:19

hi,

in which version can I use shaders? Or can that every version?

---------------------------------
my hp is http://3dgs.funpic.de
Posted By: Pappenheimer

Re: Water Shader: Exchange the cube_map - 01/28/05 05:25

Look here:

infopage of 3DGS

Commercial and professional version of A6 only!
Posted By: William

Re: Water Shader: Exchange the cube_map - 01/30/05 16:25

I'm having the problems that both Rhuarc and Ranger1 had with this shader on a Radeon 9200. I've recently tried this demo on a computer with a Radeon 9200 and recieve similar pixelation that there is in the picture Rhuarc posted. It works fine on my Radeon 9800 at home... Do you have any idea why its doing this Steempipe?
Posted By: XNASorcerer

Re: Released! - HLSL Water Code - 05/19/05 01:41

Steempipe, why is that your shader reflect sprites as grey color?
Posted By: Josh_Arldt

Re: Released! - HLSL Water Code - 05/19/05 02:01

Is there a way to get rid of this pixelated effect on ATI Radeon 9200's?
It looks absolutely terrible on my 9200.

Also would it be possile to change this to work on level blocks?
I'd like to have a fallback technique to where if this shader isn't supported by the users card it just displays the water level blocks turbulence texture.
Posted By: Steempipe

Re: Released! - HLSL Water Code - 05/19/05 08:00

Quote:

Steempipe, why is that your shader reflect sprites as grey color?




I can look into it if you'd make a small example and PM/Email me a link to it.

JBA: Is the 9200 problem present with the demo, or happening if different textures are used?? I'll try to look into it a bit if I have some time.
Posted By: XNASorcerer

Re: Released! - HLSL Water Code - 05/19/05 14:18

Quote:


I can look into it if you'd make a small example and PM/Email me a link to it.




I don't have where to put the example, but I could send it to you by email. Is that ok?
Also, if I use the shader, sometimes the chassis of the car and some panels disappers. Do you have any idea why?

See this pic:


Edited: The invisible chassis char depends of where I put the car in the level. If I move it a lilte, the chassis appears.
Posted By: Ahriman

Re: Released! - HLSL Water Code - 06/27/05 23:20

Steempipe I hope you are around cause I am down to 3 days and I am hoping you can help me. I got this code working looks great for water, but I really need to get some controlable transparency. I tried using the alpha channel of the bumpmap which does work by adding mov r0.w, t0.w in the asm for the pixel shader.

Problem with this is that the bump map is moving which makes the alpha map move as well so the transparency doesn't stay in place. So my question is how can I get this to work staying within VS and PS 1.1.
Posted By: nightshade

Re: Released! - HLSL Water Code - 06/30/05 14:08

I just changed Out.Bump = (float2(IN.Bump.x+cos_x, IN.Bump.y+sin_y)* RippleScale)*0.2;
to
Out.Bump = (float2(IN.Bump.x+cos_x, IN.Bump.y+sin_y)* RippleScale)*2.2;
.
Now I have more ripples, but what should I change, that the water moves slower (its very fast;D).
Thanks, Reaver.
Posted By: Ahriman

Re: Released! - HLSL Water Code - 06/30/05 20:20

my.skill41 = float(ShaderCount);
my.skill42 = float(0);
my.skill43 = float(0);
my.skill44 = float(0);
ShaderCount += 0.001;

changing this in the action for the water will adjust the speed that the uv coordinates are being shifted
Posted By: nightshade

Re: Water Shader: Exchange the cube_map - 07/01/05 10:18

Quote:

Quote:

Quote:

Yes, now the code from ventilator works.
I used it to create a CubeMap from the position of my water (inside a room) and replaced the
sky cube map with the one from the script, and now i have a "real" environment reflection!





old_bill,

Can you should me how to do that? Thanks




Yes, its quiet simple:

Copy this script into your wdl file:

Code:
 var_nsave fh;
bmap* canvas;
bmap* b_render1;
bmap* b_render2;
bmap* b_render3;
bmap* b_render4;
bmap* b_render5;
bmap* b_render6;
var cubenumber = 0;
var directions[18] = 180, 0, 0, 90, 0, 0, 0, 0, 0, -90, 0, 0, 90, -90, 0, 90, 90, 0;
string tempstring1;
string tempstring2;
string _ts_;

//----------------------------------------------------------------------------- write_cubemap
function write8(byte) // write char
{
file_asc_write(fh, byte);
}

function write16(short) // write unsigned short
{
file_asc_write(fh, short&255);
file_asc_write(fh, (short>>8)&255);
}

function str_padding(str, number, padding)
{
str_for_num(_ts_, number);
var i = 0;
i = padding - str_len(_ts_);
while(i > 0)
{
str_cat(str, "0");
i-=1;
}
str_cat(str, _ts_);
}

function write_cubemap()
{
var i;
var xx;
var yy;
var format;
var pixel;
var pixelalpha;
var canvas_size[2];

canvas_size.x = bmap_width(b_render1);
canvas_size.y = bmap_height(b_render1);
format = bmap_lock(b_render1, 0);
bmap_lock(b_render2, 0);
bmap_lock(b_render3, 0);
bmap_lock(b_render4, 0);
bmap_lock(b_render5, 0);
bmap_lock(b_render6, 0);

str_cpy(tempstring1, "cubemap");
str_padding(tempstring1, cubenumber, 4);
str_cat(tempstring1, "+6.tga");
fh = file_open_write(tempstring1);
cubenumber+=1;
//--------------------------------------------------------write header
write8(0);
write8(0);
write8(2); // image type
write16(0);
write16(0);
write8(0);
write16(0);
write16(0);
write16(canvas_size.x * 6); // width
write16(canvas_size.y); // height
write8(24); // color depth
write8(0);
//--------------------------------------------------------write image data
yy = canvas_size.y - 1;
while(yy >= 0)
{
i = 0;
while(i < 6)
{
if(i==0){canvas=b_render1;}
if(i==1){canvas=b_render2;}
if(i==2){canvas=b_render3;}
if(i==3){canvas=b_render4;}
if(i==4){canvas=b_render5;}
if(i==5){canvas=b_render6;}
xx = 0;
while(xx < canvas_size.x)
{
pixel = pixel_for_bmap(canvas, xx, yy);
pixel_to_vec(temp, pixelalpha, format, pixel);
write8(temp.x); // b
write8(temp.y); // g
write8(temp.z); // r
xx+=1;
}
i+=1;
}
yy-=1;
}
file_close(fh);
bmap_unlock(b_render1);
bmap_unlock(b_render2);
bmap_unlock(b_render3);
bmap_unlock(b_render4);
bmap_unlock(b_render5);
bmap_unlock(b_render6);
}

//----------------------------------------------------------------------------- capture_cubemap
function capture_cubemap
{
var old_arc;
var old_x;
var old_y;
var old_screen;

b_render1 = bmap_create("render.tga"); // use a 256x256 tga for example -> determines cube map size
b_render2 = bmap_create("render.tga");
b_render3 = bmap_create("render.tga");
b_render4 = bmap_create("render.tga");
b_render5 = bmap_create("render.tga");
b_render6 = bmap_create("render.tga");

old_arc = camera.arc;
old_x = screen_size.x;
old_y = screen_size.y;
old_screen = video_screen;

camera.arc = 90;
video_set(256, 256, 32, 2); // should be same resolution as render.tga

freeze_mode = on;
vec_set(camera.pan, directions[0]); wait(1); bmap_for_screen(b_render1,1,0);
vec_set(camera.pan, directions[3]); wait(1); bmap_for_screen(b_render2,1,0);
vec_set(camera.pan, directions[6]); wait(1); bmap_for_screen(b_render3,1,0);
vec_set(camera.pan, directions[9]); wait(1); bmap_for_screen(b_render4,1,0);
vec_set(camera.pan, directions[12]); wait(1); bmap_for_screen(b_render5,1,0);
vec_set(camera.pan, directions[15]); wait(1); bmap_for_screen(b_render6,1,0);
freeze_mode = off;

wait(1);
write_cubemap();

wait(1);
camera.arc = old_arc;
video_set(old_x, old_y, 32, old_screen);
}

on_h=capture_cubemap;


Make sure that an empty tga file named "render" is in your save folder.

Then go to the position where the water is and move with the cam to the ground and look to the sky (tilt 90°).
Press h and the screen will become black for some seconds.
Close the engine and search for "cubemap0000+6.tga" in your save folder.

Assign this file to the water shader as "water_cube".
It looks nice, but remember it will not display the player and it only works for small planes.
Realtime reflection would require the pro edition.

But try it!

old_bill




Hallo, bei mir erstellt es so ne cube map fast perfekt, nur sind da solche kleinen Streifchen noch drinn, siehe hier :



Und was ich komisch finde, ist, dass wennn ich "H" drücke, nach ner weile possible endless loop in capture_cubemap. Kann ja sein das es an dem liegt, kannst mir helfen bitte? Danke

(Sorry ich weiss, ist offthread)

EDIT : achja, das blaue bitte ignorieren, hab "H" gedrückt, wo Bildschirm blau war, aber die Streifen kommen auch so;).

Posted By: AndrewSwallow

Re: Released! - HLSL Water Code - 07/01/05 19:18

hmm, wierd here, i pressed F7 then ran to the edge, got stuck, jumped to the centre of the water then i went underneath by END and flew by HOME

also it starts swimming wuite a way higher than the water

andrewds

Posted By: nightshade

Re: Released! - HLSL Water Code - 07/02/05 08:07

in english : As I pressed "H", with old_bills shader he maked a cubemap, but it maked 2 small strifes (sorry I dont know, that I chosed the right word).






Posted By: nightshade

Re: Released! - HLSL Water Code - 07/08/05 11:46

No help?
© 2024 lite-C Forums