-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Replaces fullscreen quad with a viewport covering triangle #2589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zzuegg
wants to merge
7
commits into
jMonkeyEngine:master
Choose a base branch
from
zzuegg:fullscreen_triangle
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+241
−7
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
99ae154
*Add FullscreenTriangle.java
zzuegg 26295f9
*Update Postprocessor to use the new FullscreenTriangle geometry
zzuegg bc6b3bf
Changed post vertex shaders to work with the already correct position…
zzuegg 0e78b63
Revert to the old vertex shader code
zzuegg ea76ce7
Reworked the positions so that the vertex positions are correct with …
zzuegg 8c1bb36
Added support for using fullscreen triangle or quad in `FilterPostPro…
zzuegg 7570143
Added screenshot test for FogFilter using fullscreen triangle rendering.
zzuegg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
jme3-core/src/main/java/com/jme3/scene/shape/FullscreenTriangle.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.jme3.scene.shape; | ||
|
|
||
| import com.jme3.scene.Mesh; | ||
| import com.jme3.scene.VertexBuffer; | ||
|
|
||
|
|
||
| /** | ||
| * The FullscreenTriangle class defines a mesh representing a single | ||
| * triangle that spans the entire screen. It is typically used in rendering | ||
| * techniques where a fullscreen quad or triangle is needed, such as in | ||
| * post-processing effects or screen-space operations. | ||
| */ | ||
| public class FullscreenTriangle extends Mesh { | ||
|
|
||
| /** | ||
| * Encapsulates the vertex positions for a fullscreen triangle. | ||
| * The positions are transformed by the vertex shader to cover the entire screen. | ||
| */ | ||
| private static final float[] POSITIONS = { | ||
| 0, 0, 0, // -1 -1 0 after vertex shader transform | ||
| 2, 0, 0, // 3 -1 0 after vertex shader transform | ||
| 0, 2, 0 // -1 3 0 after vertex shader transform | ||
| }; | ||
|
|
||
| private static final float[] TEXCOORDS = { | ||
| 0,0, | ||
| 2,0, | ||
| 0,2 | ||
| }; | ||
|
|
||
|
|
||
| public FullscreenTriangle() { | ||
| super(); | ||
| setBuffer(VertexBuffer.Type.Position, 3, POSITIONS); | ||
| setBuffer(VertexBuffer.Type.TexCoord, 2, TEXCOORDS); | ||
| setBuffer(VertexBuffer.Type.Index, 3, new short[]{0, 1, 2}); | ||
| updateBound(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
...tests/src/test/java/org/jmonkeyengine/screenshottests/post/TestFogFullscreenTriangle.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| /* | ||
| * Copyright (c) 2025 jMonkeyEngine | ||
| * All rights reserved. | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * | ||
| * * Redistributions in binary form must reproduce the above copyright | ||
| * notice, this list of conditions and the following disclaimer in the | ||
| * documentation and/or other materials provided with the distribution. | ||
| * | ||
| * * Neither the name of 'jMonkeyEngine' nor the names of its contributors | ||
| * may be used to endorse or promote products derived from this software | ||
| * without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
| * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
| * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
| * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
| * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
| * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
| package org.jmonkeyengine.screenshottests.post; | ||
|
|
||
| import com.jme3.app.Application; | ||
| import com.jme3.app.SimpleApplication; | ||
| import com.jme3.app.state.BaseAppState; | ||
| import com.jme3.asset.AssetManager; | ||
| import com.jme3.light.DirectionalLight; | ||
| import com.jme3.material.Material; | ||
| import com.jme3.math.ColorRGBA; | ||
| import com.jme3.math.Quaternion; | ||
| import com.jme3.math.Vector3f; | ||
| import com.jme3.post.FilterPostProcessor; | ||
| import com.jme3.post.filters.FogFilter; | ||
| import com.jme3.renderer.queue.RenderQueue; | ||
| import com.jme3.scene.Node; | ||
| import com.jme3.terrain.geomipmap.TerrainQuad; | ||
| import com.jme3.terrain.heightmap.AbstractHeightMap; | ||
| import com.jme3.terrain.heightmap.ImageBasedHeightMap; | ||
| import com.jme3.texture.Texture; | ||
| import com.jme3.util.SkyFactory; | ||
| import org.jmonkeyengine.screenshottests.testframework.ScreenshotTestBase; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Screenshot test for the Fog filter. | ||
| * | ||
| * <p>This test creates a scene with a terrain and sky, with a fog effect applied. | ||
| * The fog is a light gray color and has a specific density and distance setting. | ||
| * | ||
| * @author Richard Tingle (screenshot test adaptation) | ||
| */ | ||
| public class TestFogFullscreenTriangle extends ScreenshotTestBase { | ||
|
|
||
| /** | ||
| * This test creates a scene with a fog effect. | ||
| */ | ||
| @Test | ||
| public void testFog() { | ||
| screenshotTest(new BaseAppState() { | ||
| @Override | ||
| protected void initialize(Application app) { | ||
| SimpleApplication simpleApplication = (SimpleApplication) app; | ||
| Node rootNode = simpleApplication.getRootNode(); | ||
|
|
||
| simpleApplication.getCamera().setLocation(new Vector3f(-34.74095f, 95.21318f, -287.4945f)); | ||
| simpleApplication.getCamera().setRotation(new Quaternion(0.023536969f, 0.9361278f, -0.016098259f, -0.35050195f)); | ||
|
|
||
| Node mainScene = new Node(); | ||
|
|
||
| mainScene.attachChild(SkyFactory.createSky(simpleApplication.getAssetManager(), | ||
| "Textures/Sky/Bright/BrightSky.dds", | ||
| SkyFactory.EnvMapType.CubeMap)); | ||
|
|
||
| createTerrain(mainScene, app.getAssetManager()); | ||
|
|
||
| DirectionalLight sun = new DirectionalLight(); | ||
| Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f); | ||
| sun.setDirection(lightDir); | ||
| sun.setColor(ColorRGBA.White.clone().multLocal(2)); | ||
| mainScene.addLight(sun); | ||
|
|
||
| rootNode.attachChild(mainScene); | ||
|
|
||
| FilterPostProcessor fpp = new FilterPostProcessor(simpleApplication.getAssetManager(),true); | ||
|
|
||
| FogFilter fog = new FogFilter(); | ||
| fog.setFogColor(new ColorRGBA(0.9f, 0.9f, 0.9f, 1.0f)); | ||
| fog.setFogDistance(155); | ||
| fog.setFogDensity(1.0f); | ||
| fpp.addFilter(fog); | ||
| simpleApplication.getViewPort().addProcessor(fpp); | ||
| } | ||
|
|
||
|
|
||
| private void createTerrain(Node rootNode, AssetManager assetManager) { | ||
| Material matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md"); | ||
| matRock.setBoolean("useTriPlanarMapping", false); | ||
| matRock.setBoolean("WardIso", true); | ||
| matRock.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png")); | ||
| Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png"); | ||
| Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg"); | ||
| grass.setWrap(Texture.WrapMode.Repeat); | ||
| matRock.setTexture("DiffuseMap", grass); | ||
| matRock.setFloat("DiffuseMap_0_scale", 64); | ||
| Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg"); | ||
| dirt.setWrap(Texture.WrapMode.Repeat); | ||
| matRock.setTexture("DiffuseMap_1", dirt); | ||
| matRock.setFloat("DiffuseMap_1_scale", 16); | ||
| Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg"); | ||
| rock.setWrap(Texture.WrapMode.Repeat); | ||
| matRock.setTexture("DiffuseMap_2", rock); | ||
| matRock.setFloat("DiffuseMap_2_scale", 128); | ||
| Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg"); | ||
| normalMap0.setWrap(Texture.WrapMode.Repeat); | ||
| Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png"); | ||
| normalMap1.setWrap(Texture.WrapMode.Repeat); | ||
| Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png"); | ||
| normalMap2.setWrap(Texture.WrapMode.Repeat); | ||
| matRock.setTexture("NormalMap", normalMap0); | ||
| matRock.setTexture("NormalMap_1", normalMap1); | ||
| matRock.setTexture("NormalMap_2", normalMap2); | ||
|
|
||
| AbstractHeightMap heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f); | ||
| heightmap.load(); | ||
|
|
||
| TerrainQuad terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap()); | ||
|
|
||
| terrain.setMaterial(matRock); | ||
| terrain.setLocalScale(new Vector3f(5, 5, 5)); | ||
| terrain.setLocalTranslation(new Vector3f(0, -30, 0)); | ||
| terrain.setLocked(false); // unlock it so we can edit the height | ||
|
|
||
| terrain.setShadowMode(RenderQueue.ShadowMode.Receive); | ||
| rootNode.attachChild(terrain); | ||
|
|
||
| } | ||
|
|
||
|
|
||
| @Override | ||
| protected void cleanup(Application app) { | ||
| } | ||
|
|
||
| @Override | ||
| protected void onEnable() { | ||
| } | ||
|
|
||
| @Override | ||
| protected void onDisable() { | ||
| } | ||
|
|
||
| @Override | ||
| public void update(float tpf) { | ||
| super.update(tpf); | ||
| System.out.println(getApplication().getCamera().getLocation()); | ||
| } | ||
|
|
||
| }) | ||
| .setBaseImageFileName("org.jmonkeyengine.screenshottests.post.TestFog.testFog") | ||
| .setFramesToTakeScreenshotsOn(1) | ||
| .run(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯