diff --git a/assets/DMonkey/AmbientLight.j3md b/assets/DMonkey/AmbientLight.j3md index e99ce23..02b8d00 100644 --- a/assets/DMonkey/AmbientLight.j3md +++ b/assets/DMonkey/AmbientLight.j3md @@ -5,9 +5,7 @@ MaterialDef AmbientLight { Texture2D DepthBuffer Texture2D NormalBuffer Texture2D DiffuseBuffer - Vector3 LightDir - Vector4Array DirectionalColors - Vector3Array Directions + Vector3 ViewLightDir Float LightIntensity Int DirectionalLights diff --git a/assets/DMonkey/Shaders/AmbientLight.frag b/assets/DMonkey/Shaders/AmbientLight.frag index 042a52b..e95bde1 100644 --- a/assets/DMonkey/Shaders/AmbientLight.frag +++ b/assets/DMonkey/Shaders/AmbientLight.frag @@ -1,25 +1,38 @@ #define SPECULAR +#define GAMMA_CORRECT #import "DMonkey/Shaders/DM_Light.glsllib" uniform vec4 m_Color; uniform float m_LightIntensity; -uniform vec3 m_LightDir; +uniform vec3 m_ViewLightDir; const vec3 lightDirection = vec3(0.1, 0.3, 0.0); const float GAMMA = 2.2; - +vec3 FilmicMain(vec3 texColor){ + float range = 0.2; + texColor *= range; + vec3 x = max(vec3(0.0),texColor-0.004); // Filmic Curve + vec3 retColor = (x*(6.2*x+0.5))/(x*(6.2*x+1.7)+0.06); + return retColor; +} void main() { dm_decode(); + + vec3 albedo = GBuffer.albedo; + #ifdef GAMMA_CORRECT + albedo = gamma(GBuffer.albedo, GAMMA); + #endif + - vec3 lightDir = normalize((g_ViewMatrix * vec4(m_LightDir, 0.0)).xyz); - //lightDir = normalize(m_LightDir); - vec3 albedo = gamma(GBuffer.albedo, GAMMA); - - Light light = Light(vec4(gamma(m_Color.rgb, GAMMA), 0.0), vec3(0.0), lightDir); + Light light = Light(vec4(gamma(m_Color.rgb, GAMMA), 0.0), vec3(0.0), m_ViewLightDir); vec4 color = ComputeLighting(light); color += vec4(0.05, 0.05, 0.1, 0.0); - gl_FragColor.rgb = albedo * color.rgb; + gl_FragColor.rgb = albedo * color.rgb * 1.5; + + //gl_FragColor.rgb = FilmicMain(gl_FragColor.rgb); + #ifdef GAMMA_CORRECT gl_FragColor.rgb = gamma(gl_FragColor.rgb, 1.0 / GAMMA); + #endif } diff --git a/assets/Materials/Generated/test_object-test_object_geom_0.j3m b/assets/Materials/Generated/test_object-test_object_geom_0.j3m deleted file mode 100644 index ac05292..0000000 --- a/assets/Materials/Generated/test_object-test_object_geom_0.j3m +++ /dev/null @@ -1,17 +0,0 @@ -Material MyMaterial : Common/MatDefs/Light/Lighting.j3md { - MaterialParameters { - ParallaxHeight : 0.05 - Shininess : 64.0 - } - AdditionalRenderState { - FaceCull Back - Wireframe Off - DepthWrite On - PolyOffset 0.0 0.0 - AlphaTestFalloff 0.0 - Blend Off - PointSprite Off - ColorWrite On - DepthTest On - } -} diff --git a/src/me/merciless/dmonkey3/DeferredRenderState.java b/src/me/merciless/dmonkey3/DeferredRenderState.java index 0a2d279..1a9c5f0 100644 --- a/src/me/merciless/dmonkey3/DeferredRenderState.java +++ b/src/me/merciless/dmonkey3/DeferredRenderState.java @@ -5,6 +5,7 @@ import com.jme3.app.state.AppStateManager; import com.jme3.math.ColorRGBA; import com.jme3.post.FilterPostProcessor; +import com.jme3.post.filters.FXAAFilter; import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; import com.jme3.renderer.ViewPort; diff --git a/src/me/merciless/dmonkey3/LightRenderer.java b/src/me/merciless/dmonkey3/LightRenderer.java index bc753b9..e96a232 100644 --- a/src/me/merciless/dmonkey3/LightRenderer.java +++ b/src/me/merciless/dmonkey3/LightRenderer.java @@ -4,7 +4,9 @@ import com.jme3.light.DirectionalLight; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; +import com.jme3.math.Matrix4f; import com.jme3.math.Vector3f; +import com.jme3.math.Vector4f; import com.jme3.post.SceneProcessor; import com.jme3.renderer.Camera; import com.jme3.renderer.RenderManager; @@ -94,7 +96,13 @@ public void postQueue(RenderQueue rq) { public void postFrame(FrameBuffer out) { updateMaterial(); vsLightDir.set(camera.getViewMatrix().mult(dl.getDirection().normalizeLocal()).normalize()); - material.setVector3("LightDir", dl.getDirection()); + + Vector3f vec3 = dl.getDirection(); + Vector4f vec4 = new Vector4f(vec3.x, vec3.y, vec3.z, 0); + camera.getViewMatrix().mult(vec4, vec4); + + vec3 = new Vector3f(vec4.x, vec4.y, vec4.z); + material.setVector3("ViewLightDir", vec3); renderManager.getRenderer().setFrameBuffer(null); renderManager.getRenderer().clearBuffers(true, true, true); renderManager.renderGeometry(fullscreenQuad); diff --git a/src/me/merciless/dmonkey3/TestCase.java b/src/me/merciless/dmonkey3/TestCase.java index 3fdf049..9581b60 100644 --- a/src/me/merciless/dmonkey3/TestCase.java +++ b/src/me/merciless/dmonkey3/TestCase.java @@ -11,6 +11,7 @@ import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; import com.jme3.scene.Geometry; +import com.jme3.scene.Spatial; import com.jme3.scene.shape.Box; import com.jme3.system.AppSettings; import com.jme3.texture.Texture; @@ -66,6 +67,11 @@ public void simpleInitApp() { ((Texture)(groundPlane.getMaterial().getTextureParam("NormalTex").getValue())).setWrap(Texture.WrapMode.Repeat); deferred.getRootNode().attachChild(groundPlane); + + Spatial spat = assetManager.loadModel("Models/Tracy/Tracy.j3o"); + //spat.setMaterial(cylinder.getMaterial()); + spat.move(-2, -2, 1); + deferred.getRootNode().attachChild(spat); } public static void main(String[] arg) {