Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


gordon13

Member Since 09 Jun 2010
Offline Last Active May 17 2013 05:17 PM

Topics I've Started

torque custom shader

14 May 2013 - 07:48 PM

Hello I'm learning shader programming and have come across a problem when attempting to add a custom shader to the Torque game engine. I looked at existing shaders that work in torque and tried to make my shader have the same format but the shader doesnt seem to load. theres no error message or anything that might give a clue to what could be wrong.
 
I made this in FX composer and modified the format to match existing torque shaders as best I can. 
It works in fx composer but not in torque. I'm thinking its something to do with the link between the engine and the shader. the shader isnt getting the data it needs and the engine isn't getting the shader stuff it needs  but cant seem to find any useful information or anything I can understand(at least up till now).
 
Could someone have a look at my files and shed some light? Id really appreciate it, thanks.
 
material.cs
 
shader.cs
 
heroV.hlsl
 
heroP.hlsl

New to shader programming(Rendermonkey)

09 June 2010 - 04:01 AM

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 :)

PARTNERS