LightBlow Shader

Thanks! It was one of my first shader… i missed it. Fixed in the mercurial repository.



I have 2 questions:


  1. about uniforms:

    I did simple fog in my lightblow.frag

    gl_FragColor.rgb = mix(fogColor.rgb,gl_FragColor.rgb,vec3(fogFactor));

    Is it allowed to make such operations with gl_FragColor?


  2. @normen , can you test my shaders in the mercurial repository to fix all bugs?

    hg clone https://paulgeraskin@code.google.com/p/jme-glsl-shaders/ - Mercurial repository.

    There is a JMP project with java examples. Simply, run all examples. They all should work.

    You are the only one person who has Mac (which I know).

    Thanks a lot beforehand.
@mifth said:
1) about uniforms:
I did simple fog in my lightblow.frag
gl_FragColor.rgb = mix(fogColor.rgb,gl_FragColor.rgb,vec3(fogFactor));
Is it allowed to make such operations with gl_FragColor?

gl_FragColor is not an uniform, it's a build in output parameter. So yes it's allowed, i'd say it's the very purpose of this variable.

Nice! Thank you @nehon !



Another question:

I have a post processor Cartoon edges. It makes additional geometry. It copies mesh and shift polygons.

When I switch this cartoon edge processor on, it creates additional geometry to all objects (which have this processor in MatDef).



Can I specify to some objects not to use this processor even if these objects have the processor in MatDef?

MatDef - http://code.google.com/p/jme-glsl-shaders/source/browse/assets/MatDefs/MatCap/MatCap.j3md

The processor is called CartoonEdge.

No you can’t, a PostProcessor is applied on a viewport, not on a scene.

You could put the objects you don’t want the effect on in another viewport.

Nice! That’s cool. THANK YOU!

Is it possible to place objects to another viewport when game started? I mean dynamically.

Yes create your new viewport in your simpleInit .

Each viewport will have a scene (rootNode for the main viewport and whatever for your second viewport)

You just have to switch objects from the rootNode to the other node.

Don’t forget to call updateLogicalState and updateGeometricState int he update loop^on the other node as it won’t be called automatically on it.

1 Like

@nehon , just another question about g_Time.



In FakeParticleBlow.vert I have such operation:

[java]

float thisTime = g_Time * m_TimeSpeed;

texCoordAni.y += thisTime;

[/java]





But what if texCoordAni.y will be equal more than allowed value for “float”? Will I get crush?

Should I add something to avoid it?

I guess like in any system you just get an overflow (going from max value to min value in one step). Since this looks like some constant movement thing it should be OK I think.

Thanks, @normen ! I hope it’s ok. I did another shader with such parameters like FakeParticleBlow.



I did an Animated Texture Shader.



http://i.imgur.com/v9NqI.jpg



Shader: http://code.google.com/p/jme-glsl-shaders/source/browse/assets/Shaders/SimpleSprite/?r=ecf224d6f57665c78fc9d9805132d14a0f46db10

MatDef: http://code.google.com/p/jme-glsl-shaders/source/browse/assets/?r=ecf224d6f57665c78fc9d9805132d14a0f46db10#assets%2FMatDefs%2FSimpleSprite

Materials: http://code.google.com/p/jme-glsl-shaders/source/browse/assets/?r=ecf224d6f57665c78fc9d9805132d14a0f46db10#assets%2FMaterials%2FSimpleSprite

Textures: http://code.google.com/p/jme-glsl-shaders/source/browse/assets/?r=ecf224d6f57665c78fc9d9805132d14a0f46db10#assets%2FTextures%2FSimpleSprite

@mifth said:
@nehon , just another question about g_Time.

In FakeParticleBlow.vert I have such operation:
[java]
float thisTime = g_Time * m_TimeSpeed;
texCoordAni.y += thisTime;
[/java]


But what if texCoordAni.y will be equal more than allowed value for "float"? Will I get crush?
Should I add something to avoid it?

I don't know for sure, but...when you think about it....
g_Time is the time in seconds since your process started.
There are around 31,5 million seconds in a year (which is 31,5 * 10 exp 6).
The max float capacity is 10 exp 308 on a 64 bit system (according to wikipedia).
So event at speed =10 I guess your process would have to run for millenniums before reaching the float maximum range.

Even if your shader rocks... There is a slight chance that it won't be used anymore in several millenniums ;)

I think this float is 32bit no? Anyway it shouldn’t be a problem I guess ^^

Even if I have such an operation:



[java]selectedTile += g_Time*m_Speed;



// the "1 - " bit is because otherwise it goes from right to left

texCoordAni.x = -(1 - ((texCoordAni.x + selectedTile % iNumTilesU) / iNumTilesU)); ///selectedTile;

texCoordAni.y = ((-texCoordAni.y - selectedTile / iNumTilesU) / iNumTilesV); ///selectedTile;

[/java]



m_Speed = 24;





Vertex shder is here: http://code.google.com/p/jme-glsl-shaders/source/browse/assets/Shaders/SimpleSprite/SimpleSprite.vert?r=ecf224d6f57665c78fc9d9805132d14a0f46db10

Thanks!

Well i guess it’s safe too, it’s just milleniums/24…

@mifth: i have downloaded the shadercollection_05, LightBlow works fine, but i get an error with the FakeParticleBlow, see image below:



this is the .vert file:

[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;





#ifdef FOG

varying float fog_z;

#endif



#if defined(FOG_SKY)

varying vec3 I;

uniform vec3 g_CameraPosition;

uniform mat4 g_WorldMatrix;

#endif





void main(){

gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);



float thisTime = g_Time * m_TimeSpeed;





texCoord = inTexCoord;

texCoordAni = inTexCoord;









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

texCoordAni.y += thisTime;

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

texCoordAni.y -= thisTime;

#endif



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

texCoordAni.x += thisTime;

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

texCoordAni.x -= thisTime;

#endif





#if defined(FOG_SKY)

vec3 worldPos = (g_WorldMatrix * pos).xyz;

I = normalize( g_CameraPosition - worldPos ).xyz;

#endif



#ifdef FOG

fog_z = gl_Position.z;

#endif



}

[/java]



@zzuegg said:
@mifth: i have downloaded the shadercollection_05, LightBlow works fine, but i get an error with the FakeParticleBlow, see image below:



I tracked the issue down, when both, Animation_X and Animation_Y are unchecked the shader will fail since m_TimeSpeed is not instanced.

@zzuegg , thanks for the report!

Fixed in the mercurial repository: http://code.google.com/p/jme-glsl-shaders/source/browse/assets/Shaders/FakeParticleBlow/FakeParticleBlow.vert?spec=svnde43c705f1189534132a2abbd254464a160a81af&r=de43c705f1189534132a2abbd254464a160a81af

ShaderBlow_06 is out.



LightBlow - uniforms optimization. Simple_IBL feature and example is added is added. Fixes for ATI video cards.



FakeParticleBlow fixes.



http://code.google.com/p/jme-glsl-shaders/downloads/detail?name=JME_ShaderBlow_06.zip&can=2&q=

And another good news - ShaderBlow library will be used in this project:

http://code.google.com/p/rise-of-mutants/



YAHOOOO!!!

A simple Model Viewer was made with lightBlow shader:



details here: http://code.google.com/p/rise-of-mutants/



http://www.youtube.com/watch?v=7zjIcAkW75o&feature=player_embedded

1 Like

Hi,



(i don’t know if i can post this here, if not, please let me know …)



can someone give out a code example to use the toon shader



I have setup the material correctly and i use this code

Code:
Material mat = assetManager.loadMaterial("Materials/LightBlow/Toon_System/Toon_Base.j3m"); thing.setMaterial(mat);

as i try to have an object outline (with no toon shading), the material is setup this way :
Code:
Material toon : MatDefs/LightBlow/LightBlow.j3md { MaterialParameters { Toon : false
    EdgesColor : 1.0 0.2 0.2 1.0
    EdgeSize : 5.5099998
    FogColor : 0.8 0.8 0.8 17.0

    Fog_Edges : true
    DiffuseMap : Textures/machine_texture.png
    SpecularMap : Textures/machine_gloss.png
    NormalMap : Textures/machine_normals.png
    Shininess : 1.2
 }
AdditionalRenderState {
}

}


but it does not show any outline :(
btw : why "Fog_Edges" ? why not "Edges" ?

thx