1
0
mirror of https://github.com/DigvijaysinhGohil/Godot-Shader-Lib.git synced 2025-09-20 04:15:58 +08:00

Parallax Mapping node finalized

This commit is contained in:
Digvijaysinh Gohil
2023-12-24 20:18:30 +05:30
parent 9b79e5fca3
commit 8b1f8d246e
3 changed files with 18 additions and 13 deletions

View File

@ -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;
}