09
Jun
09

Simple X-Ray Shader

From Ogre3D.

/* Vertex Shader */

varying vec3 P;
varying vec3 N;
varying vec3 I;

void main()
{
	//Transform vertex by modelview and projection matrices
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	
	// Position in clip space
	P = vec3(gl_ModelViewMatrix * gl_Vertex);
	
	// Normal transform (transposed model-view inverse)
	N = gl_NormalMatrix * gl_Normal;
	
	// Incident vector
	I = P;
	
	// Forward current color and texture coordinates after applying texture matrix
	gl_FrontColor = gl_Color;
	gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
}

/* Fragment Shader */

varying vec3 P;
varying vec3 N;
varying vec3 I;

uniform float EdgeFalloff;

void main()
{
	float opacity = dot(normalize(N), normalize(-I));
	opacity = abs(opacity);
	opacity = 1.0 - pow(opacity, EdgeFalloff);
	
	gl_FragColor = opacity * gl_Color;
}
Advertisements

2 Responses to “Simple X-Ray Shader”


  1. 1 el toro
    November 22, 2011 at 6:18 am

    Do you have any references for this shader – e.g. a comprehensive text on the theory behind it

    • 2 toneburst
      April 12, 2012 at 11:49 am

      Hi there.

      I’m afraid I don’t. I’m not very good at documentation, unfortunately (this website was an attempt to be a bit better, in fact). The shader came either as part of the Ogre3D library, or from a forum associated with it. I can’t remember which, though.

      My understanding of how the shader works is that surface opacity is changed according to the normal orientation. There’s no directional lighting involved. It’s a very simple setup. You could combine this with other lighting models to enhance the effect.

      Hope this helps,

      a|x


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Twitter

June 2009
M T W T F S S
« May   Jul »
1234567
891011121314
15161718192021
22232425262728
2930  

Links

Blog Stats

  • 468,884 hits

%d bloggers like this: