Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎯 Unreal

New to shader programming(Rendermonkey)

Started by gordon13 Jun 9, 2010 at 10:01 AM 0 replies 1.6k views
Original Post
gordon13
gordon13
Hi,
I need to create a refraction shader for a bullet trail effect in C#(Neoaxis engine).
Im totally new to this. Ive found one or two tutorials that got me started and Managed to make a simple Phong shader. Im a little confused with all the different elements of RenderMonkey. Im finding it hard to understand the example files so Im asking here.
I have a few questions:

If I was going to create a simple refraction shader(I just need some basic transparency and distortion(no need for cubemaps/reflections/whatever)), what would be a good way to start?

Im just trying to get my head around the program. Why are there two programming areas in a pass and whats the difference between the two?(Vertex Program, Fragment Program)

The tutorial shader:

Why is this part of the code in Vertex Program rather than Fragment?
------------------------------------------------------------------------
uniform vec3 LightPosition;
uniform vec3 EyePosition;

varying vec3 ViewDirection;
varying vec3 LightDirection;
varying vec3 Normal;

void main( void )
{

gl_Position = ftransform();

vec4 ObjectPosition = gl_ModelViewMatrix * gl_Vertex;

ViewDirection = EyePosition - ObjectPosition.xyz;
LightDirection = LightPosition - ObjectPosition.xyz;
Normal = gl_NormalMatrix * gl_Normal;

}

and why is this part in Fragment program rather than Vertex?:
----------------------------------------------------------------------
uniform vec4 Ambient;
uniform vec4 Specular;
uniform vec4 Diffuse;
uniform vec4 BaseColor;

uniform float SpecularPower;
uniform float RefractionPower;

varying vec3 ViewDirection;
varying vec3 LightDirection;
varying vec3 Normal;

void main( void )
{

vec3 LightDirection = normalize( LightDirection );
vec3 Normal = normalize( Normal );
float NDotL = dot( Normal, LightDirection );

vec3 Reflection = normalize( ( ( 2.0 * Normal ) * NDotL ) - LightDirection );
vec3 ViewDirection = normalize( ViewDirection );
float RDotV = max( 0.0, dot( Reflection, ViewDirection ) );

vec4 TotalAmbient = Ambient * BaseColor;
vec4 TotalDiffuse = Diffuse * NDotL * BaseColor;
vec4 TotalSpecular = Specular * ( pow( RDotV, SpecularPower ) );

gl_FragColor = ( TotalAmbient + TotalDiffuse + TotalSpecular );

}


I hope someone can shed some light :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.