Pixel shaders are programs that run on the GPU to manipulate pixels. There are different types of shaders including pixel shaders, vertex shaders, and geometric shaders. Shaders replaced fixed functionality with programmability, allowing effects to be programmed. Popular shader programming languages include HLSL, GLSL, and Cg. Cg is a C-like language designed for GPU programming and shader development. It allows shaders to be written in a high-level language and compiled for different GPUs.
7. Effect of Shaders Replaced hard coded effects Gives a programmable alternative Fixed Function PipelineProgrammable Function Pipeline 3.Parallel Programming
13. Syntax and Semantics(1) Data Types: int, float, half, fixed, bool, sampler* Operators: Arithmetic and logical operators as in C Additional: arithmetic operations for vector and matrix operrations
14. Syntax and Semantics(2) Functions and Control Structures: Similar to C Standard Cg Library: Specialised GPU programming tasks Eg. Texture Mapping functions tex1D and tex2D Cg Runtime Library:Can be used with OpenGl or DirectX
15. Example Shader // input vertexstructVertIn { float4 pos : POSITION; float4 color : COLOR0; }; // output vertexstructVertOut { float4 pos : POSITION; float4 color : COLOR0; }; // vertex shader main entry VertOutmain(VertIn IN, uniform float4x4 modelViewProj) { VertOut OUT; OUT.pos= mul(modelViewProj, IN.pos); // calculate output coords OUT.color = IN.color; // copy input color to output OUT.color.z= 1.0f; // blue component of color = 1.0f return OUT; }
16. Games that Use Cg HIT MAN : Blood Money BATTLE FIELD 2 FAR CRY RACER And many more