Methius
September 21, 2008, 1:23pm
1
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.
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
Woaw excellent result and simple shader program (easy when it's done)
I suppose it's a very high polygon model.
timong
September 22, 2008, 11:27am
5
Frightening! :-o Looks good!
i guess i might want to use that one…
timong
September 23, 2008, 2:38pm
7
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
clovis
September 23, 2008, 6:19pm
11
Hospital or Metroid Game!
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.
Methius
September 23, 2008, 8:46pm
13
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
Methius
September 23, 2008, 8:58pm
14
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.
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:
neakor
September 24, 2008, 5:13am
15
nice one. thx for sharing.
Indeed it's pretty good with low poly too
where are shaders called shaders? i mean, they don't really "shade" anything but completely pimp it up
Methius
September 24, 2008, 9:47pm
18
-> 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.
Methius
September 25, 2008, 12:01am
20
Off course not. I think jME needs a lot more "gimmicks", so happy to share.