Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

alkisbkn

Member Since 21 Feb 2008
Offline Last Active Oct 31 2012 10:00 AM

Posts I've Made

In Topic: Normal of sine

12 August 2012 - 06:32 AM

haegarr,

thank you for your help! I had 2 mistakes in my current code (the points from 2 - 5, I had corrected them before):
I was calculating the normal as:
normal = normalize(float3(derivativeX, 1, derivativeZ));
where it should have been with minus sign, as you said in your post.

The second mistake, was the scaling of the final accumulated height. I didn't expect it to have such a big impact!

So, thank you for your help, here is a screenshot of how the water looks now Posted Image

In Topic: Normal of sine

11 August 2012 - 03:44 PM

Which still doesn't look correct :S

In Topic: Normal of sine

11 August 2012 - 06:16 AM

Thanks everyone, I think it is working correctly now. Below I am showing how I am doing it:
float height = 50.0 * sin(fs * waveVertex.x + t * _Time.y) +
		  125.0 * sin(fs * waveVertex.z + t * _Time.y + PI/4.0) +
		  135.0 * sin(-fs * waveVertex.x/4.0 - t * _Time.y * 0.75 + PI/2.0) +
		  165.0 * sin(-fs * waveVertex.z/8.0 - t * _Time.y * 0.5 + PI);
height *= 0.25;

float derivative = 150.0 * fs * cos(fs * waveVertex.x + t * _Time.y) +
		 125.0 * fs * cos(fs * waveVertex.z + t * _Time.y + PI/4.0) +
		 135.0 * -fs * cos(-fs * waveVertex.x/4.0 + t * _Time.y * 0.75 + PI/2.0) +
		 165.0 * -fs * cos(-fs * waveVertex.z/8.0 + t * _Time.y * 0.5 + PI);


float3 tan1 = float3(1.0, derivative, 0.0);
float3 bitan1 = float3(0.0, derivative, 1.0);

normal = normalize(cross(bitan1, tan1));
And this gives me the result as you see in the screenshot.

In Topic: Normal of sine

10 August 2012 - 06:23 PM

Okay, it seems that the correct derivative of "wave1" equation is the following:
float3 tan1 = float3(1.0, 30.0 * fs * cos(fs * waveVertex.x + t), 0.0);
float3 bitan1 = float3(0.0, 30.0 * fs * cos(fs * waveVertex.x + t), 1.0);
for tan and bitan. Then I do
normal = normalize(cross(bitan1, tan1));
For 1 wave it seems to be correct, however how should I go about adding many wave's normals together? Just summing them and normalizing the result?

In Topic: Normal of sine

10 August 2012 - 01:22 PM

This appears to be tricky afterall. Shouldn't the vertex and direction z be affecting the tan1 as well?

Edit:
I changed the wave function to something more simple for now, I basically removed the power to 2.
So, the derivative of:

float wave1 = 30.0f * sin(fs * dir_vertex + t);

should now be:
float tan1y = cos(fs * dir.x * wave_vertex.x)
float bitan1y = cos(fs * dir.y * wave_vertex.z);
(is t in the derivative equation? I think not, as it's constant)

However this too doesn't give me a correct result.

PARTNERS