Skip to content

Commit

Permalink
Set shadows to the morph test
Browse files Browse the repository at this point in the history
  • Loading branch information
tonihele committed Oct 15, 2023
1 parent c051387 commit c6c70f9
Showing 1 changed file with 50 additions and 1 deletion.
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 c6c70f9

Please sign in to comment.