Redesign of the frag part of unshadedNodes so it's more modular, and can be properly used as GLSL 1.5 shader.

Added a stress test for unshadedNodes.
Changed the name of the texture parameter to textureMap in TextureFetch shaderNode as it was conflicting with the texture function used to fetch a texel from a a texture in glsl 1.5
define_list_fix
Nehon 10 years ago
parent be58be75ef
commit 596954b056
  1. 216
      jme3-core/src/main/resources/Common/MatDefs/Misc/UnshadedNodes.j3md
  2. 4
      jme3-core/src/main/resources/Common/MatDefs/ShaderNodes/Basic/TextureFetch.j3sn
  3. 2
      jme3-core/src/main/resources/Common/MatDefs/ShaderNodes/Basic/texture.frag
  4. 2
      jme3-core/src/main/resources/Common/MatDefs/ShaderNodes/Basic/texture15.frag
  5. 102
      jme3-examples/src/main/java/jme3test/stress/TestShaderNodesStress.java

@ -1,97 +1,121 @@
MaterialDef UnshadedNodes { MaterialDef UnshadedNodes {
MaterialParameters {
MaterialParameters { Texture2D ColorMap
Texture2D ColorMap Texture2D LightMap
Texture2D LightMap Color Color (Color)
Color Color (Color) Boolean VertexColor (UseVertexColor)
Boolean VertexColor (UseVertexColor) Boolean SeparateTexCoord
Boolean SeparateTexCoord Float AlphaDiscardThreshold (AlphaTestFallOff)
Int NumberOfBones
// Alpha threshold for fragment discarding Matrix4Array BoneMatrices
Float AlphaDiscardThreshold (AlphaTestFallOff) }
Technique {
// For hardware skinning WorldParameters {
Int NumberOfBones WorldViewProjectionMatrix
Matrix4Array BoneMatrices WorldViewMatrix
}
} VertexShaderNodes {
ShaderNode GpuSkinning {
Technique { Definition : BasicGPUSkinning : Common/MatDefs/ShaderNodes/HardwareSkinning/HardwareSkinning.j3sn
Condition : NumberOfBones
WorldParameters { InputMapping {
WorldViewProjectionMatrix modelPosition = Global.position
//used for fog boneMatrices = MatParam.BoneMatrices
WorldViewMatrix boneWeight = Attr.inHWBoneWeight
} boneIndex = Attr.inHWBoneIndex
}
VertexShaderNodes{ OutputMapping {
ShaderNode GpuSkinning{ Global.position = modModelPosition
Definition: BasicGPUSkinning : Common/MatDefs/ShaderNodes/HardwareSkinning/HardwareSkinning.j3sn }
Condition : NumberOfBones }
InputMapping{ ShaderNode UnshadedVert {
modelPosition = Global.position; Definition : CommonVert : Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn
boneMatrices = MatParam.BoneMatrices InputMapping {
boneWeight = Attr.inHWBoneWeight worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix
boneIndex = Attr.inHWBoneIndex modelPosition = Global.position.xyz
} texCoord1 = Attr.inTexCoord : ColorMap || (LightMap && !SeparateTexCoord)
OutputMapping{ texCoord2 = Attr.inTexCoord2 : SeparateTexCoord
Global.position = modModelPosition vertColor = Attr.inColor : VertexColor
} }
} OutputMapping {
ShaderNode UnshadedVert{ Global.position = projPosition
Definition: CommonVert : Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn }
InputMapping{ }
worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix }
modelPosition = Global.position.xyz FragmentShaderNodes {
texCoord1 = Attr.inTexCoord: ColorMap || (LightMap && !SeparateTexCoord) ShaderNode MatColorMult {
texCoord2 = Attr.inTexCoord2: SeparateTexCoord Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
vertColor = Attr.inColor: VertexColor InputMappings {
} color1 = MatParam.Color
OutputMapping{ color2 = Global.outColor
Global.position = projPosition }
} OutputMappings {
} Global.outColor = outColor
} }
FragmentShaderNodes{ Condition : Color
ShaderNode UnshadedFrag{ }
Definition: Unshaded : Common/MatDefs/ShaderNodes/Common/Unshaded.j3sn ShaderNode VertColorMult {
InputMapping{ Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
texCoord = UnshadedVert.texCoord1: ColorMap InputMappings {
vertColor = UnshadedVert.vertColor: VertexColor color1 = UnshadedVert.vertColor
matColor = MatParam.Color: Color color2 = Global.outColor
colorMap = MatParam.ColorMap: ColorMap }
color = Global.outColor OutputMappings {
} Global.outColor = outColor
OutputMapping{ }
Global.outColor = color Condition : VertexColor
} }
} ShaderNode ColorMapTF {
Definition : TextureFetch : Common/MatDefs/ShaderNodes/Basic/TextureFetch.j3sn
ShaderNode AlphaDiscardThreshold{ InputMappings {
Definition: AlphaDiscard : Common/MatDefs/ShaderNodes/Basic/AlphaDiscard.j3sn texCoord = UnshadedVert.texCoord1
Condition : AlphaDiscardThreshold textureMap = MatParam.ColorMap
InputMapping{ }
alpha = Global.outColor.a OutputMappings {
threshold = MatParam.AlphaDiscardThreshold }
} Condition : ColorMap
} }
ShaderNode LightMap{ ShaderNode ColorMapMult {
Definition: LightMapping : Common/MatDefs/ShaderNodes/LightMapping/LightMapping.j3sn Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
Condition: LightMap InputMappings {
InputMapping{ color1 = ColorMapTF.outColor
texCoord = UnshadedVert.texCoord1: !SeparateTexCoord color2 = Global.outColor
texCoord = UnshadedVert.texCoord2: SeparateTexCoord }
lightMap = MatParam.LightMap OutputMappings {
color = Global.outColor Global.outColor = outColor
} }
OutputMapping{ Condition : ColorMap
Global.outColor = color }
} ShaderNode AlphaDiscardThreshold {
} Definition : AlphaDiscard : Common/MatDefs/ShaderNodes/Basic/AlphaDiscard.j3sn
Condition : AlphaDiscardThreshold
} InputMapping {
alpha = Global.outColor.a
} threshold = MatParam.AlphaDiscardThreshold
}
}
ShaderNode LightMapTF {
Definition : TextureFetch : Common/MatDefs/ShaderNodes/Basic/TextureFetch.j3sn
InputMappings {
textureMap = MatParam.LightMap
texCoord = UnshadedVert.texCoord2 : SeparateTexCoord
texCoord = UnshadedVert.texCoord1 : !SeparateTexCoord
}
OutputMappings {
}
Condition : LightMap
}
ShaderNode LightMapMult {
Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
OutputMappings {
Global.outColor = outColor
}
InputMappings {
color1 = LightMapTF.outColor
color2 = Global.outColor
}
Condition : LightMap
}
}
}
} }

@ -5,12 +5,12 @@ ShaderNodeDefinitions{
Shader GLSL150: Common/MatDefs/ShaderNodes/Basic/texture15.frag Shader GLSL150: Common/MatDefs/ShaderNodes/Basic/texture15.frag
Documentation{ Documentation{
Fetches a color value in the given texture acording to given texture coordinates Fetches a color value in the given texture acording to given texture coordinates
@input texture the texture to read @input textureMap the texture to read
@input texCoord the texture coordinates @input texCoord the texture coordinates
@output outColor the fetched color @output outColor the fetched color
} }
Input { Input {
sampler2D texture sampler2D textureMap
vec2 texCoord vec2 texCoord
} }
Output { Output {

@ -1,3 +1,3 @@
void main(){ void main(){
outColor = texture2D(texture,texCoord); outColor = texture2D(textureMap,texCoord);
} }

@ -1,3 +1,3 @@
void main(){ void main(){
outColor = texture(texture,texCoord); outColor = texture(textureMap,texCoord);
} }

@ -0,0 +1,102 @@
package jme3test.stress;
import com.jme3.app.BasicProfilerState;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.profile.AppProfiler;
import com.jme3.profile.AppStep;
import com.jme3.profile.VpStep;
import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
import java.util.logging.Level;
import java.util.logging.Logger;
public class TestShaderNodesStress extends SimpleApplication {
public static void main(String[] args) {
TestShaderNodesStress app = new TestShaderNodesStress();
app.start();
}
@Override
public void simpleInitApp() {
Quad q = new Quad(1, 1);
Geometry g = new Geometry("quad", q);
g.setLocalTranslation(-500, -500, 0);
g.setLocalScale(1000);
rootNode.attachChild(g);
cam.setLocation(new Vector3f(0.0f, 0.0f, 0.40647888f));
cam.setRotation(new Quaternion(0.0f, 1.0f, 0.0f, 0.0f));
Texture tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
Material mat = new Material(assetManager, "Common/MatDefs/Misc/UnshadedNodes.j3md");
//Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Yellow);
mat.setTexture("ColorMap", tex);
g.setMaterial(mat);
//place the geoms in the transparent bucket so that they are rendered back to front for maximum overdraw
g.setQueueBucket(RenderQueue.Bucket.Transparent);
for (int i = 0; i < 1000; i++) {
Geometry cl = g.clone(false);
cl.move(0, 0, -(i + 1));
rootNode.attachChild(cl);
}
flyCam.setMoveSpeed(20);
Logger.getLogger("com.jme3").setLevel(Level.WARNING);
this.setAppProfiler(new Profiler());
}
private class Profiler implements AppProfiler {
private long startTime;
private long updateTime;
private long renderTime;
private long sum;
private int nbFrames;
@Override
public void appStep(AppStep step) {
switch (step) {
case BeginFrame:
startTime = System.nanoTime();
break;
case RenderFrame:
updateTime = System.nanoTime();
// System.err.println("Update time : " + (updateTime - startTime));
break;
case EndFrame:
nbFrames++;
if (nbFrames >= 150) {
renderTime = System.nanoTime();
sum += renderTime - updateTime;
System.err.println("render time : " + (renderTime - updateTime));
System.err.println("Average render time : " + ((float)sum / (float)(nbFrames-150)));
}
break;
}
}
@Override
public void vpStep(VpStep step, ViewPort vp, RenderQueue.Bucket bucket) {
}
}
}
Loading…
Cancel
Save