ShaderBlow Dissolve Issue but solved it

Hi all :slight_smile: . As the topic says I was having a problem with ShaderBlow Dissolve Shader but solved it. I downloaded the ShaderBlow plugin. The Problem was that when I created a Dissolve Material in the MaterialEditor I could not add it to the model. I was getting an error. I tried to add the material both through scene composer and through class/code but was getting an error.

Here is the code part:

[java]
package MyStuff;

import com.jme3.app.SimpleApplication;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;

/**
*

  • @author Kamran
    */
    public class Main extends SimpleApplication{
    Spatial back1;

    public static void main(String [] args){
    Main app = new Main();
    app.start();
    }

    @Override
    public void simpleInitApp() {
    back1 = assetManager.loadModel(“ShaderBlow/Models/Background1/Background1_Effect.j3o”);
    ((Node)back1).getChild(“Background1”).setMaterial(assetManager.loadMaterial(“ShaderBlow/Materials/background1.j3m”));
    rootNode.attachChild(back1);
    }

}
[/java]

Here is the error I was getting:

[java]
Feb 27, 2014 1:07:15 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
com.jme3.asset.AssetLoadException: An exception has occured while loading asset: ShaderBlow/Materials/background1.j3m
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:290)
at com.jme3.asset.DesktopAssetManager.loadMaterial(DesktopAssetManager.java:350)
at MyStuff.Main.simpleInitApp(Main.java:26)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:226)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.IOException: Value parameter statement syntax incorrect
at com.jme3.material.plugins.J3MLoader.readValueParam(J3MLoader.java:270)
at com.jme3.material.plugins.J3MLoader.readExtendingMaterialParams(J3MLoader.java:296)
at com.jme3.material.plugins.J3MLoader.loadFromRoot(J3MLoader.java:531)
at com.jme3.material.plugins.J3MLoader.load(J3MLoader.java:555)
at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:288)
… 6 more
[/java]

To be sure I checked if the other Shaders in ShaderBlow were working or not but they were working. When I created the material in the class/code like in the Dissolve example it worked then. I was not sure why though. So I went through the Dissolves’s Lighting.frag and found a small problem. Starting from line 175 to 182 the code is

Lighting.frag
[java]
#ifdef DISSOLVE_MAP
if (m_DissolveParams.y == 0.0 && texture2D(m_DissolveMap, newTexCoord).r < m_DissolveParams.x) {
discard;
}
if (m_DissolveParams.y == 1.0 && texture2D(m_DissolveMap, newTexCoord).r > m_DissolveParams.x) {
discard;
}
#endif
[/java]

I am still new to shaders and how it works but one thing I found out while messing with shaders is that the “if” conditions does not always work like this, so what I did was add #ifdef

Update Lighting.frag

[java]
#ifdef DISSOLVE_MAP
#ifdef DISSOLVE_PARAMS
if (m_DissolveParams.y == 0.0 && texture2D(m_DissolveMap, newTexCoord).r < m_DissolveParams.x) {
discard;
}
if (m_DissolveParams.y == 1.0 && texture2D(m_DissolveMap, newTexCoord).r > m_DissolveParams.x) {
discard;
}
#endif
#endif
[/java]

After just adding these two lines “#ifdef DISSOLVE_PARAMS” and “#endif” solved the problem. Now I can create the Dissolve Material in the MaterialEditor and add it directly to the scene composer or through code. Hope it helps anyone else that came across this problem :slight_smile: OR it just could be me :facepalm:

K Out!