Shader help - mipmaps/AA?

Hello, i copied original Godot shader parallax part into Visual Script shader, but im not sure how to make Visual script equal oryginal one.

every texture param use linear filter

Right side is default Godot material converted to file:

// NOTE: Shader automatically converted from Godot Engine 4.2.1.stable's StandardMaterial3D.

shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;
uniform vec4 albedo : source_color;
uniform sampler2D texture_albedo : source_color,filter_linear_mipmap,repeat_enable;
uniform float point_size : hint_range(0,128);
uniform float roughness : hint_range(0,1);
uniform sampler2D texture_metallic : hint_default_white,filter_linear_mipmap,repeat_enable;
uniform vec4 metallic_texture_channel;
uniform sampler2D texture_roughness : hint_roughness_r,filter_linear_mipmap,repeat_enable;
uniform float specular;
uniform float metallic;
uniform sampler2D texture_heightmap : hint_default_black,filter_linear_mipmap,repeat_enable;
uniform float heightmap_scale;
uniform int heightmap_min_layers;
uniform int heightmap_max_layers;
uniform vec2 heightmap_flip;
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
uniform vec3 uv2_scale;
uniform vec3 uv2_offset;


void vertex() {
	UV=UV*uv1_scale.xy+uv1_offset.xy;
}






void fragment() {
	vec2 base_uv = UV;
	{
		vec3 view_dir = normalize(normalize(-VERTEX + EYE_OFFSET) * mat3(TANGENT * heightmap_flip.x, -BINORMAL * heightmap_flip.y, NORMAL));
		float num_layers = mix(float(heightmap_max_layers),float(heightmap_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));
		float layer_depth = 1.0 / num_layers;
		float current_layer_depth = 0.0;
		vec2 P = view_dir.xy * heightmap_scale * 0.01;
		vec2 delta = P / num_layers;
		vec2 ofs = base_uv;
		float depth = 1.0 - texture(texture_heightmap, ofs).r;
		float current_depth = 0.0;
		while(current_depth < depth) {
			ofs -= delta;
			depth = 1.0 - texture(texture_heightmap, ofs).r;
			current_depth += layer_depth;
		}
		vec2 prev_ofs = ofs + delta;
		float after_depth  = depth - current_depth;
		float before_depth = ( 1.0 - texture(texture_heightmap, prev_ofs).r  ) - current_depth + layer_depth;
		float weight = after_depth / (after_depth - before_depth);
		ofs = mix(ofs,prev_ofs,weight);
		base_uv=ofs;
	}
	vec4 albedo_tex = texture(texture_albedo,base_uv);
	ALBEDO = albedo.rgb * albedo_tex.rgb;
	float metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);
	METALLIC = metallic_tex * metallic;
	vec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0);
	float roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);
	ROUGHNESS = roughness_tex * roughness;
	SPECULAR = specular;
}

So i copied vec2 base_uv = UV;{ part code into Visual Shader expression, and as you see on the left side it do work, but i dont know how to make this mipmap/AA work correctly the same way like in oryginal.

I also did setup render modes same as original, but no help.

Please help how to make left(VShader) side same as right(original).

Here is VScript:

Ok, self solved. seems like even if Visual Shader had image, it had problems because of way it was loaded. Very confusing from user side i must say.

For future people having same issue, here was solution:

instead of:

	get_active_material(0).set_shader_parameter("parallaxmap", ImageTexture.create_from_image(Image.load_from_file("res://IMAGE_PATH")))

use:

	get_active_material(0).set_shader_parameter("parallaxmap", load("res://IMAGE_PATH"))

edit:
also adding all textures in action, it really look pleasant, i like Godot deep parallax :slight_smile:

edit2:
Heightmap based Vertex/Frag Visual Shader Terrain had also a lot of issues with NORMAL/BINORMAL/TANGENT to use NormalMap.

Somehow managed to solve this and it looks really cool

So… everything in shader! its just Plane with subdivision modified by shader :slight_smile:


image

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.