In this part we take the two critical lines of the last part (marked bold) and turn it into a complete HLSL shader. In this introduction I target Shader Model 3.0 which is compatible with DirectX 9.0c.
The shader code consists of 5 parts. The application inputs, the structures used (for input and output), the vertex shader(s), the pixel shader(s) and the technique(s). The vertex shader is executed for each vertex in the model and does the minimum it has to do, transform the model into clip space. The pixel shader is executed for each pixel and simply returns a fully opaque white pixel in this case. In the next part we'll add some diffuse lighting.// These are comments
// 1: Application inputsfloat4x4 object_to_clip: WORLDVIEWPROJECTION;
// 2: Structuresstruct vs_in {float4 pos_object: POSITION;};
struct ps_in {float4 pos_clip: POSITION;};
// 3: Vertex Shadersps_in vs_main(vs_in input) {ps_in output;output.pos_clip = mul(input.pos_object, object_to_clip);return output;}
// 4: Pixel Shadersfloat4 ps_main(ps_in input) : COLOR {return float4(1.f, 1.f, 1.f, 1.f);}
// 5: Techniquestechnique main {pass p0 {
VertexShader = compile vs_3_0 vs_main();
PixelShader = compile ps_3_0 ps_main();
}}
Geen opmerkingen:
Een reactie posten