Merge pull request #433 from Calinou/3d-preview-improve-deep-parallax

Improve the appearance of Deep Parallax in the 3D preview
This commit is contained in:
Rodz Labs 2022-03-28 22:27:22 +02:00 committed by GitHub
commit 5bbac12802
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

@ -540,7 +540,7 @@
"type": "size"
}
],
"preview_shader": "shader_type spatial;\nrender_mode blend_mix,cull_back,diffuse_burley,specular_schlick_ggx\n$if $(connected:opacity_tex) and $(param:flags_transparent)\n,depth_draw_alpha_prepass\n$fi\n;\n\nuniform sampler2D texture_albedo : hint_albedo; // $output(0)\nuniform sampler2D texture_emission : hint_black_albedo; // $output(2)\nuniform sampler2D texture_normal : hint_normal; // $output(3)\nuniform sampler2D texture_orm : hint_white; // $output(1)\nuniform sampler2D texture_subsurface_scattering : hint_white; // $output(5)\nuniform sampler2D texture_depth : hint_black; // $output(4)\nuniform int depth_min_layers = 8;\nuniform int depth_max_layers = 32;\nuniform vec2 depth_flip = vec2(1.0);\n\nuniform vec3 uv1_scale;\nuniform vec3 uv1_offset;\n\n$definitions\n\nvoid vertex() {\n\tUV=UV*uv1_scale.xy+uv1_offset.xy;\n}\n\nvoid fragment() {\n\tvec2 base_uv = UV;\n$if $(connected:depth_tex)\n\t{\n$begin_generate\n\t\tfloat depth_scale = 0.2*$depth_scale;\n$end_generate\n\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*depth_flip.x,-BINORMAL*depth_flip.y,NORMAL));\n\t\tfloat num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n\t\tfloat layer_depth = 1.0 / num_layers;\n\t\tfloat current_layer_depth = 0.0;\n\t\tvec2 P = view_dir.xy * depth_scale;\n\t\tvec2 delta = P / num_layers;\n\t\tvec2 ofs = base_uv;\n\t\tfloat depth = textureLod(texture_depth, ofs,0.0).r;\n\t\tfloat current_depth = 0.0;\n\t\twhile(current_depth < depth) {\n\t\t\tofs -= delta;\n\t\t\tdepth = textureLod(texture_depth, ofs,0.0).r;\n\t\t\tcurrent_depth += layer_depth;\n\t\t}\n\t\tvec2 prev_ofs = ofs + delta;\n\t\tfloat after_depth = depth - current_depth;\n\t\tfloat before_depth = textureLod(texture_depth, prev_ofs, 0.0).r - current_depth + layer_depth;\n\t\tfloat weight = after_depth / (after_depth - before_depth);\n\t\tofs = mix(ofs,prev_ofs,weight);\n\t\tbase_uv=ofs;\n\t}\n$fi\n$begin_generate\n\tvec4 albedo_tex = texture(texture_albedo, base_uv);\n\tALBEDO = $albedo_color.rgb * albedo_tex.rgb;\n\tvec4 orm_tex = texture(texture_orm, base_uv);\n\tMETALLIC = $metallic*orm_tex.b;\n\tROUGHNESS = $roughness*orm_tex.g;\n\tSPECULAR = 0.5;\n\tNORMALMAP = texture(texture_normal, base_uv).rgb;\n\tNORMALMAP_DEPTH = $normal;\n\tvec3 emission_tex = texture(texture_emission, base_uv).rgb;\n\tEMISSION = emission_tex*$emission_energy;\n\tAO = orm_tex.r;\n\tAO_LIGHT_AFFECT = $ao;\n$if $(connected:opacity_tex) and $(param:flags_transparent)\n\tALPHA = albedo_tex.a;\n$fi\n\tfloat sss_tex = texture(texture_subsurface_scattering, base_uv).r;\n\tSSS_STRENGTH=$sss*sss_tex;\n$end_generate\n}\n"
"preview_shader": "shader_type spatial;\nrender_mode blend_mix,cull_back,diffuse_burley,specular_schlick_ggx\n$if $(connected:opacity_tex) and $(param:flags_transparent)\n,depth_draw_alpha_prepass\n$fi\n;\n\nuniform sampler2D texture_albedo : hint_albedo; // $output(0)\nuniform sampler2D texture_emission : hint_black_albedo; // $output(2)\nuniform sampler2D texture_normal : hint_normal; // $output(3)\nuniform sampler2D texture_orm : hint_white; // $output(1)\nuniform sampler2D texture_subsurface_scattering : hint_white; // $output(5)\nuniform sampler2D texture_depth : hint_black; // $output(4)\nuniform int depth_min_layers = 8;\nuniform int depth_max_layers = 32;\nuniform vec2 depth_flip = vec2(1.0);\n\nuniform vec3 uv1_scale;\nuniform vec3 uv1_offset;\n\n$definitions\n\nvoid vertex() {\n\tUV=UV*uv1_scale.xy+uv1_offset.xy;\n}\n\nvoid fragment() {\n\tvec2 base_uv = UV;\n$if $(connected:depth_tex)\n\t{\n$begin_generate\n\t\tfloat depth_scale = 0.2*$depth_scale;\n$end_generate\n\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*depth_flip.x,-BINORMAL*depth_flip.y,NORMAL));\n\t\tfloat num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n\t\tfloat layer_depth = 1.0 / num_layers;\n\t\tfloat current_layer_depth = 0.0;\n\t\tvec2 P = view_dir.xy * depth_scale;\n\t\tvec2 delta = P / num_layers / dot(VIEW, NORMAL);\n\t\tvec2 ofs = base_uv;\n\t\tfloat depth = textureLod(texture_depth, ofs,0.0).r;\n\t\tfloat current_depth = 0.0;\n\t\twhile(current_depth < depth) {\n\t\t\tofs -= delta;\n\t\t\tdepth = textureLod(texture_depth, ofs,0.0).r;\n\t\t\tcurrent_depth += layer_depth;\n\t\t}\n\t\tvec2 prev_ofs = ofs + delta;\n\t\tfloat after_depth = depth - current_depth;\n\t\tfloat before_depth = textureLod(texture_depth, prev_ofs, 0.0).r - current_depth + layer_depth;\n\t\tfloat weight = after_depth / (after_depth - before_depth);\n\t\tofs = mix(ofs,prev_ofs,weight);\n\t\tbase_uv=ofs;\n\t}\n$fi\n$begin_generate\n\tvec4 albedo_tex = texture(texture_albedo, base_uv);\n\tALBEDO = $albedo_color.rgb * albedo_tex.rgb;\n\tvec4 orm_tex = texture(texture_orm, base_uv);\n\tMETALLIC = $metallic*orm_tex.b;\n\tROUGHNESS = $roughness*orm_tex.g;\n\tSPECULAR = 0.5;\n\tNORMALMAP = texture(texture_normal, base_uv).rgb;\n\tNORMALMAP_DEPTH = $normal;\n\tvec3 emission_tex = texture(texture_emission, base_uv).rgb;\n\tEMISSION = emission_tex*$emission_energy;\n\tAO = orm_tex.r;\n\tAO_LIGHT_AFFECT = $ao;\n$if $(connected:opacity_tex) and $(param:flags_transparent)\n\tALPHA = albedo_tex.a;\n$fi\n\tfloat sss_tex = texture(texture_subsurface_scattering, base_uv).r;\n\tSSS_STRENGTH=$sss*sss_tex;\n$end_generate\n}\n"
},
"type": "material_export"
}

View File

@ -39,7 +39,7 @@
},
{
"file_name": "$(path_prefix).shader",
"template": "shader_type spatial;\nrender_mode blend_mix,cull_back,diffuse_burley,specular_schlick_ggx\n$if $(connected:opacity_tex) and $(param:flags_transparent)\n,depth_draw_alpha_prepass\n$fi\n;\n\nuniform vec3 uv1_offset = vec3(1.0, 1.0, 1.0);\nuniform vec3 uv1_scale = vec3(1.0, 1.0, 1.0);\nuniform int depth_min_layers = 8;\nuniform int depth_max_layers = 16;\nuniform vec2 depth_flip = vec2(1.0);\nuniform float variation = 0.0;\nvarying float elapsed_time;\n\nvoid vertex() {\n\telapsed_time = TIME;\n\tUV = UV*uv1_scale.xy+uv1_offset.xy;\n}\n\n$definitions float_uniform_to_const,rename_buffers\n\nvoid fragment() {\n\tfloat _seed_variation_ = variation;\n\tvec2 uv = fract(UV);\n$if $(connected:depth_tex)\n\t{\n$begin_generate\n\t\tfloat depth_scale = 0.2*$depth_scale;\n$end_generate\n\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*depth_flip.x,-BINORMAL*depth_flip.y,NORMAL));\n\t\tfloat num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n\t\tfloat layer_depth = 1.0 / num_layers;\n\t\tfloat current_layer_depth = 0.0;\n\t\tvec2 P = view_dir.xy * depth_scale;\n\t\tvec2 delta = P / num_layers;\n\t\tvec2 ofs = uv;\n$begin_generate\n\t\tfloat depth = $depth_tex(ofs);\n$end_generate\n\t\tfloat current_depth = 0.0;\n\t\twhile(current_depth < depth) {\n\t\t\tofs -= delta;\n$begin_generate\n\t\t\tdepth = $depth_tex(ofs);\n$end_generate\n\t\t\tcurrent_depth += layer_depth;\n\t\t}\n\t\tvec2 prev_ofs = ofs + delta;\n\t\tfloat after_depth = depth - current_depth;\n$begin_generate\n\t\tfloat before_depth = $depth_tex(prev_ofs) - current_depth + layer_depth;\n$end_generate\n\t\tfloat weight = after_depth / (after_depth - before_depth);\n\t\tofs = mix(ofs, prev_ofs, weight);\n\t\tuv = ofs;\n\t}\n$fi\n$begin_generate rename_buffers\n\tvec3 albedo_tex = $albedo_tex(uv).rgb;\n\talbedo_tex = mix(pow((albedo_tex + vec3(0.055)) * (1.0 / (1.0 + 0.055)),vec3(2.4)),albedo_tex * (1.0 / 12.92),lessThan(albedo_tex,vec3(0.04045)));\n\tALBEDO = albedo_tex*$albedo_color.rgb;\n\tMETALLIC = $metallic_tex(uv)*$metallic;\n\tROUGHNESS = $roughness_tex(uv)*$roughness;\n\tNORMALMAP = $normal_tex(uv);\n\tEMISSION = $emission_tex(uv)*$emission_energy;\n$if $(connected:opacity_tex) and $(param:flags_transparent)\n\tALPHA = $opacity_tex(uv);\n$fi\n$end_generate\n}\n",
"template": "shader_type spatial;\nrender_mode blend_mix,cull_back,diffuse_burley,specular_schlick_ggx\n$if $(connected:opacity_tex) and $(param:flags_transparent)\n,depth_draw_alpha_prepass\n$fi\n;\n\nuniform vec3 uv1_offset = vec3(1.0, 1.0, 1.0);\nuniform vec3 uv1_scale = vec3(1.0, 1.0, 1.0);\nuniform int depth_min_layers = 8;\nuniform int depth_max_layers = 16;\nuniform vec2 depth_flip = vec2(1.0);\nuniform float variation = 0.0;\nvarying float elapsed_time;\n\nvoid vertex() {\n\telapsed_time = TIME;\n\tUV = UV*uv1_scale.xy+uv1_offset.xy;\n}\n\n$definitions float_uniform_to_const,rename_buffers\n\nvoid fragment() {\n\tfloat _seed_variation_ = variation;\n\tvec2 uv = fract(UV);\n$if $(connected:depth_tex)\n\t{\n$begin_generate\n\t\tfloat depth_scale = 0.2*$depth_scale;\n$end_generate\n\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*depth_flip.x,-BINORMAL*depth_flip.y,NORMAL));\n\t\tfloat num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n\t\tfloat layer_depth = 1.0 / num_layers;\n\t\tfloat current_layer_depth = 0.0;\n\t\tvec2 P = view_dir.xy * depth_scale;\n\t\tvec2 delta = P / num_layers / dot(VIEW, NORMAL);\n\t\tvec2 ofs = uv;\n$begin_generate\n\t\tfloat depth = $depth_tex(ofs);\n$end_generate\n\t\tfloat current_depth = 0.0;\n\t\twhile(current_depth < depth) {\n\t\t\tofs -= delta;\n$begin_generate\n\t\t\tdepth = $depth_tex(ofs);\n$end_generate\n\t\t\tcurrent_depth += layer_depth;\n\t\t}\n\t\tvec2 prev_ofs = ofs + delta;\n\t\tfloat after_depth = depth - current_depth;\n$begin_generate\n\t\tfloat before_depth = $depth_tex(prev_ofs) - current_depth + layer_depth;\n$end_generate\n\t\tfloat weight = after_depth / (after_depth - before_depth);\n\t\tofs = mix(ofs, prev_ofs, weight);\n\t\tuv = ofs;\n\t}\n$fi\n$begin_generate rename_buffers\n\tvec3 albedo_tex = $albedo_tex(uv).rgb;\n\talbedo_tex = mix(pow((albedo_tex + vec3(0.055)) * (1.0 / (1.0 + 0.055)),vec3(2.4)),albedo_tex * (1.0 / 12.92),lessThan(albedo_tex,vec3(0.04045)));\n\tALBEDO = albedo_tex*$albedo_color.rgb;\n\tMETALLIC = $metallic_tex(uv)*$metallic;\n\tROUGHNESS = $roughness_tex(uv)*$roughness;\n\tNORMALMAP = $normal_tex(uv);\n\tEMISSION = $emission_tex(uv)*$emission_energy;\n$if $(connected:opacity_tex) and $(param:flags_transparent)\n\tALPHA = $opacity_tex(uv);\n$fi\n$end_generate\n}\n",
"type": "template"
},
{

View File

@ -43,7 +43,7 @@ void fragment() {
float layer_depth = 1.0 / num_layers;
float current_layer_depth = 0.0;
vec2 P = view_dir.xy * depth_scale;
vec2 delta = P / num_layers;
vec2 delta = P / num_layers / dot(VIEW, NORMAL);
vec2 ofs = base_uv;
float depth = textureLod(texture_depth, ofs,0.0).r;
float current_depth = 0.0;