X-Ray Shader

Simple X-Ray Shader found on the net.

I didn’t find one through a search on the forum, so I thought I’d up it here.

Spare anyone the time from searching it themselves. :wink:







xray.frag

// vertex to fragment shader io
varying vec3 N;
varying vec3 I;
varying vec4 Cs;

// globals
uniform float edgefalloff;

// entry point
void main()
{
    float opac = dot(normalize(N), normalize(-I));
    opac = abs(opac);
    opac = 1.0-pow(opac, edgefalloff);
   
    gl_FragColor =  opac * Cs;
    gl_FragColor.a = opac;
}



xray.vert


// Application to vertex shader
varying vec3 N;
varying vec3 I;
varying vec4 Cs;

void main()
{
   vec4 P = gl_ModelViewMatrix * gl_Vertex;
   
   I  = P.xyz - vec3 (0);
   
   N  = gl_NormalMatrix * gl_Normal;
   
   Cs = gl_Color;
   
   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;   
}



Example usage:

GLSLShaderObjectsState xray = DisplaySystem.getDisplaySystem().getRenderer().createGLSLShaderObjectsState();
                xray.load(getClass().getClassLoader().getResource(
                        "xray.vert"),
                        getClass().getClassLoader().getResource(
                        "xray.frag"));
                xray.setEnabled(true);
                xray.setUniform("edgefalloff", 1f);

                skull.setRenderState(xray);



1 Like

that looks cool

Amazing!

Woaw excellent result and simple shader program (easy when it's done)



I suppose it's a very high polygon model.

Frightening!  :-o Looks good! :slight_smile:

i guess i might want to use that one…

HamsterofDeath said:

i guess i might want to use that one...


ye, me too, pro'ly for ghosts in jcrpg.
timong said:

HamsterofDeath said:

i guess i might want to use that one...


ye, me too, pro'ly for ghosts in jcrpg.


I must invent a need also to use it
theprism said:

timong said:

HamsterofDeath said:

i guess i might want to use that one...


ye, me too, pro'ly for ghosts in jcrpg.


I must invent a need also to use it


Yes it's a very precise use. Maybe in a Hospital game  :wink:

But the model on sreenshot have lot of polygons, I am not sure that the result is so good with a low poly model

I guess this can be used for a simple 'invisible' unit.



cool anyways… thanks for posting

Hospital or Metroid Game! :wink:

Methius, must say am in awe of you for delving into shaders, I have some mental block that prevents me for even trying to create a hello world shader.



MrCoder posted up some good resources a year ago specifying how to learn shaders along with resources of re-usable shaders.



Somehow am feeling that urge to go tinker again.

In reply to the statement that it would only look good on High Poly models:







FaceHugger

Verts: 7044

On Fps: 492

Off Fps: 561







Skeleton

Verts: 76460

On Fps: 160

Off Fps: 198

I suggest that you start learning Shaders by example.

Start by using working shaders and tweaking them.

It's more fun because if you have no knowledge of Shader programming it will take some time get something good working. :stuck_out_tongue:

At first I was just scanning through the documents, and trying all sorts of shaders, trying to get an interesting result. Now I'm a bit comfortable, i'm going through the tutorials to try to learn how to create my own shaders.



Currently I am using:


  • OpenGL

nice one. thx for sharing.

Indeed it's pretty good with low poly too :slight_smile:

where are shaders called shaders? i mean, they don't really "shade" anything but completely pimp it up

:smiley:

-> Shades -> Glasses to wear, with a different tag, only to make it sound cool.


Methius, have you any objection in adding this shader to the official jme demo's.


Off course not. I think jME needs a lot more "gimmicks", so happy to share.