Skip to main content
gamedev.net
🔒 Locked

HLSL semantics

Started by edwinnie Jul 14, 2004 at 7:30 AM 1 replies 1.3k views
Original Post
edwinnie
edwinnie
hihi! suppose i got this in an fx file: Matrix worldViewProj : WorldViewProjection; do i need to bind the effect handle with my own MVP or HLSL will calculate one for me? And if HLSL calculates one for me, how do initiate it (eg in Cg we got CG_MODELVIEW_PROJECTION enums to help us...etc)? thx! Edwinz
circlesoft
circlesoft
No, HLSL will not calculate it for you. You have to do it yourself, and then set it. When you are using Nvidia's FX Composer or ATI's RenderMonkey, it automatically searches for semantics in the file, and binds them to the appropriate matrix/texture/vector/constant. In your own applications, you have to do this yourself. Here is an example:
// wvpHandle is of type D3DXHANDLE// effect is of type ID3DXEffect*InitEffects(){   // Load the effect, compile it...      // Now find the matrix with the semantic WorldViewProjection   if( NULL == ( wvpHandle = effect->GetParameterBySemantic( NULL, "WorldViewProjection" ) ) )   {      // wvpHandle is null, it couldn't be found      // Handle accordingly   }}Render(){   // Begin the effect, set the technique...   // Calculate the WorldViewProjection matrix   D3DXMATRIX matWVP = matWorld * matView * matProj;   // Set matWVP as the WorldViewProjection matrix in the shader   effect->SetMatrix( wvpHandle, &matWVP );   // Render the object, end effect...}
The useful part about doing it this way is that you can actually define your own semantics, if needed. For example, you could define your own texture semantic scheme for all of your shaders:
- Diffuse semantic indicates it's the diffuse texture
- Normal semantic indicates it's the normal mapping texture
And so on...

The nice thing about this is that you don't have to keep all of the same variable names in all of your shaders - just the semantics.
edwinnie
edwinnie
HIHI!
oh cool, so get the param by semantics, i was doing a get param by name earlier...right!

thx!
Edwinz

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.