Hello,
I was curious about the shading performance... and to prove that it actually
happens in realtime... I made this little example which uses a special
semantic provided by FX Composer 2.5 called "TIME" which returns the time in
seconds in floating point format.
These seconds have been used as the input for cosine and sine functions to
provide a fade in and fade out value... which is then used for the red,
green, blue...
First I fed the texel color into the cosine and sine functions as well which
produced a palette like shading... But I actually though these were the
positions but it was not... so then I changed it... and now the true
positions are fed into the cosine and sine functions just to see how it
would... the texel color is also added to the output... Lot's of
possibilities to play with this.
Dividing the texel color by the output of the cosine/sine formula's produced
some kind of glowing like shading which was also kinda nice but a bit rough
too
The code as it is now is best just to demonstrate the shading in action...
even a black image would show the bars going over it !
(Press play in FX Composer 2.5 to see it in action

)
// *** Begin of Code ***
/*
Basic Texture example
(Also known (by me) as Spaceship Texture example, uses "Warpship.bmp")
version 0.01 created on 21 september 2009 by Skybuck Flying
Features:
FX Composer 2.5 examples:
+ Basic 2d texture declaration with annotations
+ Basic 2d sampler declaration with sampler states
+ Basic vertex shader with:
position 3d in/ 4d out
texture coordinate0 2d in/ 2d out
+ Basic pixel shader with:
texture coordinate 2d in
pixel color 4d out
+ Uses nice input/output structures no stupid/confusing return values

+ Uses nice naming convention, delphi like
Usage:
Step 1: Drag and drop material to object.
Step 2: Select object.
Step 3: Change SpaceShipTexture parameter in properties, and add/select an
image.
*/
/*
version 0.02 created on 22 september 2009 by Skybuck Flying
Example fixed to make debugging possible.
(Void shaders do currently not work with the nvidia shader debugger)
From the nvidia shader debugger documentation:
"
Shaders which return a value using only out parameters are currently not
supported.
You can work around this issue by making sure your shaders contain an
explicit return statement.
"
I tried:
void test()
(
return;
)
But that doesn't work.
So code needs to be changed to:
returntype test()
{
return variable of returntype
}
The necessary code changes have been made below.
Also after making these code changes it requires a close/re-open of the
project to make it work.
(Or a recompile or double click on material not sure but after some fiddling
it should work.)
*/
/*
Time shader example
(based on Basic (Spaceship) Texture Shader example version 0.02)
version 0.01 created on 22 september 2009 by Skybuck Flying
+ TIME semantic is used to prove that it's indeed a realtime shader.
+ Cos/Sin is used to cycle the colors over time.
+ Time, texel position x and y are fed into the cosine and sine functions to
produce some form
of random shading, the texel color X, Y, Z is then added to the output.
Currently shading looks like lights move over the texture and over
exposing it.
(For alternative shading examples try multiple or dividing the texel x,y
and z by the output of the functions)
(Another alternative for shading is to feed the texel colors themselfes
into the cosine and sine functions,
this would resemble a more palette like shading).
+ Demonstration how to use floating point divisions and mod (%) together.
Floating point divisions must have .0 in the floating point values
to indicate that it should be a floating point division and not
an integer division (integer division would round it to zero or one or so
permaturely !).
Usage:
Press play to see the realtime shading in action.
*/
texture SpaceShipTexture
<
string ResourceName = ""; // must be set in fx composer gui/properties.
string UIName = "SpaceShipTexture";
string ResourceType = "2D";
>;
sampler2D SpaceShipSampler2D = sampler_state
{
Texture = <SpaceShipTexture>;
MinFilter = Point;
MipFilter = Point;
MagFilter = Point;
AddressU = Clamp;
AddressV = Clamp;
};
float4x4 WorldViewProj : WorldViewProjection;
struct TVertexShaderIn
{
float3 mPosition : POSITION;
float2 mTextureCoordinate0 : TEXCOORD0;
};
struct TVertexShaderOut
{
float4 mPosition : POSITION;
float2 mTextureCoordinate0 : TEXCOORD0;
};
// void routines not supported by nvidia shader debugger
/*
void TVertexShader_Main( in TVertexShaderIn ParaIn , out TVertexShaderOut
ParaOut )
{
ParaOut.mPosition = mul(WorldViewProj, float4(ParaIn.mPosition.xyz, 1.0));
ParaOut.mTextureCoordinate0 = ParaIn.mTextureCoordinate0;
}
*/
// return routines/functions do work in nvidia shader debugger:
TVertexShaderOut TVertexShader_Main( in TVertexShaderIn ParaIn )
{
TVertexShaderOut ParaOut;
ParaOut.mPosition = mul(WorldViewProj, float4(ParaIn.mPosition.xyz, 1.0));
ParaOut.mTextureCoordinate0 = ParaIn.mTextureCoordinate0;
return ParaOut;
}
struct TPixelShaderIn
{
float2 mPosition : TEXCOORD0;
};
struct TPixelShaderOut
{
float4 mColor : COLOR;
};
// void not supported by nvidia shader debugger
/*
void TPixelShader_Main( in TPixelShaderIn ParaIn, out TPixelShaderOut
ParaOut )
{
ParaOut.mColor = tex2D( SpaceShipSampler2D, ParaIn.mPosition );
}
*/
float gPI = 3.1415926535897932384626433832795;
float gSeconds : TIME;
// return routines/functions do work in nvidia shader debugger:
TPixelShaderOut TPixelShader_Main( in TPixelShaderIn ParaIn )
{
TPixelShaderOut ParaOut;
float4 vTexel;
float4 vOutput;
vTexel = tex2D( SpaceShipSampler2D, ParaIn.mPosition );
// vOutput.x = vInput.x - vInput.y;
// vOutput.y = vInput.y;
// vOutput.z = vInput.z - vInput.y;
vOutput.x =
vTexel.x +
(
(
1.0 + cos
(
(ParaIn.mPosition.x * sin(gSeconds/2.0) * cos(gSeconds/2.5) +
gSeconds/7.0)*gPI*2
)
) / 2.0
);
vOutput.y =
vTexel.y +
(
(
1.0 + sin
(
(ParaIn.mPosition.y * cos(gSeconds/1.5) * sin(gSeconds/3.5) +
gSeconds/5.0)*gPI*2
)
) / 2.0
);
vOutput.z =
vTexel.z +
(
(
1.0 + cos
(
(ParaIn.mPosition.x * sin(gSeconds/2.0) * cos(gSeconds/2.5) *
ParaIn.mPosition.y * cos(gSeconds/1.5) * sin(gSeconds/3.5) +
gSeconds/3.0)*gPI*2 + gPI/2.0
)
) / 2.0
);
ParaOut.mColor = vOutput;
return ParaOut;
}
technique technique0 {
pass p0 {
CullFaceEnable = false;
VertexProgram = compile vp40 TVertexShader_Main();
FragmentProgram = compile fp40 TPixelShader_Main();
}
}
// *** End of Code ***
Bye,
Skybuck.