PDA

View Full Version : Very very simple Shaders with Clootie?



cronodragon
14-10-2005, 08:54 PM
Hi! Does anyone has very simple examples of shaders using Clootie? I'm reading the sample BasicHLSL, but it's still too complicated for me. They have to setup several values, and the code is quite big so I have to scroll up and down to catch the ideas. I just want to see how to make and setup a shader, so I can duplicate the work in my project. Thanks on advance! 8)

Clootie
14-10-2005, 09:24 PM
Please, don't use me for simple shaders :!:

cronodragon
14-10-2005, 09:26 PM
Please, don't use me for simple shaders :!:

But I have to learn first :cry:

I need some light on shaders.

Clootie
14-10-2005, 09:31 PM
Will it help: MS description of BasicHLSL sample (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/TutorialsAndSamples/Samples/BasicHLSL.asp) ?

Another sample to look: HLSLWithoutEffects.
Also you can download samples from DirectX Summer 2003, they tend to use assembler coded shaders (but I totally forget that samples to look for them) - so no/less effect formats, constants already have fixed registers, etc.

Clootie
14-10-2005, 09:34 PM
Please, don't use me for simple shaders :!:

But I have to learn first :cry:


I don't mind if you use headers/samples I'm providing. By using ME as a shader?.. :shock:

cronodragon
14-10-2005, 09:35 PM
How the Sample Works

First the sample loads the geometry with D3DXLoadMeshFromX and calls D3DXComputeNormals to create mesh normals if there aren't any. It then calls OptimizeInplace() to optimize the mesh for the vertex cache, then loads the textures using D3DXCreateTextureFromFile. Next, the sample calls D3DXCreateEffectFromFile to compile the effect text file to a ID3DXEffect* interface called m_pEffect.

Note that the D3DXCreateEffectFromFile takes flags which are needed to debug shaders with the Microsoft Visual Studio .NET shader debugger. Debugging vertex shaders requires either a reference device or software vertex processing. Debugging a pixel shader requires a reference device.

The D3DXSHADER_FORCE_*_SOFTWARE_NOOPT flags set various source code debugging options. Setting these flags will cause slower rendering since the shaders will be unoptimized and forced into software. All that is needed to turn these flags on with the sample code is to uncomment the #define DEBUG_VS or #define DEBUG_PS line from near the top of the file. This will also force the device into software processing by adding some code to CMyD3DApplication::ConfirmDevices. See Shader Debugger for more information about debugging shaders.

In CMyD3DApplication::Render, the sample sets the technique to use with a call to ID3DXEffect::SetTechnique and passes a D3DXHANDLE to the technique that was obtained upon initialization with a call to ID3DXBaseEffect::GetTechniqueByName. It is possible to pass a string name instead of a handle, but using a handle improves performance since this high frequency call does not have to spend time on a string compare.

The sample then sets variables used by the technique such as the World*View*Projection matrix and the time variable with various ID3DXEffect::Set* calls. To render, the sample calls ID3DXEffect::Begin which returns the number of passes required by the technique, then loops through each pass calling m_pEffect->Pass(iPass) and rendering the mesh with ID3DXBaseMesh::DrawSubset. When all the passes are done, it calls ID3DXEffect::End.

Hmm, they do more than that in the code, and they don't mention it. :?

cronodragon
14-10-2005, 09:37 PM
By using ME as a shader?.. :shock:

I think there is a confussion with your name and the units you wrote... what's the name of those units? I thought it was Clootie too :shock:

Clootie
14-10-2005, 09:37 PM
When you probably should start from generic description of DXUT framework...

Clootie
14-10-2005, 09:39 PM
By using ME as a shader?.. :shock:

I think there is a confussion with your name and the units you wrote... what's the name of those units? :shock:
Something like Clootie's DirectX headers; MS DXUT / D3DFramework adaptation for Delphi?

cronodragon
14-10-2005, 09:41 PM
Now that's a name... somehow I prefer to call them Clootie :lol: It sounds like a friendly name.

I found this, but it's for Low Level Shaders:
http://www.flipcode.com/articles/article_ps20tut.shtml

(hmmm, I thought Flipcode was dead.)

cronodragon
15-10-2005, 08:26 PM
I found a very very simple tutorial for pixel shaders:
http://www.cfxweb.net/modules.php?name=News&file=article&sid=1305

Now I have shaders in my engine, yeah! 8)