# [D3D9] .fx file macro specific for Vertex Shader or Pixel Shader

## Recommended Posts

Posted (edited)

Hello,

I'm using .fx files for my shader code. The problem is that when compiling Effect (ID3DXEffect) the vertex and pixel shader code are compiled together.

The problem is Vertex Shader has limitation max 4 sampler registers, while pixel shader can hold 16. So the fx file won't compile because I want more than 4.

Now what I would like to do is put a #ifdef around the samplers (because they're not used in the vertex shader code anyway) so that my FX file will compile. But of course they have to be seen when the ID3DXEffect is compiled for the Pixel Shader part only.. So I need to be able to set a Macro only for when the ID3DXEffect compiles the Pixel Shader, but not the Vertex Shader.

However I can't seem to find out how 😥 It seems I can only do it by compiling vertex and pixel shaders myself and doing all that work myself, basicly losing the benefit of ID3DXEffect...

I was really hoping maybe D3DX sets a macro themselves that I can use, but I can't find any information about it anywhere.

Edited by ProgrammerDX

##### Share on other sites

Do the work yourself, really... Sooner or later you'll have to leave DX9, and in DX11+ there's no effect framework
It's not that complicated, at all: Setting a few states and such and calling the shaders..

##### Share on other sites
Posted (edited)

Well that's sad, because I'll end up writing the exact same thing as ID3DXEffect, just 'cause of a "define" problem.

Anyway, do you know how to set a texture? I see there's ID3DXConstantTable that I'll need to use to set uniform values, but there's no SetTexture like there's for ID3DXEffect. Is there any way?

texture BonesMap;

sampler BonesMapSampler = sampler_state
{
Texture   = (BonesMap);
MipFilter = None;
MinFilter = Point;
MagFilter = Point;
};

Edited by ProgrammerDX

##### Share on other sites
Posted (edited)
23 minutes ago, ProgrammerDX said:

Well that's sad, because I'll end up writing the exact same thing as ID3DXEffect, just 'cause of a "define" problem.﻿

Well higher level things always have limitations.  If I recall correctly, the underlying API is IDirect3DDevice9::SetTexture(samplerIndex, texture) and SetSamplerState(samplerIndex, type, value). Vertex shaders can access sampler registers 0-3 and pixel shaders 0-15.

sampler firstTexture: register(s0);
sampler lastTexture: register(s15);

It has been a really long time since I did D3D9, any reason for not upgrading? A lot of the D3DX stuff got replaced by things like DirectXTK, DirectXMath, and other utilties, that are open source with permissive licences, so if you use them you can see what is going on and if need be, change them.

Edited by SyncViews
note on DirectXTK

##### Share on other sites

Changing to DX11 isn't that trivial, sadly.

Do you happen to know what "D3DCOMPILE_PREFER_FLOW_CONTROL" is?

## Create an account

Register a new account

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 37
• 16
• 18
• 25