Pixel shader tutorial part 2 - textures

Posted on:October 28 2005

This is the second part of the pixel shader tutorial. In the first part, we simply drew green pixels using a simple pixel shader. A pixel shader is nothing more than a short program executed on the GPU for every pixel, to calculate the color of every pixel. To make the last example a bit more interesting, we will now draw a texture instead of the green color. And because this is quite boring too, we will change the color of the texture a bit: Just make it a little bit brighter. The code for the second pixel shader looks like this, just replace the string in the beginning of the first program:
"sampler2D tex0;                                      \
\
float4 pixelShader( float2 texCoord : TEXCOORD0, \
float4 color : COLOR0 ) : COLOR0 \
{ \
float4 c = tex2D( tex0, texCoord ); \
c = c * float4(2,2,2,2); \
return c; \
}";
Right, this code is executed for every pixel on the screen. The first line gets the color of the texture tex0 using the tex2D function. The second line multiplies the color by 2, to make it brighter. Simple. If you use a texture like this:
The result of the program will look like this:
Yep, it's better than the green, boring cube. But not much. We'll have to improve this situation in the next part. :)





Comments:


this isnt new niko its the same method used for the normal and displacment maps materials shaders in the cpp code
omaremad
Quote
2005-10-29 01:12:00


opps i hought you meant it was a new feature
omaremad
Quote
2005-10-29 01:16:00


isnt it more interesting to read a pixel color and change it slightly to obtain some fancy effect?

this is pretty cool btw, i had no idea how shaders work!
Armen138
Quote
2005-10-29 12:29:00


Add comment:


Posted by:


Enter the missing letter in: "Internation?l"


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons