# [DX9] Common parameters for all shaders

## Recommended Posts

programci_84    336
Hi all.

Suppose I've more than one shaders and they include an ".fxh" file like this one:
//common.fxhuniform extern float3  g_ViewPos;uniform extern matrix  g_ViewMat;uniform extern matrix  g_ProjMat;//blah blah blah

You know some parameters can be set per frame (like the parameters above), but some others "must" be set per object (or subset).

Now, what I want to do is this: I want to fill all the parameters declared in common.fxh "once per frame", and these parameters can be used all the other shaders includes common.fxh.

How can I do that?

-R

##### Share on other sites
MJP    19756
If you want to avoid setting constants every frame you need to either use effect pools, or explicitly assign constants to registers so that there's no overlap. Like this:
// These are only set once per framefloat4x4 ViewMatrix : register (c0);float4x4 ProjMatrix : register (c4);// These are set every draw callfloat4x4 WorldMatrix : register(c8);

[Edited by - MJP on December 5, 2010 2:38:04 PM]

##### Share on other sites
skytiger    294
also check out the "shared" keyword in HLSL

##### Share on other sites
MJP    19756
Quote:
 Original post by skytigeralso check out the "shared" keyword in HLSL

"shared" is the keyword used by effect pools to denote constants shared between different effects.