Make shaders faster
This commit is contained in:
parent
20182a1e17
commit
778205e6a9
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
// #ifdef _CPos
|
||||
// uniform mat4 invVP;
|
||||
// uniform vec3 eye;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
#ifdef _IndPos
|
||||
uniform mat4 invVP;
|
||||
uniform vec3 eye;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
in vec2 pos;
|
||||
|
||||
out vec2 texCoord;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
uniform mat4 invVP;
|
||||
uniform vec3 eye;
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
uniform mat4 invP;
|
||||
|
||||
in vec2 pos;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
in vec2 pos;
|
||||
|
||||
uniform vec2 screenSize;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
in vec2 pos;
|
||||
|
||||
uniform vec2 screenSizeInv;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
uniform sampler2D colorTex;
|
||||
uniform sampler2D blendTex;
|
||||
#ifdef _Veloc
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
in vec2 pos;
|
||||
|
||||
uniform vec2 screenSizeInv;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D tex2;
|
||||
#ifdef _Veloc
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
uniform mat4 invVP;
|
||||
uniform vec3 eye;
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#version 450
|
||||
|
||||
#include "compiled.glsl"
|
||||
|
||||
uniform mat4 transpV;
|
||||
uniform mat4 invP;
|
||||
uniform mat4 invVP;
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
import os
|
||||
|
||||
def write_variant(path, name, defs, lines):
|
||||
with open(path + '/' + name, "w") as f:
|
||||
defs_written = False
|
||||
for line in lines:
|
||||
f.write(line + '\n')
|
||||
# Append defs after #version
|
||||
if defs_written == False and line.startswith('#version '):
|
||||
for d in defs:
|
||||
f.write('#define ' + d + '\n')
|
||||
defs_written = True
|
||||
|
||||
def make(base_name, json_data, fp, defs):
|
||||
shaders = []
|
||||
path = fp + '/compiled/Shaders'
|
||||
|
||||
# Go through every context shaders and gather ifdefs
|
||||
for c in json_data['contexts']:
|
||||
shader = {}
|
||||
shaders.append(shader)
|
||||
|
||||
shader['vert_name'] = c['vertex_shader'].split('.', 1)[0]
|
||||
with open(c['vertex_shader']) as f:
|
||||
shader['vert'] = f.read().splitlines()
|
||||
|
||||
shader['frag_name'] = c['fragment_shader'].split('.', 1)[0]
|
||||
with open(c['fragment_shader']) as f:
|
||||
shader['frag'] = f.read().splitlines()
|
||||
|
||||
if 'geometry_shader' in c:
|
||||
shader['geom_name'] = c['geometry_shader'].split('.', 1)[0]
|
||||
with open(c['geometry_shader']) as f:
|
||||
shader['geom'] = f.read().splitlines()
|
||||
|
||||
if 'tesscontrol_shader' in c:
|
||||
shader['tesc_name'] = c['tesscontrol_shader'].split('.', 1)[0]
|
||||
with open(c['tesscontrol_shader']) as f:
|
||||
shader['tesc'] = f.read().splitlines()
|
||||
|
||||
if 'tesseval_shader' in c:
|
||||
shader['tese_name'] = c['tesseval_shader'].split('.', 1)[0]
|
||||
with open(c['tesseval_shader']) as f:
|
||||
shader['tese'] = f.read().splitlines()
|
||||
|
||||
for shader in shaders:
|
||||
write_variant(path, c['vertex_shader'].split('/')[-1], defs, shader['vert'])
|
||||
write_variant(path, c['fragment_shader'].split('/')[-1], defs, shader['frag'])
|
||||
if 'geom' in shader:
|
||||
write_variant(path, c['geometry_shader'].split('/')[-1], defs, shader['geom'])
|
||||
if 'tesc' in shader:
|
||||
write_variant(path, c['tesscontrol_shader'].split('/')[-1], defs, shader['tesc'])
|
||||
if 'tese' in shader:
|
||||
write_variant(path, c['tesseval_shader'].split('/')[-1], defs, shader['tese'])
|
|
@ -18,7 +18,6 @@ import arm.make_state as state
|
|||
import arm.assets as assets
|
||||
import arm.log as log
|
||||
import arm.lib.make_datas
|
||||
import arm.lib.make_variants
|
||||
import arm.lib.server
|
||||
from arm.exporter import ArmoryExporter
|
||||
import time
|
||||
|
@ -43,7 +42,12 @@ def compile_shader_pass(res, raw_shaders_path, shader_name, defs):
|
|||
|
||||
fp = arm.utils.get_fp_build()
|
||||
arm.lib.make_datas.make(res, shader_name, json_data, fp, defs)
|
||||
arm.lib.make_variants.make(shader_name, json_data, fp, defs)
|
||||
|
||||
path = fp + '/compiled/Shaders'
|
||||
c = json_data['contexts'][0]
|
||||
for s in ['vertex_shader', 'fragment_shader', 'geometry_shader', 'tesscontrol_shader', 'tesseval_shader']:
|
||||
if s in c:
|
||||
shutil.copy(c[s], path + '/' + c[s].split('/')[-1])
|
||||
|
||||
def remove_readonly(func, path, excinfo):
|
||||
os.chmod(path, stat.S_IWRITE)
|
||||
|
@ -141,8 +145,12 @@ def export_data(fp, sdk_path, is_play=False, is_publish=False, in_viewport=False
|
|||
print('Exported modules: ' + str(modules))
|
||||
|
||||
defs = arm.utils.def_strings_to_array(wrd.world_defs)
|
||||
cdefs = arm.utils.def_strings_to_array(wrd.compo_defs)
|
||||
print('Shader flags: ' + str(defs))
|
||||
|
||||
# Write compiled.glsl
|
||||
write_data.write_compiledglsl(defs + cdefs)
|
||||
|
||||
# Write referenced shader passes
|
||||
path = build_dir + '/compiled/Shaders'
|
||||
if not os.path.isfile(build_dir + '/compiled/Shaders/shader_datas.arm') or state.last_world_defs != wrd.world_defs:
|
||||
|
@ -157,7 +165,6 @@ def export_data(fp, sdk_path, is_play=False, is_publish=False, in_viewport=False
|
|||
continue
|
||||
assets.shader_passes_assets[ref] = []
|
||||
if ref.startswith('compositor_pass'):
|
||||
cdefs = arm.utils.def_strings_to_array(wrd.compo_defs)
|
||||
compile_shader_pass(res, raw_shaders_path, ref, defs + cdefs)
|
||||
# elif ref.startswith('grease_pencil'):
|
||||
# compile_shader_pass(res, raw_shaders_path, ref, [])
|
||||
|
@ -181,9 +188,6 @@ def export_data(fp, sdk_path, is_play=False, is_publish=False, in_viewport=False
|
|||
if not os.path.isdir(build_dir + '/compiled/Shaders/std'):
|
||||
shutil.copytree(raw_shaders_path + 'std', build_dir + '/compiled/Shaders/std')
|
||||
|
||||
# Write compiled.glsl
|
||||
write_data.write_compiledglsl()
|
||||
|
||||
# Write khafile.js
|
||||
enable_dce = is_publish and wrd.arm_dce
|
||||
import_logic = not is_publish and arm.utils.logic_editor_space() != None
|
||||
|
|
|
@ -88,6 +88,7 @@ project.addSources('Sources');
|
|||
ammojs_path = sdk_path + '/lib/haxebullet/js/ammo/ammo.js'
|
||||
ammojs_path = ammojs_path.replace('\\', '/')
|
||||
f.write(add_assets(ammojs_path))
|
||||
# haxe.macro.Compiler.includeFile(ammojs_path)
|
||||
elif wrd.arm_physics == 'Oimo':
|
||||
assets.add_khafile_def('arm_oimo')
|
||||
if not os.path.exists('Libraries/oimo'):
|
||||
|
@ -393,7 +394,7 @@ def write_indexhtml(w, h, is_publish):
|
|||
</html>
|
||||
""")
|
||||
|
||||
def write_compiledglsl():
|
||||
def write_compiledglsl(defs):
|
||||
wrd = bpy.data.worlds['Arm']
|
||||
rpdat = arm.utils.get_rp()
|
||||
shadowmap_size = 0
|
||||
|
@ -403,7 +404,10 @@ def write_compiledglsl():
|
|||
f.write(
|
||||
"""#ifndef _COMPILED_GLSL_
|
||||
#define _COMPILED_GLSL_
|
||||
const float PI = 3.1415926535;
|
||||
""")
|
||||
for d in defs:
|
||||
f.write("#define " + d + "\n")
|
||||
f.write("""const float PI = 3.1415926535;
|
||||
const float PI2 = PI * 2.0;
|
||||
const vec2 shadowmapSize = vec2(""" + str(shadowmap_size) + """, """ + str(shadowmap_size) + """);
|
||||
const float shadowmapCubePcfSize = """ + str(round(wrd.arm_pcfsize * 10000) / 10000) + """;
|
||||
|
|
Loading…
Reference in a new issue