Glow map with costum colors using shader nodes

Hello out there!
I want to implement a simple glow effect: You can specify a glow map for the model and a glow color. The glow color gets multiplied with the glow map color, so you can set a different glow color for different object using the same glow map.

So I made this material definition:

MaterialDef CustomGlower { MaterialParameters { Color Color Color GlowMapColor Texture2D MyGlowMap }
Technique {
    WorldParameters {
        WorldViewProjectionMatrix
    }
    VertexShaderNodes {
        ShaderNode CommonVert {
            Definition : CommonVert : Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn
            InputMappings {
                worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix
                modelPosition = Global.position.xyz
            }
            OutputMappings {
                Global.position = projPosition
            }
        }
    }
    FragmentShaderNodes {
        ShaderNode ColorMult {
            Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
            InputMappings {
                color1 = MatParam.Color
                color2 = Global.color
            }
            OutputMappings {
                Global.color = outColor
            }
        }
    }
}

Technique Glow {
    WorldParameters {
        WorldViewProjectionMatrix
    }
    VertexShaderNodes {
        ShaderNode CommonVert1 {
            Definition : CommonVert : Common/MatDefs/ShaderNodes/Common/CommonVert.j3sn
            InputMappings {
                worldViewProjectionMatrix = WorldParam.WorldViewProjectionMatrix
                modelPosition = Global.position.xyz
                texCoord1 = Attr.inTexCoord
            }
            OutputMappings {
                Global.position = projPosition
            }
        }
    }
    FragmentShaderNodes {
        ShaderNode TextureFetch {
            Definition : TextureFetch : Common/MatDefs/ShaderNodes/Basic/TextureFetch.j3sn
            InputMappings {
                texCoord = CommonVert1.texCoord1
                texture = MatParam.MyGlowMap
            }
        }
        ShaderNode ColorMult1 {
            Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
            InputMappings {
                color1 = MatParam.GlowMapColor
                color2 = Global.color
            }
        }
        ShaderNode ColorMult2 {
            Definition : ColorMult : Common/MatDefs/ShaderNodes/Basic/ColorMult.j3sn
            InputMappings {
                color1 = ColorMult1.outColor
                color2 = TextureFetch.outColor
            }
            OutputMappings {
                Global.color = outColor
            }
        }
    }
}

}

As far as I understood it the technique “Glow” will be used by the BloomFilter. So I wrote this java-code to test everything:

[java]
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry(“Box”, b);

Material mat = new Material(assetManager, “MatDefs/CustomGlower.j3md”);
mat.setColor(“Color”, ColorRGBA.Brown);
mat.setColor(“GlowMapColor”, ColorRGBA.Red);
mat.setTexture(“MyGlowMap”, assetManager.loadTexture(“Textures/GlowTest.png”));
geom.setMaterial(mat);

FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
BloomFilter bloom = new BloomFilter(BloomFilter.GlowMode.Objects);
bloom.setBlurScale(3.f);
fpp.addFilter(bloom);
viewPort.addProcessor(fpp);

rootNode.attachChild(geom);
[/java]

When I execute the simple game with the code above inside of initApp(), I get following error:

Nov 16, 2013 9:14:10 PM com.jme3.app.Application handleError SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main] java.lang.IllegalStateException: No loader registered for type "" at com.jme3.asset.ImplHandler.aquireLoader(ImplHandler.java:198) at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:271) at com.jme3.asset.DesktopAssetManager.loadShader(DesktopAssetManager.java:410) at com.jme3.material.Technique.loadShader(Technique.java:217) at com.jme3.material.Technique.makeCurrent(Technique.java:201) at com.jme3.material.Material.selectTechnique(Material.java:928) at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:499) at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:322) at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:374) at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:763) at com.jme3.post.filters.BloomFilter.postQueue(BloomFilter.java:200) at com.jme3.post.FilterPostProcessor.postQueue(FilterPostProcessor.java:215) at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:979) at com.jme3.renderer.RenderManager.render(RenderManager.java:1029) at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252) at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151) at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185) at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228) at java.lang.Thread.run(Thread.java:722)

When I try to display the cube without the bloom, I get a very weird image… but when I remove the Glow technique from the materials file, everything is ok. What shall I do?

Thank you very much in advance!

1 Like

Gonna look into it.

Thank you!

I looked into it and it works with last SVN. could you please update to nightly maybe. I fixed some things in technique loading since 3.0, and the issue I fixed can possibly cause your issue.

2 Likes

Jep, that did the job. Now everythings works as expected, thanks for the quick answer!