Shader Tuts

Started by
14 comments, last by Giallanon 18 years, 8 months ago
Evenin' all, I've been searching for some good HLSL material for a while now, and I'm coming up with nothing... Very surprising how the Internet seems to have so little information on the subject!! The book shader X2 seems to be quite popular, but I'd like to learn more with some free tutorials before I go splashing out on books...! In particular, I'm looking at multitexturing. I have both a vertex and a pixel shader working fine... only they are as simple as they get... but my attempt at multitexturing is failing... Much to my dissapointment, the texture object and sampler object is VERY poorly documented! I haven't yet figured them our properly. Any help with my troubles would be much appreciated! Some advice, or leeds on where to get some info would be great. Thanks in advance, Dachande
Advertisement
NVidia FX Composer and ATIs RenderMonkey both come with lots of example shaders that might help but I agree there is limited info. on the net.
------------------------See my games programming site at: www.toymaker.info
I picked up the very basics from the book Managed DirectX 9 kickstart by Tom Miller. It has a few chapters introducing HLSL and helping you on your way. A bit limited perhaps, but it contains some good examples.

The NVidia SDK indeed provides a pile of HLSL shaders and the FX composer sounds like a great tool (haven't had time to check it out yet), so that's a good bet. From what I saw though, the NVidia sample shaders are a bit overwhelming and mostly require ps/vs 2.0 hardware.

On the MSDN you can find a helpful reference of HLSL intinsics, but beyond that there are few other pratical resources.

So, if anyone could recommend a good book about HLSL that'd be great. Preferably starting with the basics, discussing some more advanced effects and -mostly importantly- providing additional documentation of HLSL to supplement the sorely lacking docs on the net...
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Maybe people can tell us how they learnt to use shaders, and what resources
they used, whether that was books, sdk docs or the nvidea tutorials,
Hi there dachande,
How are you doing?

The Problem
Shader tutorials. Resources on shaders etc...

The Solution
I hope I'm not being condescending when I say that make sure you know your pipeline and how things are done in the fixed function pipeline before moving to shaders, such as how matrices are transformed and spaces. Spaces are probably one of the components that you need to know very well. Model Space, World Space, View Space, Clip Space...

To finish this off I have a link to a very interesting tutorial on shaders.
HLSL Introduction

I hope this helps buddy. Take good care and if you have any other questions, please don't hesitate to ask :)
I just re-read your topicstart and figured that this article about HLSL terrain rendering might help out. It covers terrain multitexturing based on height, by blending two seperate textures. This should provide you with some idea to get started. It requires sm2 though.

And I recalled I found some very nice free shaders the other day, which you can find on this page. These do focus on image post-processing, but they are generally well documented and shoud how to create some very nice effects.

Sorry I didn't post this earlier, but I kinda kicked into complain-mode when I saw I wasn't the only one not able to find proper tutorials and references for HLSL, especially since it was so late :)
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Good link. On the book front I recommend Programming Vertex and Pixel Shaders by Wolfgang Engel.
------------------------See my games programming site at: www.toymaker.info
Thanks all for your helpful replies :)

I've been through all the links, I've used RenderMonkey and FXComposer, and downloaded all sorts of example code... but I still have found no clear explanation of using multiple textures (this is not my only hangup, but it is a big one!).

Sampler objects and texture objects are often declared, but not referenced again until a call to tex2d(sampler, coords) etc... There is no clear link between the sampler, and which texture it connects to - as far as I can see.

basically (pseudoish!):

sampler ASampler;
sampler BSampler;

float4 PSmain(float2 tex : TEXCOORD0, float2 tex2 : TEXCOORD1) : COLOR
{
float2 ACol = tex2d(ASampler, tex);
float2 BCol = tex2d(BSampler, tex2);
}

I see no link between samplers and textures! I'm totally open to the possibility that I'm being dumb... BUT I know that this stuff simply isn't documented to a satisfactory mannor in the docs!

Generally I'm not too bad at this stuff, but I get hung up on details that I don't understand :D

Can anyone shed some light?

Thanks,

Dachande
Quote:Original post by dachande
I see no link between samplers and textures! I'm totally open to the possibility that I'm being dumb... BUT I know that this stuff simply isn't documented to a satisfactory mannor in the docs!


The Sampler construct is equivalent to IDirect3DDevice9::SetSamplerState() in the FFP. It controls all of the options like AddressU/V/V, Mip filter, min filter, and mag filter. Basically, it controls how your texture is read and what type of prosessing goes into it.

A Sampler is linked to a texture like this:

sampler TextureSampler = sampler_state {    texture = <diffuseTexture>;    AddressU  = CLAMP;            AddressV  = CLAMP;    AddressW  = CLAMP;    MIPFILTER = LINEAR;    MINFILTER = LINEAR;    MAGFILTER = LINEAR;};


MSDN used to have an excerpt from the first chapter of ShaderX2 on it, but I can't seem to find it.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Hi mate,

To use a texture sampler, you have to declare it. Just make sure you set a relevant texture into your device via a pDevice->SetTexture(samplerNum, texture) and away you go. E.g:

sampler tex0;
sampler tex1;

// will become in asm:
dcl_2d s0
dcl_2d s1

One thing to look out for is that the HLSL compiler will not declare any samplers that are not used (even in if the DEBUG options are used) so if you do something like:

sampler tex0;
sampler tex1;
sampler tex2;

// Sampler tex1 is not referenced in the code
float4 diffuse = tex2D(tex0, IN.textureCoords);
float3 normal = tex2D(tex2, IN.textureCoords);

// The asm generated will be something like
dcl_2d s0
dcl_2d s1
texld r0, t5, s0 // tex2D(tex0, IN.textureCoords)
texld r1, t5, s1 // tex2D(tex2, IN.textureCoords) <- s1 is used rather than s2!

In this instance your normal var will contain whatever comes from texture sampler 2 rather than 1, which is not likely to be a normal :).

T

This topic is closed to new replies.

Advertisement