Fixed binormal calculation in Single pass lighting

cleanup_build_scripts
Nehon 9 years ago
parent 2bdb3de2f5
commit 07088452ff
  1. 5
      jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag
  2. 6
      jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert
  3. 100
      jme3-examples/src/main/java/jme3test/light/TestTangentSpace.java
  4. 46
      jme3-testdata/src/main/resources/Models/Test/BasicCubeLow.obj
  5. BIN
      jme3-testdata/src/main/resources/Models/Test/Normal_pixel.png

@ -41,8 +41,7 @@ varying vec3 SpecularSum;
#ifdef NORMALMAP #ifdef NORMALMAP
uniform sampler2D m_NormalMap; uniform sampler2D m_NormalMap;
varying vec3 vTangent; varying vec4 vTangent;
varying vec3 vBinormal;
#endif #endif
varying vec3 vNormal; varying vec3 vNormal;
@ -71,7 +70,7 @@ uniform float m_Shininess;
void main(){ void main(){
#if !defined(VERTEX_LIGHTING) #if !defined(VERTEX_LIGHTING)
#if defined(NORMALMAP) #if defined(NORMALMAP)
mat3 tbnMat = mat3(normalize(vTangent.xyz) , normalize(vBinormal.xyz) , normalize(vNormal.xyz)); mat3 tbnMat = mat3(vTangent.xyz, vTangent.w * cross( (vNormal), (vTangent.xyz)), vNormal.xyz);
if (!gl_FrontFacing) if (!gl_FrontFacing)
{ {

@ -39,8 +39,7 @@ attribute vec3 inNormal;
varying vec3 vPos; varying vec3 vPos;
#ifdef NORMALMAP #ifdef NORMALMAP
attribute vec4 inTangent; attribute vec4 inTangent;
varying vec3 vTangent; varying vec4 vTangent;
varying vec3 vBinormal;
#endif #endif
#else #else
#ifdef COLORRAMP #ifdef COLORRAMP
@ -104,8 +103,7 @@ void main(){
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING) #if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
vTangent = TransformNormal(modelSpaceTan); vTangent = vec4(TransformNormal(modelSpaceTan).xyz,inTangent.w);
vBinormal = cross(wvNormal, vTangent)* inTangent.w;
vNormal = wvNormal; vNormal = wvNormal;
vPos = wvPosition; vPos = wvPosition;
#elif !defined(VERTEX_LIGHTING) #elif !defined(VERTEX_LIGHTING)

@ -0,0 +1,100 @@
package jme3test.light;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.*;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.util.TangentBinormalGenerator;
import com.jme3.util.mikktspace.MikktspaceTangentGenerator;
/**
* test
*
* @author normenhansen
*/
public class TestTangentSpace extends SimpleApplication {
public static void main(String[] args) {
TestTangentSpace app = new TestTangentSpace();
app.start();
}
private Node debugNode = new Node("debug");
@Override
public void simpleInitApp() {
renderManager.setSinglePassLightBatchSize(2);
renderManager.setPreferredLightMode(TechniqueDef.LightMode.SinglePass);
initView();
Spatial s = assetManager.loadModel("Models/Test/BasicCubeLow.obj");
rootNode.attachChild(s);
Material m = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
m.setTexture("NormalMap", assetManager.loadTexture("Models/Test/Normal_pixel.png"));
Geometry g = (Geometry)s;
Geometry g2 = (Geometry) g.deepClone();
g2.move(5, 0, 0);
g.getParent().attachChild(g2);
g.setMaterial(m);
g2.setMaterial(m);
//Regular tangent generation (left geom)
TangentBinormalGenerator.generate(g2.getMesh(), true);
//MikkTSPace Tangent generation (right geom)
MikktspaceTangentGenerator.generate(g);
createDebugTangents(g2);
createDebugTangents(g);
inputManager.addListener(new ActionListener() {
@Override
public void onAction(String name, boolean isPressed, float tpf) {
if (name.equals("toggleDebug") && isPressed) {
if (debugNode.getParent() == null) {
rootNode.attachChild(debugNode);
} else {
debugNode.removeFromParent();
}
}
}
}, "toggleDebug");
inputManager.addMapping("toggleDebug", new KeyTrigger(KeyInput.KEY_SPACE));
DirectionalLight dl = new DirectionalLight(new Vector3f(-1, -1, -1).normalizeLocal());
rootNode.addLight(dl);
}
private void initView() {
viewPort.setBackgroundColor(ColorRGBA.DarkGray);
cam.setLocation(new Vector3f(8.569681f, 3.335546f, 5.4372444f));
cam.setRotation(new Quaternion(-0.07608022f, 0.9086564f, -0.18992864f, -0.3639813f));
flyCam.setMoveSpeed(10);
}
private void createDebugTangents(Geometry geom) {
Geometry debug = new Geometry(
"Debug " + geom.getName(),
TangentBinormalGenerator.genTbnLines(geom.getMesh(), 0.8f)
);
Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
debug.setMaterial(debugMat);
debug.setCullHint(Spatial.CullHint.Never);
debug.getLocalTranslation().set(geom.getWorldTranslation());
debugNode.attachChild(debug);
}
}

@ -0,0 +1,46 @@
# Blender v2.76 (sub 0) OBJ File: 'BasicCube.blend'
# www.blender.org
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vt 0.500000 0.250043
vt 0.749957 0.250043
vt 0.749957 0.500000
vt 0.000087 0.500000
vt 0.000087 0.250043
vt 0.250043 0.250043
vt 0.250043 0.500000
vt 0.250043 0.000087
vt 0.500000 0.000087
vt 0.999913 0.250043
vt 0.999913 0.500000
vt 0.500000 0.500000
vt 0.500000 0.749957
vt 0.250044 0.749957
vn 0.577300 -0.577300 0.577300
vn -0.577300 -0.577300 0.577300
vn -0.577300 -0.577300 -0.577300
vn -0.577300 0.577300 -0.577300
vn -0.577300 0.577300 0.577300
vn 0.577300 0.577300 0.577300
vn 0.577300 0.577300 -0.577300
vn 0.577300 -0.577300 -0.577300
s 1
f 2/1/1 3/2/2 4/3/3
f 8/4/4 7/5/5 6/6/6
f 5/7/7 6/6/6 2/1/1
f 6/6/6 7/8/5 3/9/2
f 3/2/2 7/10/5 8/11/4
f 1/12/8 4/13/3 8/14/4
f 1/12/8 2/1/1 4/3/3
f 5/7/7 8/4/4 6/6/6
f 1/12/8 5/7/7 2/1/1
f 2/1/1 6/6/6 3/9/2
f 4/3/3 3/2/2 8/11/4
f 5/7/7 1/12/8 8/14/4

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Loading…
Cancel
Save