Skip to content

Proximity Fade broken in Compatibility (OpenGL) #89942

@lijon

Description

@lijon

Tested versions

System information

Godot v4.3.dev5 - macOS 13.6.0 - GLES3 (Compatibility) - Apple M1 Pro - Apple M1 Pro (8 Threads)

Issue description

The Proximity Fade in StandardMaterial3D does not work with Compatibility renderer. The produced code assumes Vulkan Z range 0.0 to 1.0 instead of OpenGL -1.0 to 1.0. The fix is to remap the depth_tex as follows:

// Proximity Fade: Enabled
	float depth_tex = textureLod(depth_texture, SCREEN_UV, 0.0).r;
        depth_tex = depth_tex * 2.0 - 1.0; // <-- For OpenGL
	vec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, depth_tex, 1.0);
	world_pos.xyz /= world_pos.w;
	ALPHA *= clamp(1.0 - smoothstep(world_pos.z + proximity_fade_distance, world_pos.z, VERTEX.z), 0.0, 1.0);

Steps to reproduce

  • Use Compatibility renderer.
  • Add a cube on a plane, or two intersecting cubes, etc.
  • Apply a new standardMaterial3D and enable Proximity Fade.

Minimal reproduction project (MRP)

N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions