From 21179dc132175d23ae0cd63787c483364500dbe7 Mon Sep 17 00:00:00 2001 From: Nehon Date: Wed, 18 Feb 2015 20:39:45 +0100 Subject: [PATCH] Changed standard lighting to blinn phong instead of phong only --- .../resources/Common/MatDefs/Light/Lighting.frag | 2 +- .../resources/Common/MatDefs/Light/Lighting.vert | 2 +- .../Common/MatDefs/Light/SPLighting.frag | 2 +- .../Common/MatDefs/Light/SPLighting.vert | 2 +- ...ghting.glsllib => BlinnPhongLighting.glsllib} | 16 +++++++++++++--- .../java/jme3test/light/TestSimpleLighting.java | 14 +++++++++++++- 6 files changed, 30 insertions(+), 8 deletions(-) rename jme3-core/src/main/resources/Common/ShaderLib/{PhongLighting.glsllib => BlinnPhongLighting.glsllib} (70%) diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag index a1f58b898..107597047 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.frag @@ -1,7 +1,7 @@ #import "Common/ShaderLib/Parallax.glsllib" #import "Common/ShaderLib/Optics.glsllib" #ifndef VERTEX_LIGHTING - #import "Common/ShaderLib/PhongLighting.glsllib" + #import "Common/ShaderLib/BlinnPhongLighting.glsllib" #import "Common/ShaderLib/Lighting.glsllib" #endif diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert index 1901ebc67..3ee6f38c6 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert @@ -2,7 +2,7 @@ #import "Common/ShaderLib/Skinning.glsllib" #import "Common/ShaderLib/Lighting.glsllib" #ifdef VERTEX_LIGHTING - #import "Common/ShaderLib/PhongLighting.glsllib" + #import "Common/ShaderLib/BlinnPhongLighting.glsllib" #endif diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag index 7a0706507..c8471b0b9 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag @@ -1,7 +1,7 @@ #import "Common/ShaderLib/Parallax.glsllib" #import "Common/ShaderLib/Optics.glsllib" #ifndef VERTEX_LIGHTING - #import "Common/ShaderLib/PhongLighting.glsllib" + #import "Common/ShaderLib/BlinnPhongLighting.glsllib" #import "Common/ShaderLib/Lighting.glsllib" #endif diff --git a/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert index 81ea869b6..1303aa2b6 100644 --- a/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert +++ b/jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert @@ -2,7 +2,7 @@ #import "Common/ShaderLib/Skinning.glsllib" #import "Common/ShaderLib/Lighting.glsllib" #ifdef VERTEX_LIGHTING - #import "Common/ShaderLib/PhongLighting.glsllib" + #import "Common/ShaderLib/BlinnPhongLighting.glsllib" #endif diff --git a/jme3-core/src/main/resources/Common/ShaderLib/PhongLighting.glsllib b/jme3-core/src/main/resources/Common/ShaderLib/BlinnPhongLighting.glsllib similarity index 70% rename from jme3-core/src/main/resources/Common/ShaderLib/PhongLighting.glsllib rename to jme3-core/src/main/resources/Common/ShaderLib/BlinnPhongLighting.glsllib index 8ebeb9924..76d881a9a 100644 --- a/jme3-core/src/main/resources/Common/ShaderLib/PhongLighting.glsllib +++ b/jme3-core/src/main/resources/Common/ShaderLib/BlinnPhongLighting.glsllib @@ -1,20 +1,30 @@ -/*Standard Phong ligting*/ +/*Blinn Phong ligting*/ /* -* Computes diffuse factor +* Computes diffuse factor (Lambert) */ float lightComputeDiffuse(in vec3 norm, in vec3 lightdir){ return max(0.0, dot(norm, lightdir)); } /* -* Computes specular factor +* Computes specular factor (blinn phong) */ float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){ + vec3 H = normalize(viewdir + lightdir); + float HdotN = max(0.0, dot(H, norm)); + return pow(HdotN, shiny); +} + +/* +*Computes standard phong specular lighting +*/ +float lightComputeSpecularPhong(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){ vec3 R = reflect(-lightdir, norm); return pow(max(dot(R, viewdir), 0.0), shiny); } + /* * Computes diffuse and specular factors and pack them in a vec2 (x=diffuse, y=specular) */ diff --git a/jme3-examples/src/main/java/jme3test/light/TestSimpleLighting.java b/jme3-examples/src/main/java/jme3test/light/TestSimpleLighting.java index 2f1cd3403..840aa2f6e 100644 --- a/jme3-examples/src/main/java/jme3test/light/TestSimpleLighting.java +++ b/jme3-examples/src/main/java/jme3test/light/TestSimpleLighting.java @@ -38,9 +38,11 @@ import com.jme3.light.PointLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; +import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; import com.jme3.scene.shape.Sphere; +import com.jme3.util.MaterialDebugAppState; import com.jme3.util.TangentBinormalGenerator; public class TestSimpleLighting extends SimpleApplication { @@ -62,8 +64,10 @@ public class TestSimpleLighting extends SimpleApplication { teapot.setLocalScale(2f); Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); // mat.selectTechnique("GBuf"); - mat.setFloat("Shininess", 12); + mat.setFloat("Shininess", 25); mat.setBoolean("UseMaterialColors", true); + cam.setLocation(new Vector3f(0.015041917f, 0.4572918f, 5.2874837f)); + cam.setRotation(new Quaternion(-1.8875003E-4f, 0.99882424f, 0.04832061f, 0.0039016632f)); // mat.setTexture("ColorRamp", assetManager.loadTexture("Textures/ColorRamp/cloudy.png")); // @@ -95,6 +99,14 @@ public class TestSimpleLighting extends SimpleApplication { dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal()); dl.setColor(ColorRGBA.Green); rootNode.addLight(dl); + + + MaterialDebugAppState debug = new MaterialDebugAppState(); + debug.registerBinding("Common/ShaderLib/BlinnPhongLighting.glsllib", teapot); + stateManager.attach(debug); + setPauseOnLostFocus(false); + flyCam.setDragToRotate(true); + } @Override