Skip to content

Commit

Permalink
Fix #1997 (shadows on hardware-accelerated morph animations) (#2111)
Browse files Browse the repository at this point in the history
* Fix shadows for morph animations

* Set shadows to the morph test
  • Loading branch information
tonihele authored Oct 16, 2023
1 parent 88813e2 commit 231f75c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "Common/ShaderLib/GLSLCompat.glsllib"
#import "Common/ShaderLib/Instancing.glsllib"
#import "Common/ShaderLib/Skinning.glsllib"
#import "Common/ShaderLib/MorphAnim.glsllib"

uniform mat4 m_LightViewProjectionMatrix0;
uniform mat4 m_LightViewProjectionMatrix1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main(){
vec4 modelSpacePos = vec4(inPosition, 1.0);

#ifdef NUM_MORPH_TARGETS
Morph_Compute(modelSpacePos, modelSpaceNorm);
Morph_Compute(modelSpacePos);
#endif

#ifdef NUM_BONES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,17 @@

import com.jme3.anim.AnimComposer;
import com.jme3.app.*;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.*;
import com.jme3.renderer.Limits;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.*;
import com.jme3.scene.plugins.gltf.GltfModelKey;
import com.jme3.scene.shape.Quad;
import com.jme3.shadow.DirectionalLightShadowRenderer;
import com.jme3.shadow.EdgeFilteringMode;

public class TestGltfMorph extends SimpleApplication {
private Node probeNode;
Expand All @@ -50,6 +57,8 @@ public static void main(String[] args) {

@Override
public void simpleInitApp() {
rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);

probeNode = (Node) assetManager.loadModel("Scenes/defaultProbe.j3o");
rootNode.attachChild(probeNode);

Expand All @@ -59,11 +68,51 @@ public void simpleInitApp() {

flyCam.setMoveSpeed(5);
flyCam.setDragToRotate(true);
flyCam.setEnabled(false);
flyCam.setEnabled(true);
viewPort.setBackgroundColor(new ColorRGBA().setAsSrgb(0.2f, 0.2f, 0.2f, 1.0f));

setupFloor();

Vector3f lightDir = new Vector3f(-1, -1, .5f).normalizeLocal();

// To make shadows, sun
DirectionalLight dl = new DirectionalLight();
dl.setDirection(lightDir);
dl.setColor(ColorRGBA.White);
rootNode.addLight(dl);

// Add ambient light
AmbientLight al = new AmbientLight();
al.setColor(ColorRGBA.White.multLocal(0.4f));
rootNode.addLight(al);

final int SHADOWMAP_SIZE = 1024;
DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(getAssetManager(), SHADOWMAP_SIZE, 3);
dlsr.setLight(dl);
dlsr.setLambda(0.55f);
dlsr.setShadowIntensity(0.6f);
dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCF8);
getViewPort().addProcessor(dlsr);

loadModel("jme3test/morph/MorphStressTest.glb", new Vector3f(0, -1, 0), 1);
}

private void setupFloor() {
Material floorMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
floorMaterial.setColor("Diffuse", new ColorRGBA(.9f, .9f, .9f, .9f));

Node floorGeom = new Node("floorGeom");
Quad q = new Quad(20, 20);
Geometry g = new Geometry("geom", q);
g.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
g.setShadowMode(RenderQueue.ShadowMode.Receive);
floorGeom.attachChild(g);

floorGeom.setMaterial(floorMaterial);

floorGeom.move(-10f, -2f, 10f);

rootNode.attachChild(floorGeom);
}

private void loadModel(String path, Vector3f offset, float scale) {
Expand Down

0 comments on commit 231f75c

Please sign in to comment.