Advertisement

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

Started by March 29, 2019 08:59 AM
5 comments, last by vinterberg 5 years, 10 months ago

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? ?

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

.:vinterberg:.

Advertisement

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;
};

 

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.

Changing to DX11 isn't that trivial, sadly.

Do you happen to know what "D3DCOMPILE_PREFER_FLOW_CONTROL" is?

https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/d3dcompile-constants

.:vinterberg:.

This topic is closed to new replies.

Advertisement