3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: Help with Ocean Shader  (Read 237 times)

« on: March 13, 2014, 06:44:37 PM »
Hey guys,

I've been trying to implement an ocean in my project using Shadmar's ocean shader (http://www.3drad.com/forum/index.php?topic=4108.msg34885#msg34885).

I was wondering whether, and if so, how I could make the movement of a ship correspond to the movement of the waves in that shader.

Also, how do I add coloured fog to that shader? I'm not that great with shaders, and though I've had a look through the shader script and found several references to 'fog', I can't seem to find a way to achieve what I want.

Thanks for any help you guys can provide,

George.
« Reply #1 on: March 13, 2014, 09:25:21 PM »
easiest method would be to compute a sin wave formula and add the offset to the .y location vector...

Code: [Select]
Vector3        loc;
int            wave;
float          yOffset;

void Main()
{
   iObjectLocation(OBJ_0,loc);
   yOffset=iFloatSin(wave)/10;
   loc.y+=yOffset;
   iObjectLocationSet(OBJ_0,loc);
   wave++;
}

it won't sync up exactly with the height of the wave at any given point in time, but it will look realistic enough to simulate the up down motion of the boat... 

getting the exact height  of  a part of a mesh (the wave mesh) would be quite a task in 3DRAD, and really not worth the effort involved...  the technique above is what i use in the following video...

http://www.youtube.com/watch?v=t-YEiEAYyeU

you can also apply a variation of this an apply it to the orientation  to make the boat pitch and roll...


as for the fog, i'll have to take a ook at the code...


--Mike
« Reply #2 on: March 14, 2014, 02:59:09 AM »
Thanks Mike,

I've already managed to implement more or less what you've suggested. It works pretty well most of the time, but the small size of  the ship in my project means I have to have a relatively flat ocean.

I really would like to implement some rough, wavy seas in my project. I figured that since Shadmar's ocean shader already manipulates the 3d position of vertices in a skinmesh, there may be a way of using that data to calculate buoy water heights.

Also, thanks a bunch for looking at the fog thing. I really should try and learn more about HLSL scripting...
« Reply #3 on: March 14, 2014, 09:41:38 AM »
for the fog... have you found and tried adjusting the following lines (119-121)...

Code: [Select]
float4 fogColor = {1.0f,1.0f,1.0f,1.0f};
float fogStart = 0.0f;
float fogEnd = 1.0f;

as for following the wave height... correlating the ships' location with the ocean mesh location seems to be the challenge here... and that's just for the center of the ship... if you want the ship the ship to pitch with the waves, you'll need to find a vector off the nose of the ship, get the wave height there, calculate the angle, then pitch the ship down the difference...

--Mike
« Reply #4 on: March 14, 2014, 06:04:07 PM »
I've already found those lines and adjusted the 'fogColour' values (as well as the start/end distance values, for good measure). Alas, it doesn't seem to change anything in my project.  :(

I'm guessing that there's something else in the script that I've missed/don't understand. These are all the references I could find to 'fog' in the shader script. Hopefully there's something important in there.

line 329:   
Code: [Select]
float FogIntensity : TEXCOORD8;
line 450:
Code: [Select]
OUT.FogIntensity = saturate((fogStart - (OUT.Pos.z))/(fogStart - fogEnd*pow(shore,2)));
line 529:    
Code: [Select]
half4 transColor = ((1-IN.FogIntensity)*RefractAmount*TransmissionRefraction
line 535: 
Code: [Select]
float4 replaceColor = pow(IN.ShoreIntensity,0.75f)*5*IN.FogIntensity*float4
line 544:   
Code: [Select]
//color.w=pow(IN.FogIntensity,20)+0.5;
I don't know how to find the location of a vertex in a mesh which is closest to a certain point. Is there a particular scriptfunction/tutorial would be useful in this regard?

On a more positive note, I've made some changes to my sailing game. I've removed the day/night transition, which has sped things up considerably. Hopefully you'll be able to try it out after these graphical issues are sorted and I post an update.

As always, thanks for your help Mike. It's very much appreciated
« Reply #5 on: March 14, 2014, 06:56:10 PM »
sorry i couldn't have been of more help... i've managed to mod (with instructions from Gene) one of his other shaders, but this is one of the shaders i never used...

--Mike

« Reply #6 on: March 14, 2014, 07:31:48 PM »
No worries Mike. I'm sure I'll figure something out
« Reply #7 on: March 18, 2014, 02:13:28 PM »
Looks like I'm still having trouble with adding fog. But since this shader looks pretty good, even without it, I might just leave it for the time being and focus on other aspects of my project. It's still an improvement over any other water I've had in my project to date:


I think the same goes for the waves...

My goal right now is to put together a basic demo, with one or two puzzles, and possibly a menu system with a save/load function (should be easy with iFileWrite commands, since there's not much data to save)
« Reply #8 on: March 18, 2014, 02:59:45 PM »
lookin' good G...

in the meantime, i'll see if Shad's got a free second to point to where to make the fog mods to the shader...

--Mike

« Last Edit: March 18, 2014, 03:55:57 PM by Mike Hense »
Pages: [1]