Basic image based lighting
This commit is contained in:
parent
ccb7ede766
commit
4cec4f5a98
|
@ -2120,17 +2120,17 @@ class ArmoryExporter(bpy.types.Operator, ExportHelper):
|
|||
c.bind_textures = []
|
||||
|
||||
tex = Object() # TODO: parse from world nodes
|
||||
tex.id = 'senvmap'
|
||||
tex.id = 'senvmapIrradiance'
|
||||
tex.name = 'envmap_irradiance'
|
||||
c.bind_textures.append(tex)
|
||||
|
||||
tex = Object() # TODO: parse from world nodes
|
||||
tex.id = 'senvmaplod'
|
||||
tex.name = 'envmap_lod1'
|
||||
tex.id = 'senvmapRadiance'
|
||||
tex.name = 'envmap_radiance'
|
||||
c.bind_textures.append(tex)
|
||||
|
||||
tex = Object() # TODO: parse from world nodes
|
||||
tex.id = 'senvmapbrdf'
|
||||
tex.id = 'senvmapBrdf'
|
||||
tex.name = 'envmap_brdf'
|
||||
c.bind_textures.append(tex)
|
||||
|
||||
|
|
|
@ -60,6 +60,32 @@ def buildNodeTree(world_name, node_group, shader_references, asset_references):
|
|||
# Add resources to khafie
|
||||
asset_references.append('compiled/ShaderResources/env_map/env_map.json')
|
||||
shader_references.append('compiled/Shaders/env_map/env_map')
|
||||
# Generate prefiltered envmaps
|
||||
#generate_envmaps()
|
||||
|
||||
with open(path + material_name + '.json', 'w') as f:
|
||||
f.write(output.to_JSON())
|
||||
|
||||
def generate_envmaps():
|
||||
if not os.path.exists('Assets/generated/envmaps'):
|
||||
os.makedirs('Assets/generated/envmaps')
|
||||
|
||||
# Get paths
|
||||
haxelib_path = "haxelib"
|
||||
if platform.system() == 'Darwin':
|
||||
haxelib_path = "/usr/local/bin/haxelib"
|
||||
|
||||
output = subprocess.check_output([haxelib_path + " path cyclesgame"], shell=True)
|
||||
output = str(output).split("\\n")[0].split("'")[1]
|
||||
cmft_path = output[:-8] + "tools/cmft/"
|
||||
|
||||
# Set dir
|
||||
s = bpy.data.filepath.split(os.path.sep)
|
||||
name = s.pop()
|
||||
name = name.split(".")
|
||||
name = name[0]
|
||||
fp = os.path.sep.join(s)
|
||||
os.chdir(fp)
|
||||
|
||||
# Generate maps
|
||||
call([cmft_path + "cmft-osx", "--input", "filename"])
|
||||
|
|
|
@ -175,7 +175,7 @@ def buildProject(self, build_type=0):
|
|||
if platform.system() == 'Darwin':
|
||||
haxelib_path = "/usr/local/bin/haxelib"
|
||||
|
||||
prefix = haxelib_path + " run kha "
|
||||
#prefix = haxelib_path + " run kha "
|
||||
|
||||
output = subprocess.check_output([haxelib_path + " path cyclesgame"], shell=True)
|
||||
output = str(output).split("\\n")[0].split("'")[1]
|
||||
|
|
|
@ -13,7 +13,7 @@ in vec3 normal;
|
|||
|
||||
vec2 envMapEquirect(vec3 normal) {
|
||||
float phi = acos(normal.z);
|
||||
float theta = atan(normal.x, normal.y) + PI;
|
||||
float theta = atan(-normal.y, normal.x) + PI;
|
||||
return vec2(theta / TwoPI, phi / PI);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,9 @@ precision mediump float;
|
|||
uniform sampler2D salbedo;
|
||||
#endif
|
||||
uniform sampler2D shadowMap;
|
||||
uniform sampler2D senvmap;
|
||||
uniform sampler2D senvmaplod;
|
||||
uniform sampler2D senvmapbrdf;
|
||||
uniform sampler2D senvmapRadiance;
|
||||
uniform sampler2D senvmapIrradiance;
|
||||
uniform sampler2D senvmapBrdf;
|
||||
#ifdef _NormalMapping
|
||||
uniform sampler2D snormal;
|
||||
#endif
|
||||
|
@ -54,9 +54,9 @@ float shadowTest(vec4 lPos, float dotNL) {
|
|||
}
|
||||
|
||||
|
||||
vec2 envMapEquirect(vec3 n) {
|
||||
float phi = acos(n.z);
|
||||
float theta = atan(n.x, n.y) + PI;
|
||||
vec2 envMapEquirect(vec3 normal) {
|
||||
float phi = acos(normal.z);
|
||||
float theta = atan(-normal.y, normal.x) + PI;
|
||||
return vec2(theta / TwoPI, phi / PI);
|
||||
}
|
||||
|
||||
|
@ -168,8 +168,9 @@ vec3 surfaceF0(vec3 baseColor, float metalness) {
|
|||
}
|
||||
|
||||
float getMipLevelFromRoughness(float roughness) {
|
||||
return 0.0;
|
||||
// First mipmap level = roughness 0, last = roughness = 1
|
||||
// 6 mipmaps + base
|
||||
return roughness * 7.0;
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
@ -182,6 +183,7 @@ void main() {
|
|||
if (lPos.w > 0.0) {
|
||||
visibility = shadowTest(lPos, dotNL);
|
||||
visibility = (visibility * 0.8) + 0.2;
|
||||
visibility = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -222,23 +224,21 @@ void main() {
|
|||
vec3 direct = diffuseBRDF(albedo, roughness, dotNV, dotNL, dotVH, dotLV) + specularBRDF(f0, roughness, dotNL, dotNH, dotNV, dotVH, dotLH);
|
||||
|
||||
// Indirect
|
||||
vec3 indirectDiffuse = texture(senvmap, envMapEquirect(n)).rgb;
|
||||
vec3 indirectDiffuse = texture(senvmapIrradiance, envMapEquirect(n)).rgb;
|
||||
indirectDiffuse = pow(indirectDiffuse, vec3(2.2)) * albedo;
|
||||
|
||||
vec3 reflectionWorld = reflect(-v, n);
|
||||
float lod = getMipLevelFromRoughness(roughness);
|
||||
//prefilteredColor = textureCube(PrefilteredEnvMap, refVec, lod)
|
||||
// vec3 prefilteredColor = textureLod(senvmaplod, envMapEquirect(reflectionWorld)).rgb;
|
||||
vec3 prefilteredColor = texture(senvmaplod, envMapEquirect(reflectionWorld)).rgb;
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld), lod).rgb;
|
||||
prefilteredColor = pow(prefilteredColor, vec3(2.2));
|
||||
//envBRDF = texture2D(BRDFIntegrationMap,vec2(roughness, ndotv)).xy
|
||||
//indirectSpecular = prefilteredColor * (specularColor * envBRDF.x + envBRDF.y)
|
||||
vec2 envBRDF = texture(senvmapbrdf, vec2(roughness, dotNV)).xy;
|
||||
vec3 indirectSpecular = prefilteredColor * (vec3(1.0) * envBRDF.x + envBRDF.y); // vec3(1.0)=specularColor
|
||||
|
||||
vec2 envBRDF = texture(senvmapBrdf, vec2(roughness, 1.0 - dotNV)).xy;
|
||||
vec3 indirectSpecular = prefilteredColor * (f0 * envBRDF.x + envBRDF.y); // f0=specularColor?
|
||||
|
||||
vec3 indirect = indirectDiffuse + indirectSpecular;
|
||||
|
||||
outColor = vec4(vec3((direct + indirect) * visibility), 1.0);
|
||||
// outColor = vec4(vec3((indirect) * visibility), 1.0);
|
||||
}
|
||||
else {
|
||||
outColor = vec4(baseColor * visibility, 1.0);
|
||||
|
|
|
@ -116,10 +116,6 @@ void main() {
|
|||
#endif
|
||||
|
||||
gl_Position = P * VM * sPos;
|
||||
|
||||
vec4 mPos = M * sPos;
|
||||
//position = mPos.xyz / mPos.w;
|
||||
position = pos;
|
||||
|
||||
#ifdef _Texturing
|
||||
texCoord = tex;
|
||||
|
@ -145,7 +141,8 @@ void main() {
|
|||
lightDir = normalize(TBN * lightDir);
|
||||
eyeDir = normalize(TBN * eyeDir);
|
||||
#else
|
||||
lightDir = (light - position);
|
||||
eyeDir = (eye - position);
|
||||
vec3 mPos = vec4(M * sPos).xyz;
|
||||
lightDir = (light - mPos);
|
||||
eyeDir = (eye - mPos);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue