Skip to main content
gamedev.net
🔒 Locked

Ocean Effect

Started by treeway Apr 30, 2006 at 11:58 AM 1 replies 600+ views
Original Post
treeway
treeway
Hi Im trying to downsample the Ocean effect from RenderMonkeys Reflections example so i can use it on VS_1_1 / PS_1_1 hardware. The vertex shader works fine so does most of the pixel shader (just by changing some of the commands such as normalize to devide a vector by itself). but then i get to the Pow function (on the last line). I know it raises a number in the left to the power of the right hand perameter - which isnt intrinsic in PS_1_1, so normally speeking a for loop wold work: for(float i = 0; i < power; i++) { number *= number; } however PS_1_1 doesnt like looping to a variable and has a warning (loop does not exit in a timely manner). So i was wondering if anyone has succeeded in converting this effect to a lower level. Or if anyone has seen an ocean quad effect of a similar standard that i could use instead. thanks
clb
clb
I think the best way to approximate pow on lower level HLSL is to create a 1D texture and lookup the values. It has downsides tho, for example you need to limit to specific value range and it's not that perfect with precision.

(edit) Oh, and I don't think your custom pow functions correctly. You're multiplying with the result from the previous iteration... You should have
float base = x;float number = 1.f;for(float i = 0; i < power; i++)   number *= base;// or alternatively (very lousy approximation for powers of 2)for(float i = 0; i < log2(power); i++)   number *= number;
S1CA
S1CA
I agree with clb, a look up texture is the best way to go IMO.

If the power is fixed, you can just unroll the loop to the desired number of multiplies. However with the limited ~8bit precision on ps1.1 hardware, this can soon lead to banding artifacts.

This same issue also comes up for per-pixel specular illumination on ps1.1 hardware. Dan Baker's Meltdown 2001 slides give details: http://www.microsoft.com/corpevents/gdc2001/slides/Per_Pixel_Lighting.ppt#341,29,Specular Effects


NB: For ps1.x targets, personally I'd lean towards re-writing the code in asm, particularly when the shader gets complex - there just aren't enough instruction slots for the HLSL compiler to do a good job on those lower targets. i.e. start with HLSL, see what the compiler produces, then re-write/re-factor. For ps2.x and above, I'm happy to use HLSL all the way.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.