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
experimental
Nehon 10 years ago
parent 2b8898b7b2
commit 6d1ab7af65
  1. 134
      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
// Alpha threshold for fragment discarding
Float AlphaDiscardThreshold (AlphaTestFallOff) Float AlphaDiscardThreshold (AlphaTestFallOff)
// For hardware skinning
Int NumberOfBones Int NumberOfBones
Matrix4Array BoneMatrices Matrix4Array BoneMatrices
} }
Technique { Technique {
WorldParameters { WorldParameters {
WorldViewProjectionMatrix WorldViewProjectionMatrix
//used for fog
WorldViewMatrix WorldViewMatrix
} }
VertexShaderNodes {
VertexShaderNodes{ ShaderNode GpuSkinning {
ShaderNode GpuSkinning{ Definition : BasicGPUSkinning : Common/MatDefs/ShaderNodes/HardwareSkinning/HardwareSkinning.j3sn
Definition: BasicGPUSkinning : Common/MatDefs/ShaderNodes/HardwareSkinning/HardwareSkinning.j3sn
Condition : NumberOfBones Condition : NumberOfBones
InputMapping{ InputMapping {
modelPosition = Global.position; modelPosition = Global.position
boneMatrices = MatParam.BoneMatrices boneMatrices = MatParam.BoneMatrices
boneWeight = Attr.inHWBoneWeight boneWeight = Attr.inHWBoneWeight
boneIndex = Attr.inHWBoneIndex boneIndex = Attr.inHWBoneIndex
} }
OutputMapping{ OutputMapping {
Global.position = modModelPosition Global.position = modModelPosition
} }
} }
ShaderNode UnshadedVert{ ShaderNode UnshadedVert {
Definition: CommonVert : Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn Definition : CommonVert : Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn
InputMapping{ InputMapping {
worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix
modelPosition = Global.position.xyz modelPosition = Global.position.xyz
texCoord1 = Attr.inTexCoord: ColorMap || (LightMap && !SeparateTexCoord) texCoord1 = Attr.inTexCoord : ColorMap || (LightMap && !SeparateTexCoord)
texCoord2 = Attr.inTexCoord2: SeparateTexCoord texCoord2 = Attr.inTexCoord2 : SeparateTexCoord
vertColor = Attr.inColor: VertexColor vertColor = Attr.inColor : VertexColor
} }
OutputMapping{ OutputMapping {
Global.position = projPosition Global.position = projPosition
} }
} }
} }
FragmentShaderNodes{ FragmentShaderNodes {
ShaderNode UnshadedFrag{ ShaderNode MatColorMult {
Definition: Unshaded : Common/MatDefs/ShaderNodes/Common/Unshaded.j3sn Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
InputMapping{ InputMappings {
texCoord = UnshadedVert.texCoord1: ColorMap color1 = MatParam.Color
vertColor = UnshadedVert.vertColor: VertexColor color2 = Global.outColor
matColor = MatParam.Color: Color
colorMap = MatParam.ColorMap: ColorMap
color = Global.outColor
}
OutputMapping{
Global.outColor = color
} }
OutputMappings {
Global.outColor = outColor
}
Condition : Color
}
ShaderNode VertColorMult {
Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
InputMappings {
color1 = UnshadedVert.vertColor
color2 = Global.outColor
}
OutputMappings {
Global.outColor = outColor
}
Condition : VertexColor
}
ShaderNode ColorMapTF {
Definition : TextureFetch : Common/MatDefs/ShaderNodes/Basic/TextureFetch.j3sn
InputMappings {
texCoord = UnshadedVert.texCoord1
textureMap = MatParam.ColorMap
}
OutputMappings {
}
Condition : ColorMap
} }
ShaderNode ColorMapMult {
ShaderNode AlphaDiscardThreshold{ Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
Definition: AlphaDiscard : Common/MatDefs/ShaderNodes/Basic/AlphaDiscard.j3sn InputMappings {
color1 = ColorMapTF.outColor
color2 = Global.outColor
}
OutputMappings {
Global.outColor = outColor
}
Condition : ColorMap
}
ShaderNode AlphaDiscardThreshold {
Definition : AlphaDiscard : Common/MatDefs/ShaderNodes/Basic/AlphaDiscard.j3sn
Condition : AlphaDiscardThreshold Condition : AlphaDiscardThreshold
InputMapping{ InputMapping {
alpha = Global.outColor.a alpha = Global.outColor.a
threshold = MatParam.AlphaDiscardThreshold threshold = MatParam.AlphaDiscardThreshold
} }
} }
ShaderNode LightMap{ ShaderNode LightMapTF {
Definition: LightMapping : Common/MatDefs/ShaderNodes/LightMapping/LightMapping.j3sn Definition : TextureFetch : Common/MatDefs/ShaderNodes/Basic/TextureFetch.j3sn
Condition: LightMap InputMappings {
InputMapping{ textureMap = MatParam.LightMap
texCoord = UnshadedVert.texCoord1: !SeparateTexCoord texCoord = UnshadedVert.texCoord2 : SeparateTexCoord
texCoord = UnshadedVert.texCoord2: SeparateTexCoord texCoord = UnshadedVert.texCoord1 : !SeparateTexCoord
lightMap = MatParam.LightMap }
color = Global.outColor OutputMappings {
} }
OutputMapping{ Condition : LightMap
Global.outColor = color }
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