WIP Video (VERY early) + Rim Light Shader

Hi guys,



I have been putting off showing off anything I have been working on till I was happy enough with it, but that will be never, so I thought I would just bit the bullet and put up a video. I ripped out a quick rim light shader this afternoon that I think is very effective, I would be happy to share it/contribute if anyone was interest. (it inspired me to make the vid)



http://www.youtube.com/watch?v=bOu6JNePmns



The rim lighting is being applied to the big growing shere, there is subtle white rim light on the main character, a bright orange one around the bot. No post proccessing (besides pssm) is being applied as it makes the rim light less obviouse (great in production, bad when trying to demonstrait said rim shader).
love to get some feedback/questions :)

Cheers
James
7 Likes

Hey, that looks like some solid work there, congrats :slight_smile: Bots, animation, custom shaders, even bullet view ^^

I took the freedom to fix the youtube embed. And btw we love to see everything in all kinds of states, no worries :wink:

whats the performance like on it ? it looks amazing and i can see many uses for it, i like the whole camera following the ray thing you got there :stuck_out_tongue:

@normen thanks man. and cheers for all your help along the way, I have no doubts I will be calling on it again :wink:



@ryuu performance appears excellent (without any actual testing) , disabling the effect made virtually no difference to FPS in this project. I will run some proper benchmarks if it ends up being shared

Hi, @thetoucher !!! Actually, I’m interested in your shader. At present, I collect and develop shaders for JME3. If you share your shaders, so I will put them in my repository. Also, I can give you an access to my repository as a developer.



My Repository: http://code.google.com/p/jme-glsl-shaders/



Also, @chototsu has contributed his cartoon shader recently and I’m going to put it soon in the repository.

Discussion of his project - http://hub.jmonkeyengine.org/groups/free-announcements/forum/topic/mikumikudance-viewer/



So, you are welcome! :slight_smile:

That’s nice!!



The shader looks great, but actually, i’m more impressed by the whole wip shooting game than the shader itself.

Looks very promising!!



good work

@mifth sounds good, I will write up another post with details.



@nehon thank you :slight_smile:

Test Scene :



http://img819.imageshack.us/img819/9569/shotone.png

http://img862.imageshack.us/img862/1044/shottwo.png

http://img7.imageshack.us/img7/8624/shotthree.png



Performance:

not sure. When doing the above tests, the frame rate did change between light on or off.



Some Possible Uses :

Highlighting objects :: door knobs, chests, weapons ect… good for ā€˜picking’

works well in cartoon looking scenes to brighten edges

can be used for velvet effects.

great for xray effects



I have simply added a few lines to standard Lighting shader, so I will try and show what I did. Im not really sure the best way to share my code so I will just show all the changes I have made as best I can, and if someone could please halp advise me the best way to go from here :slight_smile: I’m sorry if this is in the wrong place or is unclear.



Common/MatDefs/Light/Lighting.j3md

[patch]

// the env map is a spheremap and not a cube map

Boolean EnvMapAsSphereMap

+

  • Color RimLighting;

    +

    }

    Technique {

    [/patch]



    [patch]

    USE_REFLECTION : EnvMap

    SPHERE_MAP : SphereMap

    +
  •        RIM_LIGHTING : RimLighting<br />
    

}

}

[/patch]



Common/MatDefs/Light/Lighting.vertfrag

[patch]

uniform ENVMAP m_EnvMap;

#endif

+

  • uniform vec4 m_RimLighting;

    float tangDot(in vec3 v1, in vec3 v2){

    [/patch]

    [patch]

    #endif

    gl_FragColor.a = alpha;

    +
  • #ifdef RIM_LIGHTING

    +
  • vec4 rim = pow( 1.0 - dot( normal, vViewDir.xyz ), 1.5 ) * m_RimLighting * m_RimLighting.w;
  • rim.a = 0.0;

    +
  • gl_FragColor += rim*diffuseColor;
  • #endif

    }

    [/patch]



    Usage

    usage is pretty simple …

    [java]float red = 0.0f;

    float blue = 0.0f;

    float green = 1.0f;

    float power = 0.5f;

    mat.setColor(ā€œRimLightingā€, new ColorRGBA(red,green,blue,power));[/java]



    The RimShader is a Color, alhpa is used as the ā€œpowerā€, the higher the power the greater the effect. power must be > 0.



    There is room to add some more customization to the appears by passing in a bias and additional power. There is probably plenty of room for optimization as well.
4 Likes

That actually looks like a pretty cool game! Great shader, btw!





-nomnom

that’s neat!

@Momoko_Fan what do you think, we should add this to the lighting shader, could make some neat effect for global illumination and like the toucher said can be used in many ways like selection.



Also it’s a good candidate for shader injection, isn’t it?

1 Like

Thank you, cool effect! I will add your shader to my LightBlow shader. If you want i can add any information about you or any resource. That effect is something like in Left4Dead2.









Uploaded with ImageShack.us

@mifth not really, this is more and outlined glow shader, the rim light light ā€œinsideā€ the object



btw, i have to take look at your light blow shader to see if we could include things in the actual lighting shader.

If you agree of course.

Aa, I understand. Yeah, glow post processing.

@nehon About lightblow shader, I’m fully agree. I’m glad to help core devs with it. If you find any errors, please tell me. :slight_smile:

mifth said:
I collect and develop shaders for JME3

Why isn't there an AssetPack or library plugin for jMP for them yet? :P

Its an interesting idea but yes it really should be added as a shader injector…

I noticed a bug, i think the rim lighting is being applied multiple times, once per light, I haven’t had a chance to open up the code yet to confirm or fix but I think it makes sense, I will have a look at fixing this in my lunch time (damn work)

Yes, the lighting shader is multipass, so it runs once per (non-ambient) light, it also runs once if the only thing you have is ambient lights in the scene.

normen said:
Why isn't there an AssetPack or library plugin for jMP for them yet? :P


it will be soon :)

ok, bug fix :

[patch]

  • uniform vec4 g_AmbientLightColor;

    [/patch]

    [patch]+if (length(g_AmbientLightColor.xyz) != 0.0) { // 1st pass only

    vec4 rim = pow( 1.0 - dot( normal, vViewDir.xyz ), 1.5 ) * m_RimLighting * m_RimLighting.w;

    rim.a = 0.0;

    gl_FragColor += rim*diffuseColor;

    +}[/patch]



    This was the easiest way I could figure out how get my code to execute once per frame in a multipass shader, I would love for some advice from some smart devs ( Momoko :slight_smile: ) on the correct way to do this, it was a pain to figure out and I know its wrong.

I guess its okay. Just make sure the ambient is really set … Maybe we can set the alpha on the ambient color to 1 if its the first light, and then set to 0 for subsequent lights