From 5f8b92f9c3bb2f0d03207a462f14b15db0104cd4 Mon Sep 17 00:00:00 2001 From: N8n5h Date: Mon, 1 Mar 2021 01:16:17 -0300 Subject: [PATCH] Applied flip workaround for point light too for html5 and atlas The same concept for spot lights was applied for point lights; the difference is that because point lights require to do the projection in the shader, the first inversion was applied in sampleCube() when returning the uv coordinates. "_FlipY" was added to replace "_InvY" in "PCFFakeCube()" because the inversion is only necessary for shaders and not anything else, otherwise it would break rendering of other parts. --- Shaders/std/shadows.glsl | 23 ++++++++++++++--------- blender/arm/make.py | 20 ++++++++++---------- blender/arm/write_data.py | 3 +++ 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Shaders/std/shadows.glsl b/Shaders/std/shadows.glsl index baf940a4..8aa053f3 100755 --- a/Shaders/std/shadows.glsl +++ b/Shaders/std/shadows.glsl @@ -42,7 +42,12 @@ vec2 sampleCube(vec3 dir, out int faceIndex) { uv = vec2(dir.x < 0.0 ? dir.z : -dir.z, -dir.y); } // downscale uv a little to hide seams + // transform coordinates from clip space to texture space + #ifndef _FlipY return uv * 0.9976 * ma + 0.5; + #else + return vec2(uv.x * ma, uv.y * -ma) * 0.9976 + 0.5; + #endif } #endif @@ -189,7 +194,7 @@ float PCFFakeCube(sampler2DShadow shadowMap, const vec3 lp, vec3 ml, const float vec4 pointLightTile = pointLightDataArray[lightIndex + faceIndex]; // x: tile X offset, y: tile Y offset, z: tile size relative to atlas vec2 uvtiled = pointLightTile.z * uv + pointLightTile.xy; - #ifdef _InvY + #ifdef _FlipY uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system #endif @@ -199,7 +204,7 @@ float PCFFakeCube(sampler2DShadow shadowMap, const vec3 lp, vec3 ml, const float uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(-1.0, 0.0) / smSize))); pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; - #ifdef _InvY + #ifdef _FlipY uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system #endif result += texture(shadowMap, vec3(pointLightTile.z * uvtiled + pointLightTile.xy, compare)); @@ -207,7 +212,7 @@ float PCFFakeCube(sampler2DShadow shadowMap, const vec3 lp, vec3 ml, const float uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(-1.0, 1.0) / smSize))); pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; - #ifdef _InvY + #ifdef _FlipY uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system #endif result += texture(shadowMap, vec3(uvtiled, compare)); @@ -215,7 +220,7 @@ float PCFFakeCube(sampler2DShadow shadowMap, const vec3 lp, vec3 ml, const float uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(0.0, -1.0) / smSize))); pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; - #ifdef _InvY + #ifdef _FlipY uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system #endif result += texture(shadowMap, vec3(uvtiled, compare)); @@ -223,7 +228,7 @@ float PCFFakeCube(sampler2DShadow shadowMap, const vec3 lp, vec3 ml, const float uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(-1.0, -1.0) / smSize))); pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; - #ifdef _InvY + #ifdef _FlipY uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system #endif result += texture(shadowMap, vec3(uvtiled, compare)); @@ -231,7 +236,7 @@ float PCFFakeCube(sampler2DShadow shadowMap, const vec3 lp, vec3 ml, const float uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(0.0, 1.0) / smSize))); pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; - #ifdef _InvY + #ifdef _FlipY uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system #endif result += texture(shadowMap, vec3(uvtiled, compare)); @@ -239,7 +244,7 @@ float PCFFakeCube(sampler2DShadow shadowMap, const vec3 lp, vec3 ml, const float uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(1.0, -1.0) / smSize))); pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; - #ifdef _InvY + #ifdef _FlipY uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system #endif result += texture(shadowMap, vec3(uvtiled, compare)); @@ -247,7 +252,7 @@ float PCFFakeCube(sampler2DShadow shadowMap, const vec3 lp, vec3 ml, const float uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(1.0, 0.0) / smSize))); pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; - #ifdef _InvY + #ifdef _FlipY uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system #endif result += texture(shadowMap, vec3(uvtiled, compare)); @@ -255,7 +260,7 @@ float PCFFakeCube(sampler2DShadow shadowMap, const vec3 lp, vec3 ml, const float uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(1.0, 1.0) / smSize))); pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; - #ifdef _InvY + #ifdef _FlipY uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system #endif result += texture(shadowMap, vec3(uvtiled, compare)); diff --git a/blender/arm/make.py b/blender/arm/make.py index c00fcc52..4538a9e6 100755 --- a/blender/arm/make.py +++ b/blender/arm/make.py @@ -211,7 +211,7 @@ def export_data(fp, sdk_path): resx, resy = arm.utils.get_render_resolution(arm.utils.get_active_scene()) if wrd.arm_write_config: write_data.write_config(resx, resy) - + # Change project version (Build, Publish) if (not state.is_play) and (wrd.arm_project_version_autoinc): wrd.arm_project_version = arm.utils.arm.utils.change_version_project(wrd.arm_project_version) @@ -654,12 +654,12 @@ def build_success(): state.proc_publish_build = run_proc(cmd, done_gradlew_build) else: print('\nBuilding APK Warning: ANDROID_SDK_ROOT is not specified in environment variables and "Android SDK Path" setting is not specified in preferences: \n- If you specify an environment variable ANDROID_SDK_ROOT, then you need to restart Blender;\n- If you specify the setting "Android SDK Path" in the preferences, then repeat operation "Publish"') - + # HTML5 After Publish if target_name.startswith('html5'): if len(arm.utils.get_html5_copy_path()) > 0 and (wrd.arm_project_html5_copy): project_name = arm.utils.safesrc(wrd.arm_project_name +'-'+ wrd.arm_project_version) - dst = os.path.join(arm.utils.get_html5_copy_path(), project_name) + dst = os.path.join(arm.utils.get_html5_copy_path(), project_name) if os.path.exists(dst): shutil.rmtree(dst) try: @@ -673,10 +673,10 @@ def build_success(): link_html5_app = arm.utils.get_link_web_server() +'/'+ project_name print("Running a browser with a link " + link_html5_app) webbrowser.open(link_html5_app) - + # Windows After Publish if target_name.startswith('windows'): - list_vs = [] + list_vs = [] err = '' # Print message project_name = arm.utils.safesrc(wrd.arm_project_name +'-'+ wrd.arm_project_version) @@ -707,18 +707,18 @@ def build_success(): for vs in list_vs: print('- ' + vs[1] + ' (version ' + vs[3] +')') return - # Current VS + # Current VS vs_path = '' for vs in list_vs: if vs[0] == wrd.arm_project_win_list_vs: vs_path = vs[2] break - # Open in Visual Studio + # Open in Visual Studio if int(wrd.arm_project_win_build) == 1: cmd = os.path.join('start "' + vs_path, 'Common7', 'IDE', 'devenv.exe" "' + os.path.join(project_path, project_name + '.sln"')) subprocess.Popen(cmd, shell=True) # Compile - if int(wrd.arm_project_win_build) > 1: + if int(wrd.arm_project_win_build) > 1: bits = '64' if wrd.arm_project_win_build_arch == 'x64' else '32' # vcvars cmd = os.path.join(vs_path, 'VC', 'Auxiliary', 'Build', 'vcvars' + bits + '.bat') @@ -792,7 +792,7 @@ def done_vs_vars(): # MSBuild wrd = bpy.data.worlds['Arm'] list_vs, err = arm.utils.get_list_installed_vs(True, True, True) - # Current VS + # Current VS vs_path = '' vs_name = '' for vs in list_vs: @@ -851,7 +851,7 @@ def done_vs_build(): os.chdir(res_path) # set work folder subprocess.Popen(cmd, shell=True) # Open Build Directory - if wrd.arm_project_win_build_open: + if wrd.arm_project_win_build_open: arm.utils.open_folder(path) state.redraw_ui = True else: diff --git a/blender/arm/write_data.py b/blender/arm/write_data.py index 9f88e335..439e2984 100755 --- a/blender/arm/write_data.py +++ b/blender/arm/write_data.py @@ -537,6 +537,9 @@ def write_compiledglsl(defs, make_variants): #endif """) + if state.target == 'html5': + f.write("#define _FlipY\n") + f.write("""const float PI = 3.1415926535; const float PI2 = PI * 2.0; const vec2 shadowmapSize = vec2(""" + str(shadowmap_size) + """, """ + str(shadowmap_size) + """);