Lets start! | -|||||||||||
-
-
-
- At first, we need to include all headers and do the stuff we always - do, like in nearly all other tutorials: -
Because we want to use some interesting shaders in this tutorials,
- we need to set some data for them to make them able to compute nice
- colors. In this example, we'll use a simple vertex shader which will
- calculate the color of the vertex based on the position of the camera.
- For this, the shader needs the following data: The inverted world
- matrix for transforming the normal, the clip matrix for transforming
- the position, the camera position and the world position of the object
- for the calculation of the angle of light, and the color of the light.
- To be able to tell the shader all this data every frame, we have to
- derive a class from the IShaderConstantSetCallBack interface and override
- its only method, namely OnSetConstants(). This method will be called
- every time the material is set.
The next few lines start up the engine. Just like in most other - tutorials before. But in addition, we ask the user if he wants this - example to use high level shaders if he selected a driver which is - capable of doing so. -
Now for the more interesting parts. If we are using Direct3D, we
- want to load vertex and pixel shader programs, if we have
In addition, we check if the hardware and the selected renderer
- is capable of executing the shaders we want. If not, we simply set
- the filename string to 0. This is not necessary, but useful in this
- example: For example, if the hardware is able to execute vertex shaders
- but not pixel shaders, we create a new material which only uses the
- vertex shader, and no pixel shader. Otherwise, if we would tell the
- engine to create this material and the engine sees that the hardware
- wouldn't be able to fullfill the request completely,
Now lets create the new materials.
Now its time for testing out the materials. We create a test cube - and set the material we created. In addition, we add a text scene node - to the cube and a rotatation animator, to make it look more interesting - and important. -
Same for the second cube, but with the second material we created. -
- Then we add a third cube without a shader on it, to be able to compare - the cubes. - -
- And last, we add a skybox and a user controlled camera to the scene. For - the skybox textures, we disable mipmap generation, because we don't need - mipmaps on it. - -
- Now draw everything. That's all. - -
- Compile and run this, and I hope you have fun with your new little shader - writing tool :). - |
-
Shader files | -||||||||||||||
-
-
- The files containing the shaders can be found in the media directory - of the SDK. However, they look like this: -
-
-
-
-
-
-
- |
-
-
- - + + +
Lets start! | +|||||||||||
+
+
+
+ At first, we need to include all headers and do the stuff we always + do, like in nearly all other tutorials: +
Because we want to use some interesting shaders in this tutorials,
+ we need to set some data for them to make them able to compute nice
+ colors. In this example, we'll use a simple vertex shader which will
+ calculate the color of the vertex based on the position of the camera.
+ For this, the shader needs the following data: The inverted world
+ matrix for transforming the normal, the clip matrix for transforming
+ the position, the camera position and the world position of the object
+ for the calculation of the angle of light, and the color of the light.
+ To be able to tell the shader all this data every frame, we have to
+ derive a class from the IShaderConstantSetCallBack interface and override
+ its only method, namely OnSetConstants(). This method will be called
+ every time the material is set.
The next few lines start up the engine. Just like in most other + tutorials before. But in addition, we ask the user if he wants this + example to use high level shaders if he selected a driver which is + capable of doing so. +
Now for the more interesting parts. If we are using Direct3D, we
+ want to load vertex and pixel shader programs, if we have
In addition, we check if the hardware and the selected renderer
+ is capable of executing the shaders we want. If not, we simply set
+ the filename string to 0. This is not necessary, but useful in this
+ example: For example, if the hardware is able to execute vertex shaders
+ but not pixel shaders, we create a new material which only uses the
+ vertex shader, and no pixel shader. Otherwise, if we would tell the
+ engine to create this material and the engine sees that the hardware
+ wouldn't be able to fullfill the request completely,
Now lets create the new materials.
Now its time for testing out the materials. We create a test cube + and set the material we created. In addition, we add a text scene node + to the cube and a rotatation animator, to make it look more interesting + and important. +
Same for the second cube, but with the second material we created. +
+ Then we add a third cube without a shader on it, to be able to compare + the cubes. + +
+ And last, we add a skybox and a user controlled camera to the scene. For + the skybox textures, we disable mipmap generation, because we don't need + mipmaps on it. + +
+ Now draw everything. That's all. + +
+ Compile and run this, and I hope you have fun with your new little shader + writing tool :). + |
+
Shader files | +||||||||||||||
+
+
+ The files containing the shaders can be found in the media directory + of the SDK. However, they look like this: +
+
+
+
+
+
+
+ |
+
+
+ + -- cgit v1.1