mirror of
https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git
synced 2025-09-19 20:05:57 +08:00
Parallax Mapping node finalized
This commit is contained in:
@ -52,5 +52,4 @@ func _get_code(input_vars: Array[String], output_vars: Array[String], mode: Shad
|
||||
var amplitude: String = input_vars[1]
|
||||
if !height_map:
|
||||
return output_vars[0] + " = UV;"
|
||||
|
||||
return output_vars[0] + " = parallax_mapping_uv(%s, %s, CAMERA_DIRECTION_WORLD, INV_VIEW_MATRIX, UV);" % [height_map, amplitude];
|
||||
return output_vars[0] + " = parallax_mapping_uv(%s, -%s, UV, TANGENT, NORMAL, BINORMAL, VIEW);" % [height_map, amplitude];
|
||||
|
@ -1,11 +1,17 @@
|
||||
vec2 parallax_mapping_uv(sampler2D height_map, float bump_scale, vec3 view_direction, mat4 inv_view_matrix, vec2 uv){
|
||||
vec3 _eye = -(inv_view_matrix * vec4(view_direction, 0.0)).xyz;
|
||||
_eye = normalize(view_direction);
|
||||
float _depth = texture(height_map, uv).w;
|
||||
vec2 _half_offset = normalize(_eye).xy * (_depth) * bump_scale;
|
||||
_depth = (_depth + texture(height_map, uv + _half_offset).x) * 0.5;
|
||||
_half_offset = normalize(_eye).xy * (_depth) * bump_scale;
|
||||
_depth = (_depth + texture(height_map, uv + _half_offset).x) * 0.5;
|
||||
_half_offset = normalize(_eye).xy * (_depth) * bump_scale;
|
||||
return uv + _half_offset;
|
||||
vec2 parallax_mapping_uv_offset_1_step(float height, float amplitude, vec3 view_dir_tangent)
|
||||
{
|
||||
height = height * amplitude - amplitude / 2.0;
|
||||
vec3 _vector = view_dir_tangent;
|
||||
_vector.y += 0.42;
|
||||
return height * (_vector.xz / _vector.y);
|
||||
}
|
||||
|
||||
vec2 parallax_mapping_uv(sampler2D height, float amplitude, vec2 uv, vec3 tangent, vec3 normal, vec3 binormal, vec3 view)
|
||||
{
|
||||
float depth = amplitude / 10.0;
|
||||
mat3 _tangent_matrix = mat3(tangent, normal, -binormal); // VIEW TO TANGENT SPACE
|
||||
vec3 _view_tangent = transpose(_tangent_matrix) * view;
|
||||
float _parallaxHeight = texture(height, uv).r;
|
||||
vec2 _parallaxOffset = parallax_mapping_uv_offset_1_step(_parallaxHeight, depth, _view_tangent);
|
||||
return _parallaxOffset + uv;
|
||||
}
|
Reference in New Issue
Block a user