2 bugs with j3m material (Solved)

Hi guys! I found a bug (as I suppose) in j3m Material.

When I assign g_time in j3m, so animation does not work.

But when I assign the g_time in my code, so it works.

[java]mat.setFloat(“g_Time”, 1.0f);[/java]



Uploaded with ImageShack.us

Log with j3m:

init:

Deleting: /home/mifth/jMonkeyProjects/JME_ShaderBlow/build/built-jar.properties

deps-jar:

Updating property file: /home/mifth/jMonkeyProjects/JME_ShaderBlow/build/built-jar.properties

Compiling 1 source file to /home/mifth/jMonkeyProjects/JME_ShaderBlow/build/classes

Note: /home/mifth/jMonkeyProjects/JME_ShaderBlow/src/ShaderBlow/FakeParticleBlow1.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

compile-single:

run-single:

Jul 27, 2011 2:40:40 AM com.jme3.system.JmeSystem initialize

INFO: Running on jMonkey Engine 3 Alpha 0.6

Jul 27, 2011 2:40:40 AM com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory #1: file:/home/mifth/jmonkeyplatform/jmonkeyplatform/libs/

Jul 27, 2011 2:40:40 AM com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory #2: /home/mifth/jMonkeyProjects/JME_ShaderBlow

Jul 27, 2011 2:40:40 AM com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory #3: /home/mifth/jMonkeyProjects/JME_ShaderBlow

Jul 27, 2011 2:40:40 AM com.jme3.system.Natives extractNativeLib

WARNING: Cannot locate native library: linux/libbulletjme.so

Jul 27, 2011 2:40:40 AM com.jme3.system.lwjgl.LwjglAbstractDisplay run

INFO: Using LWJGL 2.7.1

Jul 27, 2011 2:40:40 AM com.jme3.system.lwjgl.LwjglDisplay createContext

INFO: Selected display mode: 1280 x 720 x 0 @0Hz

Jul 27, 2011 2:40:40 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Adapter: null

Jul 27, 2011 2:40:40 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Driver Version: null

Jul 27, 2011 2:40:40 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Vendor: NVIDIA Corporation

Jul 27, 2011 2:40:40 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: OpenGL Version: 3.3.0 NVIDIA 270.41.06

Jul 27, 2011 2:40:40 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Renderer: GeForce GTS 250/PCI/SSE2

Jul 27, 2011 2:40:40 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: GLSL Ver: 3.30 NVIDIA via Cg compiler

Jul 27, 2011 2:40:40 AM com.jme3.system.lwjgl.LwjglTimer

INFO: Timer resolution: 1,000 ticks per second

Jul 27, 2011 2:40:40 AM com.jme3.renderer.lwjgl.LwjglRenderer initialize

INFO: Caps: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample, TextureMultisample, OpenGL20, OpenGL21, OpenGL30, OpenGL31, OpenGL32, ARBprogram, GLSL100, GLSL110, GLSL120, GLSL130, GLSL140, GLSL150, VertexTextureFetch, TextureArray, TextureBuffer, FloatTexture, FloatColorBuffer, FloatDepthBuffer, PackedFloatTexture, SharedExponentTexture, PackedFloatColorBuffer, TextureCompressionLATC, NonPowerOfTwoTextures, MeshInstancing, VertexBufferArray]

Jul 27, 2011 2:40:40 AM com.jme3.asset.DesktopAssetManager

INFO: DesktopAssetManager created.

Jul 27, 2011 2:40:40 AM com.jme3.renderer.Camera

INFO: Camera created (W: 1,280, H: 720)

Jul 27, 2011 2:40:40 AM com.jme3.renderer.Camera

INFO: Camera created (W: 1,280, H: 720)

Jul 27, 2011 2:40:40 AM com.jme3.input.lwjgl.LwjglMouseInput initialize

INFO: Mouse created.

Jul 27, 2011 2:40:40 AM com.jme3.input.lwjgl.LwjglKeyInput initialize

INFO: Keyboard created.

Jul 27, 2011 2:40:40 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread

INFO: AudioRenderer supports 64 channels

Jul 27, 2011 2:40:40 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread

INFO: Audio effect extension version: 1.0

Jul 27, 2011 2:40:40 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread

INFO: Audio max auxilary sends: 1

Jul 27, 2011 2:40:40 AM com.jme3.material.MaterialDef

INFO: Loaded material definition: Unshaded

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Gui Node)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (Statistics View) attached to this node (Gui Node)

Jul 27, 2011 2:40:41 AM com.jme3.material.MaterialDef

INFO: Loaded material definition: Sky Plane

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (Sky) attached to this node (Root Node)

Jul 27, 2011 2:40:41 AM com.jme3.material.MaterialDef

INFO: Loaded material definition: Phong Lighting

Jul 27, 2011 2:40:41 AM com.jme3.material.MaterialDef

INFO: Loaded material definition: FakeParticleBlow

Jul 27, 2011 2:40:41 AM com.jme3.scene.Node attachChild

INFO: Child (Models/jme_FakeParticleBlow/plane.blend) attached to this node (Root Node)

Jul 27, 2011 2:40:41 AM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform m_Animation_Y is not declared in shader.

Jul 27, 2011 2:40:41 AM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform m_g_Time is not declared in shader.

Jul 27, 2011 2:40:41 AM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform m_Change_Direction is not declared in shader.

Jul 27, 2011 2:40:41 AM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform m_VertexColor is not declared in shader.

______________________________________________________________________

Another bug with j3m:

I did some modifications for toon shader here: http://hub.jmonkeyengine.org/groups/free-announcements/forum/topic/mikumikudance-viewer/?topic_page=4&num=15

When I did that below, it worked ok:

[java]vec4 colour;

vec3 N = normalize(normal);

vec3 V = normalize(vViewDir.xyz);

if (dot(N, V) < 0.2) colour = vec4(0,0.5,0,1);

else colour = (((AmbientSum + DiffuseSum) * diffuseColor) +

SpecularSum2 * specularColor * light.y * 0.8) ;

gl_FragColor = colour;[/java]



Uploaded with ImageShack.us

But When I use EdgeSize unform (with any values (0.2, 0, 5, -100, xxx…)) in j3m Material, so I got such green edges:

[java]vec4 colour;

vec3 N = normalize(normal);

vec3 V = normalize(vViewDir.xyz);

if (dot(N, V) < EdgeSize) colour = vec4(0,0.5,0,1);

else colour = (((AmbientSum + DiffuseSum) * diffuseColor) +

SpecularSum2 * specularColor * light.y * 0.8) ;

gl_FragColor = colour;[/java]



Uploaded with ImageShack.us

My log with j3m and EdgeSize uniform:

init:

Deleting: /home/mifth/jMonkeyProjects/JME_ShaderBlow/build/built-jar.properties

deps-jar:

Updating property file: /home/mifth/jMonkeyProjects/JME_ShaderBlow/build/built-jar.properties

Compiling 1 source file to /home/mifth/jMonkeyProjects/JME_ShaderBlow/build/classes

Note: /home/mifth/jMonkeyProjects/JME_ShaderBlow/src/ShaderBlow/toon.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

compile-single:

run-single:

Jul 27, 2011 3:05:41 AM com.jme3.system.JmeSystem initialize

INFO: Running on jMonkey Engine 3 Alpha 0.6

Jul 27, 2011 3:05:41 AM com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory #1: file:/home/mifth/jmonkeyplatform/jmonkeyplatform/libs/

Jul 27, 2011 3:05:41 AM com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory #2: /home/mifth/jMonkeyProjects/JME_ShaderBlow

Jul 27, 2011 3:05:41 AM com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory #3: /home/mifth/jMonkeyProjects/JME_ShaderBlow

Jul 27, 2011 3:05:41 AM com.jme3.system.Natives extractNativeLib

WARNING: Cannot locate native library: linux/libbulletjme.so

Jul 27, 2011 3:05:41 AM com.jme3.system.lwjgl.LwjglAbstractDisplay run

INFO: Using LWJGL 2.7.1

Jul 27, 2011 3:05:41 AM com.jme3.system.lwjgl.LwjglDisplay createContext

INFO: Selected display mode: 1280 x 720 x 0 @0Hz

Jul 27, 2011 3:05:41 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Adapter: null

Jul 27, 2011 3:05:41 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Driver Version: null

Jul 27, 2011 3:05:41 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Vendor: NVIDIA Corporation

Jul 27, 2011 3:05:41 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: OpenGL Version: 3.3.0 NVIDIA 270.41.06

Jul 27, 2011 3:05:41 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: Renderer: GeForce GTS 250/PCI/SSE2

Jul 27, 2011 3:05:41 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo

INFO: GLSL Ver: 3.30 NVIDIA via Cg compiler

Jul 27, 2011 3:05:41 AM com.jme3.system.lwjgl.LwjglTimer

INFO: Timer resolution: 1,000 ticks per second

Jul 27, 2011 3:05:41 AM com.jme3.renderer.lwjgl.LwjglRenderer initialize

INFO: Caps: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample, TextureMultisample, OpenGL20, OpenGL21, OpenGL30, OpenGL31, OpenGL32, ARBprogram, GLSL100, GLSL110, GLSL120, GLSL130, GLSL140, GLSL150, VertexTextureFetch, TextureArray, TextureBuffer, FloatTexture, FloatColorBuffer, FloatDepthBuffer, PackedFloatTexture, SharedExponentTexture, PackedFloatColorBuffer, TextureCompressionLATC, NonPowerOfTwoTextures, MeshInstancing, VertexBufferArray]

Jul 27, 2011 3:05:41 AM com.jme3.asset.DesktopAssetManager

INFO: DesktopAssetManager created.

Jul 27, 2011 3:05:41 AM com.jme3.renderer.Camera

INFO: Camera created (W: 1,280, H: 720)

Jul 27, 2011 3:05:41 AM com.jme3.renderer.Camera

INFO: Camera created (W: 1,280, H: 720)

Jul 27, 2011 3:05:41 AM com.jme3.input.lwjgl.LwjglMouseInput initialize

INFO: Mouse created.

Jul 27, 2011 3:05:41 AM com.jme3.input.lwjgl.LwjglKeyInput initialize

INFO: Keyboard created.

Jul 27, 2011 3:05:41 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread

INFO: AudioRenderer supports 64 channels

Jul 27, 2011 3:05:41 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread

INFO: Audio effect extension version: 1.0

Jul 27, 2011 3:05:41 AM com.jme3.audio.lwjgl.LwjglAudioRenderer initInThread

INFO: Audio max auxilary sends: 1

Jul 27, 2011 3:05:41 AM com.jme3.material.MaterialDef

INFO: Loaded material definition: Unshaded

Jul 27, 2011 3:05:41 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:41 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Gui Node)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (null)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (null) attached to this node (Statistics View)

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (Statistics View) attached to this node (Gui Node)

Jul 27, 2011 3:05:42 AM com.jme3.material.MaterialDef

INFO: Loaded material definition: Sky Plane

Jul 27, 2011 3:05:42 AM com.jme3.scene.Node attachChild

INFO: Child (Sky) attached to this node (Root Node)

Jul 27, 2011 3:05:42 AM com.jme3.material.MaterialDef

INFO: Loaded material definition: Phong Lighting

Unknown statement in OBJ! o

Jul 27, 2011 3:05:43 AM com.jme3.scene.plugins.OBJLoader createGeometry

WARNING: OBJ mesh toon-geom-0 doesnt contain normals! It might not display correctly

Jul 27, 2011 3:05:43 AM com.jme3.scene.Node attachChild

INFO: Child (toon-geom-0) attached to this node (toon-objnode)

Jul 27, 2011 3:05:43 AM com.jme3.material.MaterialDef

INFO: Loaded material definition: pmd

Jul 27, 2011 3:05:44 AM com.jme3.scene.Node attachChild

INFO: Child (toon-geom-0) attached to this node (Root Node)

Jul 27, 2011 3:05:44 AM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform g_CameraPosition is not declared in shader.

Jul 27, 2011 3:05:44 AM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform g_WorldMatrix is not declared in shader.

Jul 27, 2011 3:05:44 AM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform m_EdgeSize is not declared in shader.

Jul 27, 2011 3:05:44 AM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform g_LightDirection is not declared in shader.

Jul 27, 2011 3:05:44 AM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

INFO: Uniform m_VertexColor is not declared in shader.

1 Like

Thanks for answering! You get it right!





Material within code:





[java]package FakeParticleBlow;



import com.jme3.app.SimpleApplication;

import com.jme3.asset.TextureKey;

import com.jme3.material.Material;

import com.jme3.material.RenderState.BlendMode;

import com.jme3.material.RenderState.FaceCullMode;

import com.jme3.math.ColorRGBA;

import com.jme3.renderer.queue.RenderQueue.Bucket;

import com.jme3.scene.Spatial;

import com.jme3.texture.Texture;

import com.jme3.util.SkyFactory;





public class FakeParticleBlow extends SimpleApplication {



Spatial fire;





public static void main(String[] args) {

FakeParticleBlow app = new FakeParticleBlow();

app.start();

}

private Material mat;





@Override

public void simpleInitApp() {



// TextureKey skyhi = new TextureKey(“Textures/Water256.dds”, true);

// skyhi.setGenerateMips(true);

// skyhi.setAsCube(true);

// final Texture texhi = assetManager.loadTexture(skyhi);





TextureKey skylow = new TextureKey(“Textures/Water32.dds”, true);

skylow.setGenerateMips(true);

skylow.setAsCube(true);

final Texture texlow = assetManager.loadTexture(skylow);



rootNode.attachChild(SkyFactory.createSky(assetManager, texlow, false));



fire = assetManager.loadModel(“Models/FakeParticleBlow/FakeParticleBlow.j3o”);

mat = new Material(assetManager, “MatDefs/FakeParticleBlow/FakeParticleBlow.j3md”);



Texture tex = assetManager.loadTexture(“Models/FakeParticleBlow/particles.png”);

tex.setWrap(Texture.WrapMode.Repeat);

mat.setTexture(“MaskMap”, assetManager.loadTexture(“Models/FakeParticleBlow/mask.png”));

mat.setTexture(“AniTexMap”, tex);



mat.setFloat(“m_TimeSpeed”, 1.0f);

mat.setBoolean(“Animation_Y”, true);

// mat.setBoolean(“Animation_X”, true);

mat.setBoolean(“Change_Direction”, true);





mat.setColor(“BaseColor”, new ColorRGBA(2.0f,1.0f,0.5f,1.0f));

mat.getAdditionalRenderState().setBlendMode(BlendMode.Additive);

mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);





fire.setQueueBucket(Bucket.Transparent);



fire.setMaterial(mat);

rootNode.attachChild(fire);



flyCam.setMoveSpeed(5);



}





@Override

public void simpleUpdate(float tpf){





}





}[/java]











Material within j3m:





[java]

package FakeParticleBlow;



import com.jme3.app.SimpleApplication;

import com.jme3.asset.TextureKey;

import com.jme3.material.Material;

import com.jme3.renderer.queue.RenderQueue.Bucket;

import com.jme3.scene.Spatial;

import com.jme3.texture.Texture;

import com.jme3.util.SkyFactory;



/** Sample 6 - how to give an object’s surface a material and texture.

  • How to make objects transparent, or let colors "leak" through partially
  • transparent textures. How to make bumpy and shiny surfaces. */

    public class FakeParticleBlow1 extends SimpleApplication {



    Spatial fire;





    public static void main(String[] args) {

    FakeParticleBlow1 app = new FakeParticleBlow1();

    app.start();

    }







    @Override

    public void simpleInitApp() {



    // TextureKey skyhi = new TextureKey("Textures/Water256.dds", true);

    // skyhi.setGenerateMips(true);

    // skyhi.setAsCube(true);

    // final Texture texhi = assetManager.loadTexture(skyhi);





    TextureKey skylow = new TextureKey("Textures/Water32.dds", true);

    skylow.setGenerateMips(true);

    skylow.setAsCube(true);

    final Texture texlow = assetManager.loadTexture(skylow);



    rootNode.attachChild(SkyFactory.createSky(assetManager, texlow, false));



    fire = assetManager.loadModel("Models/FakeParticleBlow/FakeParticleBlow.j3o");





    Material mat = assetManager.loadMaterial("Materials/FakeParticleBlow/FakeParticleBlow.j3m");

    fire.setMaterial(mat);



    fire.setQueueBucket(Bucket.Transparent);





    rootNode.attachChild(fire);



    flyCam.setMoveSpeed(5);



    }





    @Override

    public void simpleUpdate(float tpf){





    }





    }[/java]

You may be misusing g_Time as that is supposed to be set by the engine, not your code.



Time needs to be listed in the WorldParameters and the shader needs to have a g_Time uniform that it uses… but you should not have to set this from your own code.



I use this for the waving of Mythruna grass, so I know it works in principle. I can’t say why it is doing inconsistent strange things in your case but since you are doing something you shouldn’t, it could just be that when you set g_Time in code that the engine overrides it where it doesn’t get a chance when it’s part of the j3m. But I’m just speculating.

For the second issue, if you set your uniform using mat.setFloaf(“EdgeSize”,values); the uniform should be named m_EdgeSize in the shader.

@pspeed : I did it in WorldParameters and has g_Time.





Thi is my matdef:



MaterialDef FakeParticleBlow {



MaterialParameters {

Texture2D MaskMap

Texture2D AniTexMap

Float g_Time

Color BaseColor

Boolean Animation_Y

Boolean Animation_X

Boolean Change_Direction



}



Technique {

VertexShader GLSL100: Shaders/FakeParticleBlow.vert

FragmentShader GLSL100: Shaders/FakeParticleBlow.frag



WorldParameters {

WorldViewProjectionMatrix

Time



}



Defines {



ANY_DIR_Y : Animation_Y

ANY_DIR_X : Animation_X

CHANGE_DIR : Change_Direction





}

}



Technique FixedFunc {

}



}

You’ve masked the real value with a uniform. Take it out.



Edit: ie: the MaterialParameters Float g_Time should be removed.

@pspeed: Thanks for reply! g_Time is speed of animation parameter. If I remove it, so I will not be able to change speed animation. This parameter is vital, and it works inside of code. And you can see haw this shader works on that video: http://hub.jmonkeyengine.org/groups/contribution-depot-jme3/forum/topic/fakeparticleblow-shader/



@nehon: Thanks for answer. Do you mean I should use “m_” parameter for uniforms? I thought it was a deprecated parameter. :slight_smile: Well, I’ll try to make all my uniforms with “m_” and post here the result.

@pspeed: At that topic nehon recommended me to use g_Time: http://hub.jmonkeyengine.org/groups/graphics/forum/topic/how-to-animate-textures-in-jme3/ So I think g_Time should be used.

g_Time is set by the engine. You should never directly set anything starting with g_. I think @nehon was mistaken.



I use g_Time to animate my grass… and it varies with the system timer. I never actually set it. If I want to animate faster then I scale it in my shader.



Hmmm… unless he was recommending that you set it every frame to something faster than system time. Just setting it once really “shouldn’t” have any effect though it might as a side-effect of something else going wrong.

mifth said:
@nehon: Thanks for answer. Do you mean I should use "m_" parameter for uniforms? I thought it was a deprecated parameter. :) Well, I'll try to make all my uniforms with "m_" and post here the result.


He means that in the .vert and .frag files it is m_Foo. When you set it in code or in the material file it is just Foo. The engine prepends the m_ for you. m_ indicates (in the shader) a uniform set by code. g_ indicates a uniform set by the engine.

So I just read the linked thread and I think you misunderstood the content. I didn’t see a post where it was suggested that you set g_Time yourself… only that you can use it in a shader because the engine is setting the global value for you.



I’ll reiterate that you will have undefined and potentially bad/non-functioning behavior if you declare these g_ uniforms and set them yourself. Let the engine set them.

Oh, Thanks!!! I will try to experiment with “m_” and “g_” parameters!!! Thanks!!!

Nehon said in that topic about g_tpf and g_time:

Actually you can in JME3.

there is a g_Tpf ot g_Time uniform passed to the shader if you declare it in the worldParameters section of the j3md file




Ok, but how can I change speed of animation? g_tpf makes it faster or slower depending of its value. I saw direcX shader which used Time parameter too in the same way…

Is this your shader? g_Time moves at the speed of system time. If you want to move it faster then multiply it by some value inside the shader… ie: where it is used.

Something like: [java]g_Time *= m_Value;[/java] ???

I shy away from modifying uniform values directly in the shader. Paranoia about the bad things that happen if you do the same to vertex attributes.



…but presumably you are using g_Time somewhere and that is where I’d multiply it by your m_Value.



So, essentially, yes. Sort of. :slight_smile:

1 Like

Hi guys again!!!



About EdgeSize bug - it was my mistake. I did not use “m_” parameter in my fragment shader, so it worked incorrectly.



About g_Time bug - I changed g_Time to m_TimeSpeed parameter, but the bug presents. It perfectly works in my code, but it does not work in j3m Material. Looks like texture is not updated in j3m (with SimpleUpdate ()), or Tpf does not work in j3m.



My Code:





Vertex Shader:



[java]uniform mat4 g_WorldViewProjectionMatrix;

uniform float g_Time;



#if defined (ANY_DIR_Y) || defined (ANY_DIR_X)



uniform float m_TimeSpeed;

#endif



attribute vec3 inPosition;

attribute vec2 inTexCoord;



varying vec2 texCoord;

varying vec2 texCoordAni;



void main(){

gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);



g_Time *= m_TimeSpeed;





texCoord = inTexCoord;

texCoordAni = inTexCoord;









#if defined (ANY_DIR_Y) && !defined (CHANGE_DIR)

texCoordAni.y += g_Time;

#elif defined (ANY_DIR_Y) && defined (CHANGE_DIR)

texCoordAni.y -= g_Time;

#endif



#if defined (ANY_DIR_X) && !defined (CHANGE_DIR)

texCoordAni.x += g_Time;

#elif defined (ANY_DIR_X) && defined (CHANGE_DIR)

texCoordAni.x -= g_Time;

#endif





}[/java]







Fragment Shader:



[java]varying vec2 texCoord;

varying vec2 texCoordAni;



uniform vec4 m_BaseColor;



uniform sampler2D m_MaskMap;

uniform sampler2D m_AniTexMap;



void main(){



float Mask = texture2D(m_MaskMap, texCoord).r;

vec3 AniTex = texture2D(m_AniTexMap, vec2(texCoordAni)).rgb;



gl_FragColor.rgb = m_BaseColor.rgb * Mask * AniTex;

gl_FragColor.a = Mask;

}[/java]









Material Defenition:



[java]MaterialDef FakeParticleBlow {



MaterialParameters {

Texture2D MaskMap

Texture2D AniTexMap

Float TimeSpeed

Color BaseColor

Boolean Animation_Y

Boolean Animation_X

Boolean Change_Direction



}



Technique {

VertexShader GLSL100: Shaders/FakeParticleBlow.vert

FragmentShader GLSL100: Shaders/FakeParticleBlow.frag



WorldParameters {

WorldViewProjectionMatrix

Time



}



Defines {



ANY_DIR_Y : Animation_Y

ANY_DIR_X : Animation_X

CHANGE_DIR : Change_Direction





}

}



Technique FixedFunc {

}



}[/java]

So now it’s m_TimeSpeed that doesn’t work? Can we see the latest j3m that isn’t working right?

Yes, of cource. This is my material:







[java]Material Fake_Particle_Blow : MatDefs/FakeParticleBlow.j3md {

MaterialParameters {

MaskMap : Flip Models/jme_FakeParticleBlow/mask.png

AniTexMap : Flip Models/jme_FakeParticleBlow/particles.png

BaseColor : 2.0 1.0 0.5 1.0

Change_Direction : true

Animation_Y : true

TimeSpeed : 0.5

}

AdditionalRenderState {

FaceCull Off

Blend Additive

}

}



[/java]







And this is my code with j3m Material. “fire” is a plane (polygon) model:



[java]package ShaderBlow;



import com.jme3.app.SimpleApplication;

import com.jme3.asset.AssetKey;

import com.jme3.asset.TextureKey;

import com.jme3.material.Material;

import com.jme3.renderer.queue.RenderQueue.Bucket;

import com.jme3.scene.Spatial;

import com.jme3.texture.Texture;

import com.jme3.util.SkyFactory;



/** Sample 6 - how to give an object’s surface a material and texture.

  • How to make objects transparent, or let colors "leak" through partially
  • transparent textures. How to make bumpy and shiny surfaces. */

    public class FakeParticleBlow1 extends SimpleApplication {



    Spatial fire;





    public static void main(String[] args) {

    FakeParticleBlow1 app = new FakeParticleBlow1();

    app.start();

    }







    @Override

    public void simpleInitApp() {



    // TextureKey skyhi = new TextureKey("Textures/Water256.dds", true);

    // skyhi.setGenerateMips(true);

    // skyhi.setAsCube(true);

    // final Texture texhi = assetManager.loadTexture(skyhi);





    TextureKey skylow = new TextureKey("Textures/Water32.dds", true);

    skylow.setGenerateMips(true);

    skylow.setAsCube(true);

    final Texture texlow = assetManager.loadTexture(skylow);



    rootNode.attachChild(SkyFactory.createSky(assetManager, texlow, false));



    fire = assetManager.loadModel("Models/jme_FakeParticleBlow/FakeParticleBlow.j3o");

    fire.setMaterial( (Material) assetManager.loadAsset(new AssetKey("Materials/FakeParticleBlow.j3m")));







    fire.setQueueBucket(Bucket.Transparent);





    rootNode.attachChild(fire);



    flyCam.setMoveSpeed(5);



    }





    @Override

    public void simpleUpdate(float tpf){





    }





    }[/java]







    And here you can grab textures and a model:

    http://files.mail.ru/D9D9BT

Hi @pspeed ! I just want to ask about the bug with g_time… Is it really bug?

I have just released my shader library. ShaderBlow 0.3.



Now you can test it with mercurial. JMP Project: hg clone https://paulgeraskin@code.google.com/p/jme-glsl-shaders/ jme-glsl-shaders

Or download: http://code.google.com/p/jme-glsl-shaders/downloads/list



Threre are 2 examples. with j3m and with code. j3m still does not work.



Unlimited Free Image and File Hosting at MediaFire