Normal maps
This commit is contained in:
parent
e44d9aa8a9
commit
63620fd767
|
@ -4,18 +4,20 @@ precision mediump float;
|
|||
|
||||
uniform sampler2D stex;
|
||||
uniform sampler2D shadowMap;
|
||||
uniform sampler2D normalMap;
|
||||
uniform bool texturing;
|
||||
uniform bool lighting;
|
||||
uniform bool receiveShadow;
|
||||
uniform vec3 light;
|
||||
uniform vec3 eye;
|
||||
uniform float roughness;
|
||||
uniform bool normalMapping;
|
||||
|
||||
varying vec3 position;
|
||||
varying vec2 texCoord;
|
||||
varying vec3 normal;
|
||||
varying vec4 lPos;
|
||||
varying vec4 matColor;
|
||||
varying vec3 lightDir;
|
||||
varying vec3 eyeDir;
|
||||
|
||||
float shadowSimple(vec4 lPos) {
|
||||
|
||||
|
@ -99,12 +101,17 @@ void kore() {
|
|||
float specular = 0.1;
|
||||
|
||||
vec3 n = normalize(normal);
|
||||
vec3 l = light - position;
|
||||
l = normalize(l);
|
||||
vec3 v = eye - position;
|
||||
v = normalize(v);
|
||||
vec3 l = lightDir;
|
||||
vec3 v = eyeDir;
|
||||
|
||||
float dotNL = clamp(dot(n, l), 0.0, 1.0);
|
||||
float dotNL = 0.0;
|
||||
if (normalMapping) {
|
||||
vec3 tn = normalize(texture2D(normalMap, vec2(texCoord.x, 1.0 - texCoord.y)).rgb * 2.0 - 1.0);
|
||||
dotNL = clamp(dot(tn, l), 0.0, 1.0); //-l ?
|
||||
}
|
||||
else {
|
||||
dotNL = clamp(dot(n, l), 0.0, 1.0);
|
||||
}
|
||||
|
||||
float spec = LightingFuncGGX_OPT3(n, v, l, roughness, specular);
|
||||
vec3 rgb = spec + t * dotNL;
|
||||
|
|
|
@ -6,18 +6,31 @@ attribute vec3 pos;
|
|||
attribute vec2 tex;
|
||||
attribute vec3 nor;
|
||||
attribute vec4 col;
|
||||
attribute vec3 tan;
|
||||
attribute vec3 bitan;
|
||||
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 lightMVP;
|
||||
uniform vec4 diffuseColor;
|
||||
uniform bool normalMapping;
|
||||
uniform vec3 light;
|
||||
uniform vec3 eye;
|
||||
|
||||
varying vec3 position;
|
||||
varying vec2 texCoord;
|
||||
varying vec3 normal;
|
||||
varying vec4 lPos;
|
||||
varying vec4 matColor;
|
||||
varying vec3 lightDir;
|
||||
varying vec3 eyeDir;
|
||||
|
||||
mat3 transpose(mat3 m) {
|
||||
return mat3(m[0][0], m[1][0], m[2][0],
|
||||
m[0][1], m[1][1], m[2][1],
|
||||
m[0][2], m[1][2], m[2][2]);
|
||||
}
|
||||
|
||||
void kore() {
|
||||
|
||||
|
@ -30,4 +43,16 @@ void kore() {
|
|||
lPos = lightMVP * vec4(pos, 1.0);
|
||||
|
||||
matColor = diffuseColor * col;
|
||||
|
||||
lightDir = normalize(light - position);
|
||||
eyeDir = normalize(eye - position);
|
||||
|
||||
if (normalMapping == true) {
|
||||
vec3 vTangent = tan;
|
||||
vec3 vBitangent = bitan;
|
||||
|
||||
mat3 TBN = transpose(mat3(vTangent, vBitangent, normal));
|
||||
lightDir = normalize(TBN * lightDir);
|
||||
eyeDir = normalize(TBN * eyeDir);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ def build():
|
|||
kha_path = output
|
||||
node_path = output + "/Tools/nodejs/node-osx"
|
||||
|
||||
os.system(node_path + " " + kha_path + "/make -t html5 --haxe " + haxePath())
|
||||
os.system(bashCommand + " --nokrafix")
|
||||
#os.system(node_path + " " + kha_path + "/make -t html5 --haxe " + haxePath())
|
||||
#print(subprocess.check_output([node_path + " " + kha_path + "/make -t html5 --haxe " + haxePath()], shell=True))
|
||||
|
||||
# Copy ammo.js if necessary
|
||||
|
|
|
@ -34,6 +34,7 @@ bl_info = {
|
|||
|
||||
import bpy
|
||||
import math
|
||||
from mathutils import *
|
||||
import json
|
||||
from bpy_extras.io_utils import ExportHelper
|
||||
|
||||
|
@ -1652,6 +1653,50 @@ class LueExporter(bpy.types.Operator, ExportHelper):
|
|||
ia.material = self.WriteInt(m)
|
||||
om.index_arrays.append(ia)
|
||||
|
||||
# Export tangents
|
||||
# TODO: check for proper texture coords and if normal map is applied
|
||||
if (len(exportMesh.uv_textures) > 0):
|
||||
# exportMesh.calc_tangents() # TODO: use to export tangents
|
||||
ia = om.index_arrays[0].values
|
||||
posa = pa.values
|
||||
uva = ta.values
|
||||
tangents = []
|
||||
bitangents = []
|
||||
#print(node.name)
|
||||
for i in range(0, int(len(ia) / 3)):
|
||||
i0 = ia[i * 3 + 0]
|
||||
i1 = ia[i * 3 + 1]
|
||||
i2 = ia[i * 3 + 2]
|
||||
v0 = Vector((posa[i0 * 3 + 0], posa[i0 * 3 + 1], posa[i0 * 3 + 2]))
|
||||
v1 = Vector((posa[i1 * 3 + 0], posa[i1 * 3 + 1], posa[i1 * 3 + 2]))
|
||||
v2 = Vector((posa[i2 * 3 + 0], posa[i2 * 3 + 1], posa[i2 * 3 + 2]))
|
||||
uv0 = Vector((uva[i0 * 2 + 0], uva[i0 * 2 + 1]))
|
||||
uv1 = Vector((uva[i1 * 2 + 0], uva[i1 * 2 + 1]))
|
||||
uv2 = Vector((uva[i2 * 2 + 0], uva[i2 * 2 + 1]))
|
||||
deltaPos1 = v1 - v0
|
||||
deltaPos2 = v2 - v0
|
||||
deltaUV1 = uv1 - uv0
|
||||
deltaUV2 = uv2 - uv0
|
||||
r = 1.0 / (deltaUV1.x * deltaUV2.y - deltaUV1.y * deltaUV2.x);
|
||||
tangent = (deltaPos1 * deltaUV2.y - deltaPos2 * deltaUV1.y) * r;
|
||||
bitangent = (deltaPos2 * deltaUV1.x - deltaPos1 * deltaUV2.x) * r;
|
||||
tangents.append(tangent.x)
|
||||
tangents.append(tangent.y)
|
||||
tangents.append(tangent.z)
|
||||
bitangents.append(bitangent.x)
|
||||
bitangents.append(bitangent.y)
|
||||
bitangents.append(bitangent.z)
|
||||
tana = Object()
|
||||
tana.attrib = "tangent"
|
||||
tana.size = 3
|
||||
tana.values = tangents
|
||||
om.vertex_arrays.append(tana)
|
||||
btana = Object()
|
||||
btana.attrib = "bitangent"
|
||||
btana.size = 3
|
||||
btana.values = bitangents
|
||||
om.vertex_arrays.append(btana)
|
||||
|
||||
# If the mesh is skinned, export the skinning data here.
|
||||
|
||||
if (armature):
|
||||
|
|
Loading…
Reference in a new issue