Fix legacy shaders flag

This commit is contained in:
Lubos Lenco 2019-02-10 20:37:38 +01:00
parent 39f0ddc09b
commit 44c8cdb679
7 changed files with 50 additions and 9 deletions

View file

@ -12,6 +12,7 @@ class Starter {
#end
public static function main(scene:String, mode:Int, resize:Bool, min:Bool, max:Bool, w:Int, h:Int, msaa:Int, vsync:Bool, getRenderPath:Void->iron.RenderPath) {
function start() {
if (tasks > 0) return;
@ -35,7 +36,11 @@ class Starter {
if (c.window_maximizable) windowFeatures |= FeatureMaximizable;
if (c.window_minimizable) windowFeatures |= FeatureMinimizable;
kha.System.start({title: Main.projectName, width: c.window_w, height: c.window_h, window: {mode: windowMode, windowFeatures: windowFeatures}, framebuffer: {samplesPerPixel: c.window_msaa, verticalSync: c.window_vsync}}, function(window:kha.Window) {
#if (kha_webgl && (!arm_legacy))
try {
#end
kha.System.start({title: Main.projectName, width: c.window_w, height: c.window_h, window: {mode: windowMode, windowFeatures: windowFeatures}, framebuffer: {samplesPerPixel: c.window_msaa, verticalSync: c.window_vsync}}, function(window:kha.Window) {
iron.App.init(function() {
#if arm_loadscreen
function load(g:kha.graphics2.Graphics) {
@ -55,6 +60,15 @@ class Starter {
});
});
});
#if (kha_webgl && (!arm_legacy))
}
catch (e:Dynamic) {
if (!kha.SystemImpl.gl2) {
trace("This project was not compiled with legacy shaders flag - please use WebGL 2 capable browser.");
}
}
#end
}
#if (js && arm_bullet)

View file

@ -81,7 +81,7 @@ class ArmoryAddonPreferences(AddonPreferences):
renderdoc_path: StringProperty(name="RenderDoc Path", description="Binary path", subtype="FILE_PATH", update=renderdoc_path_update, default="")
ffmpeg_path: StringProperty(name="FFMPEG Path", description="Binary path", subtype="FILE_PATH", update=ffmpeg_path_update, default="")
save_on_build: BoolProperty(name="Save on Build", description="Save .blend", default=False)
legacy_shaders: BoolProperty(name="Legacy Shaders", description="Attempt to compile shaders runnable on older hardware", default=False)
legacy_shaders: BoolProperty(name="Legacy Shaders", description="Attempt to compile shaders runnable on older hardware, use this for WebGL1 or GLES2 support in mobile render path", default=False)
relative_paths: BoolProperty(name="Generate Relative Paths", description="Write relative paths in khafile", default=False)
viewport_controls: EnumProperty(
items=[('qwerty', 'qwerty', 'qwerty'),

View file

@ -241,8 +241,11 @@ def compile(assets_only=False):
cmd.append(state.export_gapi)
if arm.utils.get_legacy_shaders():
cmd.append('--shaderversion')
cmd.append('110')
if 'html5' in state.target:
pass
else:
cmd.append('--shaderversion')
cmd.append('110')
elif 'android' in state.target or 'ios' in state.target or 'html5' in state.target:
cmd.append('--shaderversion')
cmd.append('300')

View file

@ -89,6 +89,7 @@ def add_world_defs():
if arm.utils.get_legacy_shaders():
wrd.world_defs += '_Legacy'
assets.add_khafile_def('arm_legacy')
# Light defines
point_lights = 0

View file

@ -1,3 +1,4 @@
import bpy
import arm.material.make_tess as make_tess
def make(con_mesh):
@ -103,4 +104,9 @@ def make(con_mesh):
vert.add_out('vec3 eyeDirCam')
vert.add_uniform('mat4 WV', '_worldViewMatrix')
vert.write('eyeDirCam = vec4(WV * spos).xyz; eyeDirCam.z *= -1;')
frag.write_attrib('vec3 vVecCam = normalize(eyeDirCam);')
frag.write_attrib('vec3 vVecCam = normalize(eyeDirCam);')
wrd = bpy.data.worlds['Arm']
if '_Legacy' in wrd.world_defs:
frag.replace('sampler2DShadow', 'sampler2D')
frag.replace('samplerCubeShadow', 'samplerCube')

View file

@ -356,7 +356,7 @@ def make_forward_mobile(con_mesh):
if is_shadows:
vert.add_out('vec4 lightPosition')
vert.add_uniform('mat4 LWVP', '_biasLightWorldViewProjectionMatrix')
vert.write('lightPosition = LWVP * spos;')
vert.write('lightPosition = LWVP * spos;')
frag.add_uniform('sampler2DShadow shadowMap')
frag.add_uniform('float shadowsBias', '_sunShadowsBias')
if '_CSM' in wrd.world_defs:
@ -367,7 +367,10 @@ def make_forward_mobile(con_mesh):
else:
frag.write('if (lightPosition.w > 0.0) {')
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
frag.write(' svisibility = texture(shadowMap, vec3(lPos.xy, lPos.z - shadowsBias)).r;')
if '_Legacy' in wrd.world_defs:
frag.write(' svisibility = float(texture(shadowMap, vec2(lPos.xy)).r > lPos.z - shadowsBias);')
else:
frag.write(' svisibility = texture(shadowMap, vec3(lPos.xy, lPos.z - shadowsBias)).r;')
frag.write('}')
frag.write('direct += basecol * sdotNL * sunCol * svisibility;')
@ -391,14 +394,20 @@ def make_forward_mobile(con_mesh):
frag.add_uniform('sampler2DShadow shadowMapSpot[1]')
frag.write('if (spotPosition.w > 0.0) {')
frag.write(' vec3 lPos = spotPosition.xyz / spotPosition.w;')
frag.write(' visibility = texture(shadowMapSpot[0], vec3(lPos.xy, lPos.z - pointBias)).r;')
if '_Legacy' in wrd.world_defs:
frag.write(' visibility = float(texture(shadowMapSpot[0], vec2(lPos.xy)).r > lPos.z - pointBias);')
else:
frag.write(' visibility = texture(shadowMapSpot[0], vec3(lPos.xy, lPos.z - pointBias)).r;')
frag.write('}')
else:
frag.add_uniform('vec2 lightProj', link='_lightPlaneProj')
frag.add_uniform('samplerCubeShadow shadowMapPoint[1]')
frag.write('const float s = shadowmapCubePcfSize;') # TODO: incorrect...
frag.write('float compare = lpToDepth(ld - n * pointBias * 80, lightProj);')
frag.write('visibility = texture(shadowMapPoint[0], vec4(-l + n * pointBias * 80, compare)).r;')
if '_Legacy' in wrd.world_defs:
frag.write('visibility = float(texture(shadowMapPoint[0], vec3(-l + n * pointBias * 80)).r > compare);')
else:
frag.write('visibility = texture(shadowMapPoint[0], vec4(-l + n * pointBias * 80, compare)).r;')
frag.write('direct += basecol * dotNL * pointCol * attenuate(distance(wposition, pointPos)) * visibility;')

View file

@ -231,6 +231,14 @@ class Shader:
s in self.main_textures or \
s in self.main_attribs
def replace(self, old, new):
self.main = self.main.replace(old, new)
self.main_init = self.main_init.replace(old, new)
self.main_normal = self.main_normal.replace(old, new)
self.main_textures = self.main_textures.replace(old, new)
self.main_attribs = self.main_attribs.replace(old, new)
self.uniforms = [u.replace(old, new) for u in self.uniforms]
def write_init(self, s):
self.main_init = s + '\n' + self.main_init