I have done Your first 3D Shader but failed at the your second 3D Shader tutorial because I don't know where to plug in those wave codes. (they don't show the final code).

Can anyone follow that tutorial and complete code for me so I can study them.

Thank you very much

You mean this?

void vertex() {
  vec2 pos = VERTEX.xz;
  float k = height(pos, TIME);
  VERTEX.y = k;
}

Maybe you were just scrolling right past it.

Forgot to mention I'm using GD4 so not sure if it makes a difference (so far It works for the 1st tutorial). The second tutorial, however,:

-I couldn't even get

void fragment() {
  ALBEDO = vec3(0.1, 0.3, 0.5);
}

to make it smoother water surface like tutorial shows.

-adding ROUGHNESS gives me this looks

-I also got error such as "too many argument for height()"

It's just too many errors and it would be nice if I could have the complete correct code so I can go back and compare what I did wrong

I did and it still gives out same errors. This is my code:

shader_type spatial;
render_mode specular_toon

uniform float height_scale = 0.5;
uniform sampler2D noise;
uniform sampler2D normalmap;
varying vec2 tex_position;

void vertex() {
	vec2 pos = VERTEX.xz;
	float k = height(pos, TIME);
	VERTEX.y = k;
	NORMAL = normalize(vec3(k - height(pos + vec2(0.1, 0.0), TIME), 0.1, k - height(pos + vec2(0.0, 0.1), TIME)));
}

void fragment() {
  float fresnel = sqrt(1.0 - dot(NORMAL, VIEW));
  RIM = 0.2;
  METALLIC = 0.0;
  ROUGHNESS = 0.01 * (1.0 - fresnel);
  ALBEDO = vec3(0.01, 0.03, 0.05) + (0.1 * fresnel);
}

float height(vec2 position, float time) {
  vec2 offset = 0.01 * cos(position + time);
  return texture(noise, (position / 10.0) - offset).x;
}

OK so after moving abunch of codes around I finally got it somewhat working with this:

shader_type spatial;
render_mode specular_toon;

uniform sampler2D noise;
uniform float height_scale = 0.5;
uniform sampler2D normalmap;
varying vec2 tex_position;

float wave(vec2 position){
  position += texture(noise, position / 10.0).x * 2.0 -1.0;
  vec2 wv = 1.0 - abs(sin(position));
  return pow(1.0 - pow(wv.x * wv.y, 0.65), 4.0);
}

float height(vec2 position, float time) {
  float d = wave((position + time) * 0.4) * 0.3;
  d += wave((position - time) * 0.3) * 0.3;
  d += wave((position + time) * 0.5) * 0.2;
  d += wave((position - time) * 0.6) * 0.2;
  return d;
}

void vertex() {
	vec2 pos = VERTEX.xz;
	float k = height(pos, TIME);
	VERTEX.y = k;
	NORMAL = normalize(vec3(k - height(pos + vec2(0.1, 0.0), TIME), 0.1, k - height(pos + vec2(0.0, 0.1), TIME)));
}

void fragment() {
  float fresnel = sqrt(1.0 - dot(NORMAL, VIEW));
  RIM = 0.2;
  METALLIC = 0.0;
  ROUGHNESS = 0.01 * (1.0 - fresnel);
  ALBEDO = vec3(0.01, 0.03, 0.05) + (0.1 * fresnel);
}

So what I learn is that each function have to be at the right place (eg. if you put float height() above float wave() it will fail).

    Yes, order of operations matters, sometimes seemingly significantly more than others, but in truth always. It's more about execution order/code flow.

    4 months later

    Gowydot OK so after moving abunch of codes around I finally got it somewhat working with this:

    I got the same code and the result is far from what is presented as expected. The resulting picture is completely different from the one presented in the tutorial as a reference.

      Tomcat Yes I remember mine being jaggy and looks plastic. I wonder if they increased vertices and improved environment lightings for image display.

      2 months later