Jump to content
  • Advertisement
Sign in to follow this  
ProgrammerDX

[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.

Anyone has the answer? 🙏

Edited by ProgrammerDX

Share this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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;
    AddressU  = Clamp;
    AddressV  = Clamp;
};

 

Edited by ProgrammerDX

Share this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!