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
This commit is contained in:
parent
be58be75ef
commit
596954b056
@ -1,97 +1,121 @@
|
||||
MaterialDef UnshadedNodes {
|
||||
|
||||
MaterialParameters {
|
||||
Texture2D ColorMap
|
||||
Texture2D LightMap
|
||||
Color Color (Color)
|
||||
Boolean VertexColor (UseVertexColor)
|
||||
Boolean SeparateTexCoord
|
||||
|
||||
// Alpha threshold for fragment discarding
|
||||
Float AlphaDiscardThreshold (AlphaTestFallOff)
|
||||
|
||||
// For hardware skinning
|
||||
Int NumberOfBones
|
||||
Matrix4Array BoneMatrices
|
||||
|
||||
}
|
||||
|
||||
Technique {
|
||||
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
//used for fog
|
||||
WorldViewMatrix
|
||||
}
|
||||
|
||||
VertexShaderNodes{
|
||||
ShaderNode GpuSkinning{
|
||||
Definition: BasicGPUSkinning : Common/MatDefs/ShaderNodes/HardwareSkinning/HardwareSkinning.j3sn
|
||||
Condition : NumberOfBones
|
||||
InputMapping{
|
||||
modelPosition = Global.position;
|
||||
boneMatrices = MatParam.BoneMatrices
|
||||
boneWeight = Attr.inHWBoneWeight
|
||||
boneIndex = Attr.inHWBoneIndex
|
||||
}
|
||||
OutputMapping{
|
||||
Global.position = modModelPosition
|
||||
}
|
||||
}
|
||||
ShaderNode UnshadedVert{
|
||||
Definition: CommonVert : Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn
|
||||
InputMapping{
|
||||
worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix
|
||||
modelPosition = Global.position.xyz
|
||||
texCoord1 = Attr.inTexCoord: ColorMap || (LightMap && !SeparateTexCoord)
|
||||
texCoord2 = Attr.inTexCoord2: SeparateTexCoord
|
||||
vertColor = Attr.inColor: VertexColor
|
||||
}
|
||||
OutputMapping{
|
||||
Global.position = projPosition
|
||||
}
|
||||
}
|
||||
}
|
||||
FragmentShaderNodes{
|
||||
ShaderNode UnshadedFrag{
|
||||
Definition: Unshaded : Common/MatDefs/ShaderNodes/Common/Unshaded.j3sn
|
||||
InputMapping{
|
||||
texCoord = UnshadedVert.texCoord1: ColorMap
|
||||
vertColor = UnshadedVert.vertColor: VertexColor
|
||||
matColor = MatParam.Color: Color
|
||||
colorMap = MatParam.ColorMap: ColorMap
|
||||
color = Global.outColor
|
||||
}
|
||||
OutputMapping{
|
||||
Global.outColor = color
|
||||
}
|
||||
}
|
||||
|
||||
ShaderNode AlphaDiscardThreshold{
|
||||
Definition: AlphaDiscard : Common/MatDefs/ShaderNodes/Basic/AlphaDiscard.j3sn
|
||||
Condition : AlphaDiscardThreshold
|
||||
InputMapping{
|
||||
alpha = Global.outColor.a
|
||||
threshold = MatParam.AlphaDiscardThreshold
|
||||
}
|
||||
}
|
||||
ShaderNode LightMap{
|
||||
Definition: LightMapping : Common/MatDefs/ShaderNodes/LightMapping/LightMapping.j3sn
|
||||
Condition: LightMap
|
||||
InputMapping{
|
||||
texCoord = UnshadedVert.texCoord1: !SeparateTexCoord
|
||||
texCoord = UnshadedVert.texCoord2: SeparateTexCoord
|
||||
lightMap = MatParam.LightMap
|
||||
color = Global.outColor
|
||||
}
|
||||
OutputMapping{
|
||||
Global.outColor = color
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
MaterialDef UnshadedNodes {
|
||||
MaterialParameters {
|
||||
Texture2D ColorMap
|
||||
Texture2D LightMap
|
||||
Color Color (Color)
|
||||
Boolean VertexColor (UseVertexColor)
|
||||
Boolean SeparateTexCoord
|
||||
Float AlphaDiscardThreshold (AlphaTestFallOff)
|
||||
Int NumberOfBones
|
||||
Matrix4Array BoneMatrices
|
||||
}
|
||||
Technique {
|
||||
WorldParameters {
|
||||
WorldViewProjectionMatrix
|
||||
WorldViewMatrix
|
||||
}
|
||||
VertexShaderNodes {
|
||||
ShaderNode GpuSkinning {
|
||||
Definition : BasicGPUSkinning : Common/MatDefs/ShaderNodes/HardwareSkinning/HardwareSkinning.j3sn
|
||||
Condition : NumberOfBones
|
||||
InputMapping {
|
||||
modelPosition = Global.position
|
||||
boneMatrices = MatParam.BoneMatrices
|
||||
boneWeight = Attr.inHWBoneWeight
|
||||
boneIndex = Attr.inHWBoneIndex
|
||||
}
|
||||
OutputMapping {
|
||||
Global.position = modModelPosition
|
||||
}
|
||||
}
|
||||
ShaderNode UnshadedVert {
|
||||
Definition : CommonVert : Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn
|
||||
InputMapping {
|
||||
worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix
|
||||
modelPosition = Global.position.xyz
|
||||
texCoord1 = Attr.inTexCoord : ColorMap || (LightMap && !SeparateTexCoord)
|
||||
texCoord2 = Attr.inTexCoord2 : SeparateTexCoord
|
||||
vertColor = Attr.inColor : VertexColor
|
||||
}
|
||||
OutputMapping {
|
||||
Global.position = projPosition
|
||||
}
|
||||
}
|
||||
}
|
||||
FragmentShaderNodes {
|
||||
ShaderNode MatColorMult {
|
||||
Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
|
||||
InputMappings {
|
||||
color1 = MatParam.Color
|
||||
color2 = Global.outColor
|
||||
}
|
||||
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 {
|
||||
Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.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
|
||||
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
|
||||
Documentation{
|
||||
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
|
||||
@output outColor the fetched color
|
||||
}
|
||||
Input {
|
||||
sampler2D texture
|
||||
sampler2D textureMap
|
||||
vec2 texCoord
|
||||
}
|
||||
Output {
|
||||
|
@ -1,3 +1,3 @@
|
||||
void main(){
|
||||
outColor = texture2D(texture,texCoord);
|
||||
outColor = texture2D(textureMap,texCoord);
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
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…
x
Reference in New Issue
Block a user