From 96ba8d4ac9ae2443642f58ed6c4868654e6b2e05 Mon Sep 17 00:00:00 2001 From: Tanasart <22589759+Ttanasart-pt@users.noreply.github.com> Date: Wed, 6 Dec 2023 19:51:22 +0700 Subject: [PATCH] mac os patch --- objects/o_main/Draw_64.gml | 2 -- .../d3d_light_directional.gml | 1 + scripts/d3d_light_point/d3d_light_point.gml | 6 ++-- scripts/d3d_scene/d3d_scene.gml | 13 +++++--- scripts/panel_preview/panel_preview.gml | 32 ++++++++++--------- scripts/windowManager/windowManager.gml | 7 ++-- shaders/sh_d3d_default/sh_d3d_default.fsh | 11 ++++++- shaders/sh_d3d_geometry/sh_d3d_geometry.fsh | 12 +++++-- .../sh_d3d_normal_blur/sh_d3d_normal_blur.fsh | 7 +++- .../sh_d3d_shadow_depth.fsh | 1 + 10 files changed, 61 insertions(+), 31 deletions(-) diff --git a/objects/o_main/Draw_64.gml b/objects/o_main/Draw_64.gml index e871c267f..0e4015b5b 100644 --- a/objects/o_main/Draw_64.gml +++ b/objects/o_main/Draw_64.gml @@ -4,8 +4,6 @@ draw_clear(COLORS.bg); #region windows init if(OS == os_windows && winMan_isMinimized()) exit; - else if(OS == os_macosx) - mac_window_step(); #endregion #region widget scroll diff --git a/scripts/d3d_light_directional/d3d_light_directional.gml b/scripts/d3d_light_directional/d3d_light_directional.gml index e89534114..59f994eef 100644 --- a/scripts/d3d_light_directional/d3d_light_directional.gml +++ b/scripts/d3d_light_directional/d3d_light_directional.gml @@ -60,6 +60,7 @@ function __3dLightDirectional() : __3dLight() constructor { surface_set_target(shadow_map); draw_clear(c_black); shader_set(shadow_mapper); + shader_set_i("use_8bit", OS == os_macosx); gpu_set_ztestenable(true); camera_set_view_mat(shadow_map_camera, shadow_map_view); diff --git a/scripts/d3d_light_point/d3d_light_point.gml b/scripts/d3d_light_point/d3d_light_point.gml index 4497ccbfd..c6509c88b 100644 --- a/scripts/d3d_light_point/d3d_light_point.gml +++ b/scripts/d3d_light_point/d3d_light_point.gml @@ -62,6 +62,8 @@ function __3dLightPoint() : __3dLight() constructor { draw_clear(c_black); shader_set(shadow_mapper); + shader_set_i("use_8bit", OS == os_macosx); + gpu_set_ztestenable(true); camera_set_view_mat(shadow_map_camera, shadow_map_views[index]); @@ -80,7 +82,7 @@ function __3dLightPoint() : __3dLight() constructor { if(!shadow_active) return; for( var i = 0; i < 6; i++ ) - shadow_maps[i] = surface_verify(shadow_maps[i], shadow_map_size, shadow_map_size, surface_r32float); + shadow_maps[i] = surface_verify(shadow_maps[i], shadow_map_size, shadow_map_size, OS == os_macosx? surface_rgba8unorm : surface_r32float); var position = transform.position; @@ -101,7 +103,7 @@ function __3dLightPoint() : __3dLight() constructor { shadowProjectEnd(); } - shadow_map = surface_verify(shadow_map, shadow_map_size * 2, shadow_map_size, surface_rgba32float); + shadow_map = surface_verify(shadow_map, shadow_map_size * 2, shadow_map_size, OS == os_macosx? surface_rgba8unorm : surface_rgba32float); surface_set_target(shadow_map); draw_clear(c_black); diff --git a/scripts/d3d_scene/d3d_scene.gml b/scripts/d3d_scene/d3d_scene.gml index f822de4c9..7e25b26be 100644 --- a/scripts/d3d_scene/d3d_scene.gml +++ b/scripts/d3d_scene/d3d_scene.gml @@ -129,9 +129,9 @@ function __3dScene(camera, name = "New scene") constructor { } #endregion static geometryPass = function(deferData, object, w = 512, h = 512) { #region - deferData.geometry_data[0] = surface_verify(deferData.geometry_data[0], w, h, surface_rgba32float); - deferData.geometry_data[1] = surface_verify(deferData.geometry_data[1], w, h, surface_rgba32float); - deferData.geometry_data[2] = surface_verify(deferData.geometry_data[2], w, h, surface_rgba32float); + deferData.geometry_data[0] = surface_verify(deferData.geometry_data[0], w, h, OS == os_macosx? surface_rgba8unorm : surface_rgba32float); + deferData.geometry_data[1] = surface_verify(deferData.geometry_data[1], w, h, OS == os_macosx? surface_rgba8unorm : surface_rgba32float); + deferData.geometry_data[2] = surface_verify(deferData.geometry_data[2], w, h, OS == os_macosx? surface_rgba8unorm : surface_rgba32float); surface_set_target_ext(0, deferData.geometry_data[0]); surface_set_target_ext(1, deferData.geometry_data[1]); @@ -149,6 +149,7 @@ function __3dScene(camera, name = "New scene") constructor { shader_set(sh_d3d_geometry); shader_set_f("planeNear", camera.view_near); shader_set_f("planeFar", camera.view_far); + shader_set_i("use_8bit", OS == os_macosx); submit(object, sh_d3d_geometry); @@ -158,10 +159,12 @@ function __3dScene(camera, name = "New scene") constructor { surface_reset_target(); if(defer_normal_radius) { - var _normal_blurred = surface_create_size(deferData.geometry_data[2], surface_rgba32float); + var _normal_blurred = surface_create_size(deferData.geometry_data[2], OS == os_macosx? surface_rgba8unorm : surface_rgba32float); surface_set_shader(_normal_blurred, sh_d3d_normal_blur); shader_set_f("radius", defer_normal_radius); + shader_set_i("use_8bit", OS == os_macosx); shader_set_dim("dimension", deferData.geometry_data[2]); + draw_surface_safe(deferData.geometry_data[2]); surface_reset_shader(); @@ -202,6 +205,8 @@ function __3dScene(camera, name = "New scene") constructor { static apply = function(deferData = noone) { #region shader_set(sh_d3d_default); + shader_set_i("use_8bit", OS == os_macosx); + #region ---- background ---- shader_set_f("light_ambient", colToVec4(lightAmbient)); shader_set_i("env_use_mapping", is_surface(enviroment_map) ); diff --git a/scripts/panel_preview/panel_preview.gml b/scripts/panel_preview/panel_preview.gml index 7aa1743c0..cf9e481e7 100644 --- a/scripts/panel_preview/panel_preview.gml +++ b/scripts/panel_preview/panel_preview.gml @@ -835,25 +835,27 @@ function Panel_Preview() : PanelContent() constructor { d3_view_camera.applyCamera(); - gpu_set_cullmode(cull_noculling); - gpu_set_ztestenable(true); - gpu_set_zwriteenable(false); + if(OS != os_macosx) { + gpu_set_cullmode(cull_noculling); + gpu_set_ztestenable(true); + gpu_set_zwriteenable(false); - shader_set(sh_d3d_grid_view); - var _dist = round(d3_view_camera.focus.distance(d3_view_camera.position)); - var _tx = round(d3_view_camera.focus.x); - var _ty = round(d3_view_camera.focus.y); + shader_set(sh_d3d_grid_view); + var _dist = round(d3_view_camera.focus.distance(d3_view_camera.position)); + var _tx = round(d3_view_camera.focus.x); + var _ty = round(d3_view_camera.focus.y); - var _scale = _dist * 2; - while(_scale > 32) _scale /= 2; + var _scale = _dist * 2; + while(_scale > 32) _scale /= 2; - shader_set_f("axisBlend", _blend); - shader_set_f("scale", _scale); - shader_set_f("shift", _tx / _dist / 2, _ty / _dist / 2); - draw_sprite_stretched(s_fx_pixel, 0, _tx - _dist, _ty - _dist, _dist * 2, _dist * 2); - shader_reset(); + shader_set_f("axisBlend", _blend); + shader_set_f("scale", _scale); + shader_set_f("shift", _tx / _dist / 2, _ty / _dist / 2); + draw_sprite_stretched(s_fx_pixel, 0, _tx - _dist, _ty - _dist, _dist * 2, _dist * 2); + shader_reset(); - gpu_set_zwriteenable(true); + gpu_set_zwriteenable(true); + } #endregion #region draw diff --git a/scripts/windowManager/windowManager.gml b/scripts/windowManager/windowManager.gml index 36b7dc3fa..029b55d1c 100644 --- a/scripts/windowManager/windowManager.gml +++ b/scripts/windowManager/windowManager.gml @@ -21,6 +21,10 @@ function winMan_getData(curr = true) { #region INLINE var _monitors = display_measure_all(); + if(!is_array(_monitors) || array_empty(_monitors)) + return [ 0, 0, display_get_width(), display_get_height(), + 0, 0, display_get_width(), display_get_height(), ]; + var _x = window_get_x(); var _y = window_get_y(); @@ -38,9 +42,6 @@ function winMan_getData(curr = true) { #region )) return _monitor; } - if(!is_array(_monitor) || array_length(_monitor) < 8) - return [ 0, 0, display_get_width(), display_get_height(), - 0, 0, display_get_width(), display_get_height(), ]; return _monitors[0]; } #endregion diff --git a/shaders/sh_d3d_default/sh_d3d_default.fsh b/shaders/sh_d3d_default/sh_d3d_default.fsh index ec3ba1af4..d80ad4ad9 100644 --- a/shaders/sh_d3d_default/sh_d3d_default.fsh +++ b/shaders/sh_d3d_default/sh_d3d_default.fsh @@ -11,6 +11,8 @@ varying float v_cameraDistance; #define PI 3.14159265359 #define TAU 6.28318530718 +uniform int use_8bit; + #region ---- light ---- uniform vec4 light_ambient; uniform float shadowBias; @@ -145,6 +147,10 @@ varying float v_cameraDistance; vec3 n = normalize(dir); return vec2((atan(n.x, n.y) / TAU) + 0.5, 1. - acos(n.z) / PI); } + + vec4 unormToFloat(vec4 vec) { + return vec - 1. * 65536.; + } #endregion void main() { @@ -164,8 +170,11 @@ void main() { #region ++++ normal ++++ vec3 _norm = v_vNormal; - if(mat_defer_normal == 1) + if(mat_defer_normal == 1) { _norm = texture2D(mat_normal_map, viewProjPos.xy).rgb; + if(use_8bit == 1) + _norm = unormToFloat(_norm); + } vec3 normal = normalize(_norm); #endregion diff --git a/shaders/sh_d3d_geometry/sh_d3d_geometry.fsh b/shaders/sh_d3d_geometry/sh_d3d_geometry.fsh index 51c785a71..4a7020655 100644 --- a/shaders/sh_d3d_geometry/sh_d3d_geometry.fsh +++ b/shaders/sh_d3d_geometry/sh_d3d_geometry.fsh @@ -5,6 +5,7 @@ varying vec3 v_vNormal; uniform int mat_flip; uniform int use_normal; +uniform int use_8bit; uniform float normal_strength; uniform sampler2D normal_map; @@ -14,11 +15,16 @@ void main() { vec4 mat_baseColor = texture2D( gm_BaseTexture, uv_coord ); if(mat_baseColor.a < 0.1) discard; - gl_FragData[0] = vec4(v_worldPosition.xyz, mat_baseColor.a); - gl_FragData[1] = vec4(v_viewPosition, mat_baseColor.a); - vec3 normal = v_vNormal; if(use_normal == 1) normal += (texture2D(normal_map, uv_coord).rgb * 2. - 1.) * normal_strength; + gl_FragData[0] = vec4(v_worldPosition.xyz, mat_baseColor.a); + gl_FragData[1] = vec4(v_viewPosition, mat_baseColor.a); gl_FragData[2] = vec4(normalize(normal), mat_baseColor.a); + + if(use_8bit == 1) { + gl_FragData[0] = gl_FragData[0] / 65536. + 1.; + gl_FragData[1] = gl_FragData[1] / 65536. + 1.; + gl_FragData[2] = gl_FragData[2] / 65536. + 1.; + } } diff --git a/shaders/sh_d3d_normal_blur/sh_d3d_normal_blur.fsh b/shaders/sh_d3d_normal_blur/sh_d3d_normal_blur.fsh index 4df9ae21b..eba96cbca 100644 --- a/shaders/sh_d3d_normal_blur/sh_d3d_normal_blur.fsh +++ b/shaders/sh_d3d_normal_blur/sh_d3d_normal_blur.fsh @@ -4,8 +4,9 @@ varying vec2 v_vTexcoord; varying vec4 v_vColour; -uniform vec2 dimension; +uniform vec2 dimension; uniform float radius; +uniform int use_8bit; void main() { vec3 current = texture2D( gm_BaseTexture, v_vTexcoord ).rgb; @@ -36,4 +37,8 @@ void main() { } gl_FragColor = vec4(sampled / weight, 1.); + + if(use_8bit == 1) { + gl_FragColor = gl_FragColor / 65536. + 1.; + } } diff --git a/shaders/sh_d3d_shadow_depth/sh_d3d_shadow_depth.fsh b/shaders/sh_d3d_shadow_depth/sh_d3d_shadow_depth.fsh index b9c3dc9ac..86ed1f41b 100644 --- a/shaders/sh_d3d_shadow_depth/sh_d3d_shadow_depth.fsh +++ b/shaders/sh_d3d_shadow_depth/sh_d3d_shadow_depth.fsh @@ -1,4 +1,5 @@ varying float v_LightDepth; +uniform int use_8bit; void main() { gl_FragColor = vec4(v_LightDepth, v_LightDepth, v_LightDepth, 1.);