Ryan McDonough пре 16 часа
родитељ
комит
dcf0f0dad6

+ 220 - 0
jme3-examples/src/main/java/jme3test/effect/NoiseVectorEffectTest.java

@@ -0,0 +1,220 @@
+package jme3test.effect;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.light.PointLight;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.FastMath;
+import com.jme3.math.FastNoiseLite;
+import com.jme3.math.FastNoiseLite.NoiseType;
+import com.jme3.math.Vector2f;
+import com.jme3.post.FilterPostProcessor;
+import com.jme3.post.filters.BloomFilter;
+import com.jme3.scene.Geometry;
+import com.jme3.scene.shape.Quad;
+import com.jme3.scene.shape.Sphere;
+import com.jme3.system.AppSettings;
+import com.jme3.vectoreffect.NoiseVectorEffect;
+import com.jme3.vectoreffect.VectorEffectManagerState;
+import com.jme3.vectoreffect.VectorGroup;
+import com.jme3.vectoreffect.VectorSupplier;
+
+public class NoiseVectorEffectTest extends SimpleApplication {
+
+    private ColorRGBA colorToShift  = new ColorRGBA(0.0f, 0.0f, 1.0f, 1.0f);;
+    
+    private VectorEffectManagerState vectorEffectManagerState;    
+    private PointLight light;
+    
+    private Vector2f lightRadiusVector = new Vector2f();
+    
+    public static void main(String[] args) {
+        NoiseVectorEffectTest app = new NoiseVectorEffectTest();
+        AppSettings settings = new AppSettings(true);
+        app.setSettings(settings);
+        app.start();
+    }
+   
+
+    @Override
+    public void simpleInitApp() {
+        flyCam.setMoveSpeed(10f);
+        
+        vectorEffectManagerState = new VectorEffectManagerState();
+        stateManager.attach(vectorEffectManagerState);
+        
+        initBloom();
+        initPbrRoom(13);
+        
+        initLightAndEmissiveSphere();
+        initShakingSphere();
+        
+        lightRadiusVector.setX(light.getRadius());
+    
+     //initiate VectorEffectManagerState    
+        vectorEffectManagerState = new VectorEffectManagerState();
+        stateManager.attach(vectorEffectManagerState);
+        vectorEffectManagerState.setEnabled(true);        
+
+    //create noise effect : 
+        VectorGroup vectorsToModify = new VectorGroup(VectorSupplier.of(colorToShift), VectorSupplier.of(lightRadiusVector));
+        VectorGroup noiseMagnitudes = new VectorGroup(colorToShift.toVector4f().negate());
+        
+        NoiseVectorEffect noiseVectorEffect = new NoiseVectorEffect(vectorsToModify, noiseMagnitudes);
+        
+        noiseVectorEffect.getNoiseGenerator().SetFrequency(0.95f); // Determines the overall scale of the noise. Higher values produce more detailed, rapidly changing patterns. Lower values produce larger, smoother patterns.
+        
+    //choose a noise type:
+        noiseVectorEffect.getNoiseGenerator().SetNoiseType(NoiseType.Cellular);  // Produces organic cell patterns
+      //  noiseVectorEffect.getNoiseGenerator().SetNoiseType(NoiseType.OpenSimplex2);  // Smooth, continuous noise, less directional artifacts than Perlin. 
+      //  noiseVectorEffect.getNoiseGenerator().SetNoiseType(NoiseType.OpenSimplex2S); // Variant of OpenSimplex2 with slightly sharper features. Similar smooth natural noise.
+      //  noiseVectorEffect.getNoiseGenerator().SetNoiseType(NoiseType.Perlin);       // Classic Perlin noise. Smooth gradient noise, can show directional artifacts in some cases.
+      //  noiseVectorEffect.getNoiseGenerator().SetNoiseType(NoiseType.Value);        // Piecewise linear noise. Blockier, grid-like structures, less smooth.
+      //  noiseVectorEffect.getNoiseGenerator().SetNoiseType(NoiseType.ValueCubic);   // Smooth interpolation of Value noise. Smoother than plain Value noise, less natural than simplex types.
+
+    // (optional) choose a fractal type for more detail/complexity/chaos
+        noiseVectorEffect.getNoiseGenerator().SetFractalType(FastNoiseLite.FractalType.Ridged); // Produces sharp ridges and high-contrast peaks.
+      //  noiseVectorEffect.getNoiseGenerator().SetFractalType(FastNoiseLite.FractalType.DomainWarpIndependent);  // Applies domain warping independently per octave, creating twisted, chaotic patterns.
+      //  noiseVectorEffect.getNoiseGenerator().SetFractalType(FastNoiseLite.FractalType.DomainWarpProgressive);   // Applies domain warping progressively, later octaves warp the results of earlier octaves. Creates flowing, warped patterns.
+      //  noiseVectorEffect.getNoiseGenerator().SetFractalType(FastNoiseLite.FractalType.FBm);  // Standard fractional Brownian motion. Smooth additive fractal layers. 
+      //  noiseVectorEffect.getNoiseGenerator().SetFractalType(FastNoiseLite.FractalType.PingPong);  // Folds and mirrors noise across octaves, increasing contrast and sharp detail in bouncy, mirrored patterns.
+
+    //configure fractal params:
+        noiseVectorEffect.getNoiseGenerator().SetFractalGain(0.5f); // Gain Determines how much each successive octave contributes. higher fractal gain values result in more chaotic / less smooth effect
+        noiseVectorEffect.getNoiseGenerator().SetFractalLacunarity(2f);// Higher Lacunarity values make higher octaves "faster" (more detail / rougher), lower values make them "slower" (broader, smoother patterns)        
+        noiseVectorEffect.getNoiseGenerator().SetFractalOctaves(5); // Number of noise layers to combine. Higher octave count results in more detail but requires more computations. Lower octave count results in smoother simpler patterns.
+        noiseVectorEffect.getNoiseGenerator().SetFractalWeightedStrength(0.1f);  // Controls how much higher octaves contribute when lower octaves are already strong.    
+        
+      //  noiseVectorEffect.getNoiseGenerator().SetFractalPingPongStrength(speed);// Controls how strong the ping‑pong effect is when using the PingPong fractal type.    
+ 
+        vectorEffectManagerState.registerVectorEffect(noiseVectorEffect);        
+    }
+    
+    
+
+    @Override
+    public void simpleUpdate(float tpf) {
+        super.simpleUpdate(tpf);
+        
+        //float values like a light's radius cannot be altered by refernce like a vector object, 
+        //so the float value must be manually extracted from the x component of a vector2f and set as radius every from
+        if(lightRadiusVector != null){ 
+           light.setRadius(lightRadiusVector.getX());
+        }
+    }
+    
+    private void initBloom() {
+        
+        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
+        BloomFilter bloom = new BloomFilter(BloomFilter.GlowMode.Scene);
+        bloom.setBloomIntensity(5f);
+        bloom.setExposurePower(4.5f);
+        bloom.setExposureCutOff(0.2f);
+        bloom.setBlurScale(2);
+        fpp.addFilter(bloom);
+        viewPort.addProcessor(fpp);
+    }
+
+    private void initLightAndEmissiveSphere(){
+      
+
+      //make point light
+        light = new PointLight();
+        light.setRadius(10);
+        colorToShift = light.getColor();
+        colorToShift.set(1.0f,0.97f, 0.63f, 1.0f);
+        
+      //make sphere with Emissive color  
+        Sphere sphereMesh = new Sphere(32, 32, 0.5f);
+        Geometry glowingSphere = new Geometry("ShakingSphere", sphereMesh);
+
+        Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
+        sphereMat.setColor("BaseColor", ColorRGBA.DarkGray);
+        sphereMat.setFloat("Roughness", 0.04f);
+        sphereMat.setFloat("Metallic", 0.98f);
+        sphereMat.setFloat("EmissivePower", 0.1f);
+        sphereMat.setFloat("EmissiveIntensity", 0.3f);
+        sphereMat.setBoolean("UseVertexColor", false);
+        glowingSphere.setMaterial(sphereMat);
+        
+        
+        //assign the same colorToShift vector to both the light and emissive value (important not to clone)
+        light.setColor(colorToShift);        
+        sphereMat.setColor("Emissive", colorToShift);  
+        
+        
+        rootNode.attachChild(glowingSphere);          
+        rootNode.addLight(light);
+        
+        
+    }
+
+    private void initShakingSphere() {
+        Sphere mesh = new Sphere(16, 16, 0.5f);
+        Geometry shakingSphere = new Geometry("ShakingSphere", mesh);
+
+        Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
+        mat.setBoolean("UseMaterialColors", true);
+        mat.setColor("Diffuse", ColorRGBA.Blue);
+        mat.setColor("Specular", ColorRGBA.White);
+        mat.setFloat("Shininess", 32f);
+
+        shakingSphere.setMaterial(mat);
+        shakingSphere.setLocalTranslation(2, 0.5f, 0);
+        rootNode.attachChild(shakingSphere);
+    }
+
+
+    
+    public void initPbrRoom(float size) {
+        float half = size * 0.5f;
+        
+        Material wallMat = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
+
+        wallMat.setColor("BaseColor", new ColorRGBA(1,1,1, 1f));
+        wallMat.setFloat("Roughness", 0.12f);
+        wallMat.setFloat("Metallic", 0.02f);
+
+        // Floor
+        Geometry floor = new Geometry("Floor",
+                new Quad(size, size));
+        floor.setMaterial(wallMat);
+        floor.rotate(-FastMath.HALF_PI, 0, 0);
+        floor.setLocalTranslation(-half, -half, half);
+        rootNode.attachChild(floor);
+
+        // Ceiling
+        Geometry ceiling = new Geometry("Ceiling",
+                new Quad(size, size));
+        ceiling.setMaterial(wallMat);
+        ceiling.rotate(FastMath.HALF_PI, 0, 0);
+        ceiling.setLocalTranslation(-half, size-half, -half);
+        rootNode.attachChild(ceiling);
+
+        // Back wall
+        Geometry backWall = new Geometry("BackWall",
+                new Quad(size, size));
+        backWall.setMaterial(wallMat);
+        backWall.setLocalTranslation(-half, -half, -half);
+        rootNode.attachChild(backWall);
+
+        // Left wall
+        Geometry leftWall = new Geometry("LeftWall",
+                new Quad(size, size));
+        leftWall.setMaterial(wallMat);
+        leftWall.rotate(0, FastMath.HALF_PI, 0);
+        leftWall.setLocalTranslation(-half, -half, half);
+        rootNode.attachChild(leftWall);
+
+        // Right wall
+        Geometry rightWall = new Geometry("RightWall",
+                new Quad(size, size));
+        rightWall.setMaterial(wallMat);
+        rightWall.rotate(0, -FastMath.HALF_PI, 0);
+        rightWall.setLocalTranslation(half, -half, -half);
+        rootNode.attachChild(rightWall);
+
+    }
+    
+    
+}

+ 219 - 0
jme3-examples/src/main/java/jme3test/effect/VectorEffectGroupTest.java

@@ -0,0 +1,219 @@
+package jme3test.effect;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.effect.ParticleEmitter;
+import com.jme3.effect.ParticleMesh;
+import com.jme3.font.BitmapFont;
+import com.jme3.font.BitmapText;
+import com.jme3.input.KeyInput;
+import com.jme3.input.controls.ActionListener;
+import com.jme3.input.controls.KeyTrigger;
+import com.jme3.light.PointLight;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.Easing;
+import com.jme3.math.FastMath;
+import com.jme3.math.Vector3f;
+import com.jme3.scene.Geometry;
+import com.jme3.scene.shape.Quad;
+import com.jme3.scene.shape.Sphere;
+import com.jme3.system.AppSettings;
+import com.jme3.vectoreffect.EaseVectorEffect;
+import com.jme3.vectoreffect.VectorEffectManagerState;
+import com.jme3.vectoreffect.VectorGroup;
+import java.awt.DisplayMode;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+
+public class VectorEffectGroupTest extends SimpleApplication {
+
+    private ColorRGBA lightColor  = new ColorRGBA(1.0f, 0.7f, 0.0f, 1.0f);
+    private ColorRGBA emissiveColor = new ColorRGBA(0.27f, 0.24f, 0.0f, 1.0f);
+    private ColorRGBA particleStartColor = new ColorRGBA(0.3f, 0.275f, 0.0f, 0.9f);
+    private ColorRGBA particleEndColor = new ColorRGBA(0.6f, 0.5f, 0.2f, 0.001f);
+    
+    private VectorGroup vectorsToModify, originalVectorValues;    
+    
+    private VectorEffectManagerState vectorEffectManagerState;
+    
+    public static void main(String[] args) {
+        VectorEffectGroupTest app = new VectorEffectGroupTest();
+        AppSettings settings = new AppSettings(true);
+        app.setSettings(settings);
+        app.start();
+    }    
+
+    @Override
+    public void simpleInitApp() {
+        flyCam.setMoveSpeed(10f);
+        
+        vectorEffectManagerState = new VectorEffectManagerState();
+        stateManager.attach(vectorEffectManagerState);
+        
+        initHudText();
+        initInput();
+        initPbrRoom(13);
+        
+        initLightAndEmissiveSphere();
+        initParticleEmitter();
+    
+     //initiate VectorEffectManagerState    
+        vectorEffectManagerState = new VectorEffectManagerState();
+        stateManager.attach(vectorEffectManagerState);
+        vectorEffectManagerState.setEnabled(true);        
+        
+        vectorsToModify = new VectorGroup(lightColor, emissiveColor, particleStartColor, particleEndColor);
+        
+        originalVectorValues = vectorsToModify.clone();
+
+    }
+    
+    private final ActionListener actionListener = new ActionListener() {
+        @Override
+        public void onAction(String name, boolean isPressed, float tpf) {
+            if (!isPressed) return; // trigger only on key down
+            
+            switch (name) {
+                case "FadeOut":
+                    vectorEffectManagerState.cancelEffects(vectorsToModify);
+                    vectorEffectManagerState.registerVectorEffect(new EaseVectorEffect(vectorsToModify, new VectorGroup(ColorRGBA.Black), 2.5f, Easing.inOutQuad));
+                    break;
+
+                case "FadeIn":
+                    vectorEffectManagerState.cancelEffects(vectorsToModify);
+                    vectorEffectManagerState.registerVectorEffect( new EaseVectorEffect(vectorsToModify, originalVectorValues, 2.75f, Easing.inOutQuad));
+                    break;
+
+                case "Cancel":
+                    vectorEffectManagerState.cancelEffects(vectorsToModify);
+                    break;
+            }
+        }
+    };
+
+    private void initParticleEmitter(){
+        /** Uses Texture from jme3-test-data library! */
+        ParticleEmitter fireEffect = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
+        Material fireMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
+        fireMat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
+        fireEffect.setMaterial(fireMat);
+        fireEffect.setImagesX(2); fireEffect.setImagesY(2);
+        fireEffect.setEndColor( particleEndColor );   
+        fireEffect.setStartColor( particleStartColor ); 
+        fireEffect.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0));
+        fireEffect.setStartSize(0.85f);
+        fireEffect.setEndSize(0.01f);
+        fireEffect.setGravity(0f,0f,0f);
+        fireEffect.setLowLife(0.75f);
+        fireEffect.setHighLife(0.9f);
+        fireEffect.setParticlesPerSec(9);
+        fireEffect.getParticleInfluencer().setVelocityVariation(0.12f);
+        rootNode.attachChild(fireEffect);
+                
+        particleStartColor = fireEffect.getStartColor();
+        particleEndColor = fireEffect.getEndColor();
+    }
+
+    private void initLightAndEmissiveSphere(){      
+      //make point light
+        PointLight light = new PointLight();
+        light.setRadius(10);
+        light.setColor(lightColor);
+        lightColor = light.getColor();
+        
+      //make sphere with Emissive color  
+        Sphere sphereMesh = new Sphere(32, 32, 0.5f);
+        Geometry glowingSphere = new Geometry("ShakingSphere", sphereMesh);
+
+        Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
+        sphereMat.setColor("BaseColor", ColorRGBA.DarkGray);
+        sphereMat.setFloat("Roughness", 0.04f);
+        sphereMat.setFloat("Metallic", 0.98f);
+        sphereMat.setColor("Emissive", emissiveColor);
+        sphereMat.setBoolean("UseVertexColor", false);
+        glowingSphere.setMaterial(sphereMat);
+        
+        rootNode.attachChild(glowingSphere);          
+        rootNode.addLight(light);        
+        
+    }
+    
+    public void initPbrRoom(float size) {
+        float half = size * 0.5f;        
+        Material wallMat = new Material(assetManager, "Common/MatDefs/Light/PBRLighting.j3md");
+
+        wallMat.setColor("BaseColor", new ColorRGBA(1,1,1, 1f));
+        wallMat.setFloat("Roughness", 0.5f);
+        wallMat.setFloat("Metallic", 0.08f);
+
+        // Floor
+        Geometry floor = new Geometry("Floor",
+                new Quad(size, size));
+        floor.setMaterial(wallMat);
+        floor.rotate(-FastMath.HALF_PI, 0, 0);
+        floor.setLocalTranslation(-half, -half, half);
+        rootNode.attachChild(floor);
+
+        // Ceiling
+        Geometry ceiling = new Geometry("Ceiling",
+                new Quad(size, size));
+        ceiling.setMaterial(wallMat);
+        ceiling.rotate(FastMath.HALF_PI, 0, 0);
+        ceiling.setLocalTranslation(-half, size-half, -half);
+        rootNode.attachChild(ceiling);
+
+        // Back wall
+        Geometry backWall = new Geometry("BackWall",
+                new Quad(size, size));
+        backWall.setMaterial(wallMat);
+        backWall.setLocalTranslation(-half, -half, -half);
+        rootNode.attachChild(backWall);
+
+        // Left wall
+        Geometry leftWall = new Geometry("LeftWall",
+                new Quad(size, size));
+        leftWall.setMaterial(wallMat);
+        leftWall.rotate(0, FastMath.HALF_PI, 0);
+        leftWall.setLocalTranslation(-half, -half, half);
+        rootNode.attachChild(leftWall);
+
+        // Right wall
+        Geometry rightWall = new Geometry("RightWall",
+                new Quad(size, size));
+        rightWall.setMaterial(wallMat);
+        rightWall.rotate(0, -FastMath.HALF_PI, 0);
+        rightWall.setLocalTranslation(half, -half, -half);
+        rootNode.attachChild(rightWall);
+
+    }
+    
+    private void initInput() {
+        inputManager.addMapping("FadeIn", new KeyTrigger(KeyInput.KEY_1));
+        inputManager.addMapping("FadeOut", new KeyTrigger(KeyInput.KEY_2));
+        inputManager.addMapping("Cancel", new KeyTrigger(KeyInput.KEY_X));
+        inputManager.addListener(actionListener, "FadeIn", "FadeOut", "Cancel");        
+    }
+    
+     private void initHudText() {
+        BitmapFont font = assetManager.loadFont(
+                "Interface/Fonts/Default.fnt");
+
+        BitmapText helpText = new BitmapText(font);
+        helpText.setSize(font.getCharSet().getRenderedSize());
+        helpText.setText(
+                "Controls:\n" +
+                "1  - Fade In \n" +
+                "2  - Fade Out \n" +
+                "X - Cancel Current Effect"
+        );
+
+        // Top-left corner
+        helpText.setLocalTranslation(
+                10,
+                cam.getHeight() - 10,
+                0
+        );
+
+        guiNode.attachChild(helpText);
+    }
+}