shader_type spatial; render_mode sss_mode_skin, depth_prepass_alpha; uniform vec3 displacement_strength = vec3(0.8, 0.3, 0.2); uniform vec3 w_scale = vec3(1.0, 1.0, 1.0); uniform sampler2D disp_texture; uniform sampler2D water_texture; uniform sampler2D water_color: repeat_disable; varying vec3 passtrough; uniform sampler2D DEPTH_TEXTURE: hint_depth_texture; varying vec3 ro; varying vec3 p; varying vec3 vertex_normal_ws; float fresnel(float amount, vec3 normal, vec3 view) { return pow((1.0 - clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0 )), amount); } void vertex() { float y_correction = sin(0.5*PI*UV2.x); float inv_y_corr = sin((1.0-UV2.x)*PI/2.0); vec3 x_disp = vec3(inv_y_corr* sin(-TIME+UV.x*w_scale.x*PI), sin(TIME+UV.x*w_scale.x*PI), y_correction * (sin(-TIME+UV.x*w_scale.x*PI)-1.0)); vec3 y_disp = vec3(y_correction * sin(TIME+UV.y*w_scale.y*PI), cos(TIME+UV.y*w_scale.y*PI), inv_y_corr * (sin(TIME+UV.y*w_scale.y*PI)+1.0)); vec3 x_norm = vec3(-cos(TIME+UV.x*w_scale.x*PI)*displacement_strength.y*0.5, 0, y_correction * displacement_strength.z * (-cos(-TIME+UV.x*w_scale.x*PI))); vec3 y_norm = vec3(-sin(TIME+UV.y*w_scale.y*PI)*displacement_strength.y*0.5, 0, inv_y_corr * displacement_strength.z * (-cos(TIME+UV.y*w_scale.y*PI))); x_disp *= (1.5 + sin(-TIME+UV.x/0.5)) * displacement_strength * 0.3; x_norm *= displacement_strength.y + x_disp.y; y_disp *= (1.5 + cos(TIME*3.0+UV.x)) * displacement_strength * 0.3; y_norm *= displacement_strength.y + y_disp.y; NORMAL += vec3(x_norm+ y_norm); VERTEX += x_disp + y_disp; VERTEX -= vec3(0.0, pow(1.0-cos((UV2.x)*2.0*PI), 1.0)* 0.3, 0.0); NORMAL -= vec3(-sin((UV2.x)*2.0*PI)* 0.1, 0.0, 0.0); passtrough = vec3(0.5 + x_disp.y + y_disp.y, VERTEX.xz); //ro = (VIEW_MATRIX * vec4(0.0, 0.0, 0.0, 1.0)).xyz;// Get camera position in World space coordinates //p = ((MODEL_MATRIX)*vec4(VERTEX,1.0)).xyz;// Get fragment position in world space coordinates //vertex_normal_ws = ((MODEL_MATRIX)*vec4(NORMAL,1.0)).xyz; } void fragment() { vec2 disp_noise = (texture(disp_texture, UV *0.5 - TIME*0.1).xy-vec2(0.5))*pow(passtrough.x, 2.0); vec2 color_noise = texture(water_texture, UV2 * vec2(0.5, 0.1) + TIME * vec2(-0.05, 0.2) + disp_noise).xy * vec2(0.9, 0.1) + vec2(0.1, 0.1); float fresnel = pow(fresnel(1.0, NORMAL, VIEW), 2.2)*0.5; float wave_tips = pow(passtrough.x, 4.0) * texture(disp_texture, UV2+TIME*vec2(0.0, -0.1)).z + pow(passtrough.x, 2.0) * 0.4; float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r; depth = PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]); depth += VERTEX.z; ALPHA = min(1.0, max(0.0, depth*3.0)); ALBEDO = pow(texture(water_color, color_noise + vec2(0.0, fresnel) * 0.5).xyz, vec3(1.0)) * min(depth*0.7, 1.0); ROUGHNESS = texture(water_texture, UV2+disp_noise+TIME*vec2(0.0, -0.5)).z * 0.3 + wave_tips; NORMAL_MAP = vec3(0.5-disp_noise*0.5, 0.5); float depth_creep = texture(disp_texture, UV2*0.5 + vec2(TIME * 0.05, sin(UV2.y+TIME*PI/2.0)*0.1)).z + sin(UV2.y+TIME*PI/2.0); depth = 1.0 - (max(0.0,min(1.0, (depth*0.5 + 0.1))) - depth_creep * 0.2 - (passtrough.x-0.5) * 1.0); //EMISSION = pow(texture(water_color, vec2(pow(1.0-depth, 2.2), color_noise.y*0.5)).xyz, vec3(4.2))*3.0; EMISSION = pow(texture(water_color, pow(color_noise.xy * vec2(0.5, 1.5) + vec2(depth*0.3, depth * 0.4), vec2(1.1, 2.0))).xyz, vec3(1.4)); //EMISSION = vec3(depth); //vec2 parallax_uv = passtrough.zy; //EMISSION = vec3(parallax_uv, 0.0); //EMISSION = texture(water_color, texture(disp_texture, parallax_uv * vec2(0.1, 0.02)+ TIME * vec2( 0, 0.05)).zz).xyz; vec3 normal = vec3(0.0);// texture(surface_normalmap, UV).xyz * 2.0 - 1.0; vec3 refraction; vec3 rd = normalize(p - ro - normal * 1.5) * 2.0; vec2 offset = rd.xz; vec3 under_color = texture(water_texture, passtrough.yz * 0.1 + offset + (normal.xy)).rgb; //EMISSION = under_color; } //void light() { // Called for every pixel for every light affecting the material. // Uncomment to replace the default light processing function with this one. //}