Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godot mac - freezes after assigning shader to shader material #92029

Open
graphific opened this issue May 16, 2024 · 1 comment
Open

Godot mac - freezes after assigning shader to shader material #92029

graphific opened this issue May 16, 2024 · 1 comment

Comments

@graphific
Copy link

Tested versions

  • Reproducible in Godot 4.2.2-stable, 4.2.0, 4.0-stable, 4.0.rc1

System information

Mac air m1 - Godot v4.2.2.stable.official [15073af] - Vulkan (Forward+)

Issue description

I'm trying to import some synty assets (from the biome pack) into godot:

/Applications/Godot\ 4.2.2.app/Contents/MacOS/Godot -d sm_env_pine_03.tscn 
Godot Engine v4.2.2.stable.official.15073afe3 - https://godotengine.org
Vulkan API 1.2.231 - Forward+ - Using Vulkan Device #0: Apple - Apple M1
 
2024-05-16 22:54:53.215 Godot[35620:21004230] WARNING: AVCaptureDeviceTypeExternal is deprecated for Continuity Cameras. Please use AVCaptureDeviceTypeContinuityCamera and add NSCameraUseContinuityCameraDeviceType to your Info.plist.
(base) roelof@Roelofs-MacBook-Air TreeHut %  /Applications/Godot\ 4.2.2.app/Contents/MacOS/Godot -e sm_env_pine_03.tscn
Godot Engine v4.2.2.stable.official.15073afe3 - https://godotengine.org
Vulkan API 1.2.231 - Forward+ - Using Vulkan Device #0: Apple - Apple M1
 
2024-05-16 22:55:27.238 Godot[35691:21004970] WARNING: AVCaptureDeviceTypeExternal is deprecated for Continuity Cameras. Please use AVCaptureDeviceTypeContinuityCamera and add NSCameraUseContinuityCameraDeviceType to your Info.plist.
WARNING: Blend file import is enabled in the project settings, but no Blender path is configured in the editor settings. Blend files will not be imported.
     at: _editor_init (modules/gltf/register_types.cpp:63)
[mvk-error] VK_ERROR_DEVICE_LOST: MTLCommandBuffer "vkQueueSubmit CommandBuffer on Queue 0-0" execution failed (code 1): Discarded (victim of GPU error/recovery) (00000005:kIOGPUCommandBufferCallbackErrorInnocentVictim)
ERROR: Vulkan: Did not create swapchain successfully. Error code: VK_ERROR_DEVICE_LOST
   at: prepare_buffers (drivers/vulkan/vulkan_context.cpp:2459)
ERROR: Vulkan: Cannot submit graphics queue. Error code: VK_ERROR_DEVICE_LOST
   at: swap_buffers (drivers/vulkan/vulkan_context.cpp:2536)
ERROR: Vulkan: Did not create swapchain successfully. Error code: VK_ERROR_DEVICE_LOST
   at: prepare_buffers (drivers/vulkan/vulkan_context.cpp:2459)
ERROR: Vulkan: Cannot submit graphics queue. Error code: VK_ERROR_DEVICE_LOST
   at: swap_buffers (drivers/vulkan/vulkan_context.cpp:2536)

Steps to reproduce

The issue occurs when:

  • create the gdshader using the godotshader one above = no errors all good so far.
  • create a shader material, also good so far
  • assign the shader to the material is when Godot hangs and shows:

Minimal reproduction project (MRP)

shader_mac_hang.zip

@graphific
Copy link
Author

Some more findings:

  • using a simplified shader its the last line ALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold; that causes the issue
shader_type spatial;

render_mode depth_prepass_alpha, cull_disabled, diffuse_burley, specular_schlick_ggx;

uniform float alpha_scissor_threshold = 0.4;
uniform float specular = 0.4;
uniform float roughness = 0.85;
uniform float face_tint = 0.2;

uniform sampler2D leaf_texture;
uniform sampler2D leaf_normal_texture;
uniform vec2 leaf_uv_scale = vec2(1.0);
uniform vec3 leaf_tint_base = vec3(0.0);
uniform vec3 leaf_tint_highlight = vec3(1.0);
uniform float leaf_tint_strength = 0.0;
uniform bool use_texture_brightness = true;
uniform float leaf_brightness = 8.0;

uniform vec3 leaf_emission_color = vec3(0.0);
uniform float leaf_emission_strength = 0.0;
uniform sampler2D leaf_emission_mask;

uniform sampler2D trunk_texture;
uniform sampler2D trunk_normal_texture;
uniform vec2 trunk_uv_scale = vec2(1.0);
uniform vec3 trunk_tint = vec3(0.0);
uniform float trunk_tint_strength = 0.0;

varying vec3 world_normal;
varying vec3 global_position;

float luminance(vec3 color) {
    return dot(color, vec3(0.299, 0.587, 0.114));
}

void vertex() {
	// Called for every vertex the material is visible on.
    global_position = MODEL_MATRIX[3].xyz;
    world_normal = normalize(MODEL_NORMAL_MATRIX * NORMAL);
}

void fragment() {
	// Called for every pixel the material is visible on.
	vec2 base_uv = COLOR.b > 0.5 ? UV * leaf_uv_scale : UV * trunk_uv_scale;
    vec4 base_texture = COLOR.b > 0.5 ? texture(leaf_texture, base_uv) : texture(trunk_texture, base_uv);
    vec4 base_normal = COLOR.b > 0.5 ? texture(leaf_normal_texture, base_uv) : texture(trunk_normal_texture, base_uv);

	vec3 tinted_color = mix(
        COLOR.b > 0.5 ? leaf_tint_base : trunk_tint,
        COLOR.b > 0.5 ? leaf_tint_highlight : trunk_tint,
        COLOR.g
    );
	
	float luminance_factor = (COLOR.b > 0.5 ? (use_texture_brightness ? luminance(base_texture.rgb) * leaf_brightness : 1.0) : 1.0);
    base_texture.rgb = mix(base_texture.rgb, tinted_color * luminance_factor, COLOR.b > 0.5 ? leaf_tint_strength : trunk_tint_strength);

    float face_tint_factor = sin(world_normal.y * 16.0);
    base_texture.rgb = COLOR.b < 0.5 ? mix(base_texture.rgb, base_texture.rgb * face_tint_factor, face_tint) : base_texture.rgb;

	SPECULAR = specular;
	NORMAL_MAP = base_normal.rgb;
	NORMAL = FRONT_FACING ? NORMAL : -NORMAL;
	ROUGHNESS = roughness;
	ALBEDO = base_texture.rgb;
	ALPHA = base_texture.a;
	EMISSION = COLOR.b > 0.5 ? leaf_emission_color * texture(leaf_emission_mask, base_uv).rgb * leaf_emission_strength : vec3(0.0);
	//ALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold;
}

Also here as a zip:
pine5.gdshader.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Up for grabs
Development

No branches or pull requests

2 participants