Yop
nop, a pixel shader doesn't need a texture to work, it role is mainly to compute the color for each pixel on screen :p
for example :
- Code: Select all
void main
(
in float2 uv0 : TEXCOORD0,
out float4 color0 : COLOR0,
in float2 vpos : VPOS
)
{
// final color
color0 = float4(1, 0, 0, 1);
}
simply colorize every pixel in red, the float4 color0 is final the rgba color for each pixel on screen, varying each channel color from 0 to 1, so we can say that 1 is the 255 usual max value used in rgb code, example for red color => 255,0,0.
uv0 and vpos are used to compute the pixel position
- uv0 with uv values (screen range from 0 to 1)
- vpos with screen dimensions (screen resolution in real pixel size)
so if you write for example :
- Code: Select all
color0 = float4(1*uv0.y,0,0,1);
you obtain a black/red gradiant on height (uv0.y) because uv0.y is varying from 0 to 1 (0 is top, 1 is bottom of screen), so if multiply uv0.y per 1 result varying from 0 to 1 (exemple in middle screen => 0.5*1 = 0.5, so color of each pixel at screen center will be 0.5 for the red channel, so a dark red).
another example with vpos (real screen dimension), if you write :
- Code: Select all
if(vpos.x > 400)
color0 = float4(1,0,0,1);
it said, if current pixel position at screen.x position is greater than 400 so we colorize it in red.
you can compute position ranging from 0 to 1 for vpos if you divide it per screen resolution :
- Code: Select all
float p = vpos.x / resolution.x;
color0 = float4(1*p,0,0,1);
and you obtain the same gradiant effect but based on screen dimension, it usefull to compute real shape size based on screen aspect.
So the role of the game is to compute for each pixel a color using its coordinate.
Using textures in shaders is an option, and works the same, you "read" the pixel color on the texture and you do what you want with (mix this color with the current screen color, substract, add etc... all rest is mathematics)
for example :
- Code: Select all
sampler2D s0 : register(s0);
void main
(
in float2 uv0 : TEXCOORD0,
out float4 color0 : COLOR0,
in float2 vpos : VPOS
)
{
color0 = float4(1*uv0.x,0,0,1) * tex2D(s0,uv0);
}
tex2D return the pixel color of the s0 texture (here s0 is the current screen render, so actual screen pixels colors) using the uv0 coordinates (so the screen uv's coord) and we multiply this pixel color result with the current pixel color of screen.
So stack a cube mesh instead of a null scene node on customIPP input and the gradiant will be applied on the cube and the whole screen.
test with another textures on customIPP input
declared with :
- Code: Select all
sampler2D s1 : register(s1);
and multiply again the result of this texture :
- Code: Select all
color0 = float4(1*uv0.x,0,0,1) * tex2D(s0,uv0) * tex2D(s1,uv0);
test different math operations instead mul, and you will experiment differents results.