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.
This commit is contained in:
N8n5h 2021-03-01 01:16:17 -03:00
parent c07de1cc25
commit 5f8b92f9c3
3 changed files with 27 additions and 19 deletions

View file

@ -42,7 +42,12 @@ vec2 sampleCube(vec3 dir, out int faceIndex) {
uv = vec2(dir.x < 0.0 ? dir.z : -dir.z, -dir.y); uv = vec2(dir.x < 0.0 ? dir.z : -dir.z, -dir.y);
} }
// downscale uv a little to hide seams // downscale uv a little to hide seams
// transform coordinates from clip space to texture space
#ifndef _FlipY
return uv * 0.9976 * ma + 0.5; return uv * 0.9976 * ma + 0.5;
#else
return vec2(uv.x * ma, uv.y * -ma) * 0.9976 + 0.5;
#endif
} }
#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 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; vec2 uvtiled = pointLightTile.z * uv + pointLightTile.xy;
#ifdef _InvY #ifdef _FlipY
uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system
#endif #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))); uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(-1.0, 0.0) / smSize)));
pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; pointLightTile = pointLightDataArray[lightIndex + newFaceIndex];
uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy;
#ifdef _InvY #ifdef _FlipY
uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system
#endif #endif
result += texture(shadowMap, vec3(pointLightTile.z * uvtiled + pointLightTile.xy, compare)); 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))); uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(-1.0, 1.0) / smSize)));
pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; pointLightTile = pointLightDataArray[lightIndex + newFaceIndex];
uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy;
#ifdef _InvY #ifdef _FlipY
uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system
#endif #endif
result += texture(shadowMap, vec3(uvtiled, compare)); 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))); uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(0.0, -1.0) / smSize)));
pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; pointLightTile = pointLightDataArray[lightIndex + newFaceIndex];
uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy;
#ifdef _InvY #ifdef _FlipY
uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system
#endif #endif
result += texture(shadowMap, vec3(uvtiled, compare)); 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))); uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(-1.0, -1.0) / smSize)));
pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; pointLightTile = pointLightDataArray[lightIndex + newFaceIndex];
uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy;
#ifdef _InvY #ifdef _FlipY
uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system
#endif #endif
result += texture(shadowMap, vec3(uvtiled, compare)); 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))); uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(0.0, 1.0) / smSize)));
pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; pointLightTile = pointLightDataArray[lightIndex + newFaceIndex];
uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy;
#ifdef _InvY #ifdef _FlipY
uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system
#endif #endif
result += texture(shadowMap, vec3(uvtiled, compare)); 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))); uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(1.0, -1.0) / smSize)));
pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; pointLightTile = pointLightDataArray[lightIndex + newFaceIndex];
uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy;
#ifdef _InvY #ifdef _FlipY
uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system
#endif #endif
result += texture(shadowMap, vec3(uvtiled, compare)); 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))); uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(1.0, 0.0) / smSize)));
pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; pointLightTile = pointLightDataArray[lightIndex + newFaceIndex];
uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy;
#ifdef _InvY #ifdef _FlipY
uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system
#endif #endif
result += texture(shadowMap, vec3(uvtiled, compare)); 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))); uvtiled = transformOffsetedUV(faceIndex, newFaceIndex, vec2(uv + (vec2(1.0, 1.0) / smSize)));
pointLightTile = pointLightDataArray[lightIndex + newFaceIndex]; pointLightTile = pointLightDataArray[lightIndex + newFaceIndex];
uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy; uvtiled = pointLightTile.z * uvtiled + pointLightTile.xy;
#ifdef _InvY #ifdef _FlipY
uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system uvtiled.y = 1.0 - uvtiled.y; // invert Y coordinates for direct3d coordinate system
#endif #endif
result += texture(shadowMap, vec3(uvtiled, compare)); result += texture(shadowMap, vec3(uvtiled, compare));

View file

@ -211,7 +211,7 @@ def export_data(fp, sdk_path):
resx, resy = arm.utils.get_render_resolution(arm.utils.get_active_scene()) resx, resy = arm.utils.get_render_resolution(arm.utils.get_active_scene())
if wrd.arm_write_config: if wrd.arm_write_config:
write_data.write_config(resx, resy) write_data.write_config(resx, resy)
# Change project version (Build, Publish) # Change project version (Build, Publish)
if (not state.is_play) and (wrd.arm_project_version_autoinc): 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) 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) state.proc_publish_build = run_proc(cmd, done_gradlew_build)
else: 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"') 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 # HTML5 After Publish
if target_name.startswith('html5'): if target_name.startswith('html5'):
if len(arm.utils.get_html5_copy_path()) > 0 and (wrd.arm_project_html5_copy): 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) 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): if os.path.exists(dst):
shutil.rmtree(dst) shutil.rmtree(dst)
try: try:
@ -673,10 +673,10 @@ def build_success():
link_html5_app = arm.utils.get_link_web_server() +'/'+ project_name link_html5_app = arm.utils.get_link_web_server() +'/'+ project_name
print("Running a browser with a link " + link_html5_app) print("Running a browser with a link " + link_html5_app)
webbrowser.open(link_html5_app) webbrowser.open(link_html5_app)
# Windows After Publish # Windows After Publish
if target_name.startswith('windows'): if target_name.startswith('windows'):
list_vs = [] list_vs = []
err = '' err = ''
# Print message # Print message
project_name = arm.utils.safesrc(wrd.arm_project_name +'-'+ wrd.arm_project_version) 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: for vs in list_vs:
print('- ' + vs[1] + ' (version ' + vs[3] +')') print('- ' + vs[1] + ' (version ' + vs[3] +')')
return return
# Current VS # Current VS
vs_path = '' vs_path = ''
for vs in list_vs: for vs in list_vs:
if vs[0] == wrd.arm_project_win_list_vs: if vs[0] == wrd.arm_project_win_list_vs:
vs_path = vs[2] vs_path = vs[2]
break break
# Open in Visual Studio # Open in Visual Studio
if int(wrd.arm_project_win_build) == 1: 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"')) cmd = os.path.join('start "' + vs_path, 'Common7', 'IDE', 'devenv.exe" "' + os.path.join(project_path, project_name + '.sln"'))
subprocess.Popen(cmd, shell=True) subprocess.Popen(cmd, shell=True)
# Compile # 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' bits = '64' if wrd.arm_project_win_build_arch == 'x64' else '32'
# vcvars # vcvars
cmd = os.path.join(vs_path, 'VC', 'Auxiliary', 'Build', 'vcvars' + bits + '.bat') cmd = os.path.join(vs_path, 'VC', 'Auxiliary', 'Build', 'vcvars' + bits + '.bat')
@ -792,7 +792,7 @@ def done_vs_vars():
# MSBuild # MSBuild
wrd = bpy.data.worlds['Arm'] wrd = bpy.data.worlds['Arm']
list_vs, err = arm.utils.get_list_installed_vs(True, True, True) list_vs, err = arm.utils.get_list_installed_vs(True, True, True)
# Current VS # Current VS
vs_path = '' vs_path = ''
vs_name = '' vs_name = ''
for vs in list_vs: for vs in list_vs:
@ -851,7 +851,7 @@ def done_vs_build():
os.chdir(res_path) # set work folder os.chdir(res_path) # set work folder
subprocess.Popen(cmd, shell=True) subprocess.Popen(cmd, shell=True)
# Open Build Directory # Open Build Directory
if wrd.arm_project_win_build_open: if wrd.arm_project_win_build_open:
arm.utils.open_folder(path) arm.utils.open_folder(path)
state.redraw_ui = True state.redraw_ui = True
else: else:

View file

@ -537,6 +537,9 @@ def write_compiledglsl(defs, make_variants):
#endif #endif
""") """)
if state.target == 'html5':
f.write("#define _FlipY\n")
f.write("""const float PI = 3.1415926535; f.write("""const float PI = 3.1415926535;
const float PI2 = PI * 2.0; const float PI2 = PI * 2.0;
const vec2 shadowmapSize = vec2(""" + str(shadowmap_size) + """, """ + str(shadowmap_size) + """); const vec2 shadowmapSize = vec2(""" + str(shadowmap_size) + """, """ + str(shadowmap_size) + """);