Commit f65a68a4 authored by hybrid's avatar hybrid

Missing shader from Cg update, which was not committed in the last run.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4061 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 92d1b406
// part of the Irrlicht Engine Shader example. // part of the Irrlicht Engine Shader example.
// These simple Direct3D9 pixel and vertex shaders will be loaded by the shaders // These simple Direct3D9 pixel and vertex shaders will be loaded by the shaders
// example. Please note that these example shaders don't do anything really useful. // example. Please note that these example shaders don't do anything really useful.
// They only demonstrate that shaders can be used in Irrlicht. // They only demonstrate that shaders can be used in Irrlicht.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Global variables // Global variables
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
float4x4 mWorldViewProj; // World * View * Projection transformation float4x4 mWorldViewProj; // World * View * Projection transformation
float4x4 mInvWorld; // Inverted world matrix float4x4 mInvWorld; // Inverted world matrix
float4x4 mTransWorld; // Transposed world matrix float4x4 mTransWorld; // Transposed world matrix
float3 mLightPos; // Light position float3 mLightPos; // Light position
float4 mLightColor; // Light color float4 mLightColor; // Light color
// Vertex shader output structure // Vertex shader output structure
struct VS_OUTPUT struct VS_OUTPUT
{ {
float4 Position : POSITION; // vertex position float4 Position : POSITION; // vertex position
float4 Diffuse : COLOR0; // vertex diffuse color float4 Diffuse : COLOR0; // vertex diffuse color
float2 TexCoord : TEXCOORD0; // tex coords float2 TexCoord : TEXCOORD0; // tex coords
}; };
VS_OUTPUT vertexMain( in float4 vPosition : POSITION, VS_OUTPUT vertexMain(in float4 vPosition : POSITION,
in float3 vNormal : NORMAL, in float3 vNormal : NORMAL,
float2 texCoord : TEXCOORD0 ) float2 texCoord : TEXCOORD0 )
{ {
VS_OUTPUT Output; VS_OUTPUT Output;
// transform position to clip space // transform position to clip space
Output.Position = mul(vPosition, mWorldViewProj); Output.Position = mul(vPosition, mWorldViewProj);
// transform normal // transform normal
float3 normal = mul(vNormal, mInvWorld); float3 normal = mul(float4(vNormal,0.0), mInvWorld);
// renormalize normal // renormalize normal
normal = normalize(normal); normal = normalize(normal);
// position in world coodinates // position in world coodinates
float3 worldpos = mul(mTransWorld, vPosition); float3 worldpos = mul(mTransWorld, vPosition);
// calculate light vector, vtxpos - lightpos // calculate light vector, vtxpos - lightpos
float3 lightVector = worldpos - mLightPos; float3 lightVector = worldpos - mLightPos;
// normalize light vector // normalize light vector
lightVector = normalize(lightVector); lightVector = normalize(lightVector);
// calculate light color // calculate light color
float3 tmp = dot(-lightVector, normal); float3 tmp = dot(-lightVector, normal);
tmp = lit(tmp.x, tmp.y, 1.0); tmp = lit(tmp.x, tmp.y, 1.0);
tmp = mLightColor * tmp.y; tmp = mLightColor * tmp.y;
Output.Diffuse = float4(tmp.x, tmp.y, tmp.z, 0); Output.Diffuse = float4(tmp.x, tmp.y, tmp.z, 0);
Output.TexCoord = texCoord; Output.TexCoord = texCoord;
return Output; return Output;
} }
// Pixel shader output structure // Pixel shader output structure
struct PS_OUTPUT struct PS_OUTPUT
{ {
float4 RGBColor : COLOR0; // Pixel color float4 RGBColor : COLOR0; // Pixel color
}; };
sampler2D tex0; sampler2D myTexture;
PS_OUTPUT pixelMain( float2 TexCoord : TEXCOORD0, PS_OUTPUT pixelMain(float2 TexCoord : TEXCOORD0,
float4 Position : POSITION, float4 Position : POSITION,
float4 Diffuse : COLOR0 ) float4 Diffuse : COLOR0 )
{ {
PS_OUTPUT Output; PS_OUTPUT Output;
float4 col = tex2D( tex0, TexCoord ); // sample color map float4 col = tex2D( myTexture, TexCoord ); // sample color map
// multiply with diffuse and do other senseless operations // multiply with diffuse and do other senseless operations
Output.RGBColor = Diffuse * col; Output.RGBColor = Diffuse * col;
Output.RGBColor *= 4.0; Output.RGBColor *= 4.0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment