1
\$\begingroup\$

I am in trouble at trying to pass a big amount of variables needed for my pixel shader computations.

After trying and failing to link my struct to a cbuffer (data alignement mismatch) I tried passing my variables first to the vertex shader (with an D3D11_INPUT_ELEMENT_DESC / CreateInputLayout) with the intent to link them to the pixel shader through semantics but I hit the 32 shader inputs limit.

I am really stuck (and quite a noob at DX). What is a common / standard way to do this ? Can I only rely on a cbuffer ? Is creating a D3D11_INPUT_ELEMENT_DESC / CreateInputLayout even possible for the pixel shader ?

Example struct I want to pass to my pixel shader :

struct SceneParamsInterface {
    bool DEAOEnabled;
    XMFLOAT4 DEAOColor;
    double DEAOPow;
    bool lightEnabled;
    XMFLOAT4 lightColor;
    XMFLOAT3 lightDirection;
    bool lightMultiply;
    double lightMultiplyFactor;
    bool ambiantLightEnabled;
    XMFLOAT4 ambiantLightColor;
    bool HSEnabled;
    int HSSpread;
    bool fogEnabled;
    XMFLOAT4 fogColor;
    double fogDistanceMax;
    bool glowEnabled;
    XMFLOAT4 glowColor;
    double glowRadius;
    XMFLOAT4 skyColor;
    bool skyBoxEnabled;
    //uniform sampler2D skyBoxTexture;
    int skyBoxScheme0; // top
    int skyBoxScheme1; // left
    int skyBoxScheme2; // front
    int skyBoxScheme3; // right
    int skyBoxScheme4; // back
    int skyBoxScheme5; // bottom
    int skyBoxRotate;
    double skyBoxRotateSpeed;
    XMFLOAT3 skyBoxRotateAround;
    bool orbitTrapsEnabled;
    int orbitTrapsId;
    XMFLOAT4 objectColor;
};

Thanks!

\$\endgroup\$
6
  • \$\begingroup\$ Can you tell us what the parameters are that you are passing and what you are doing with them in the shader? \$\endgroup\$ – Alan Wolfe Aug 16 '15 at 0:54
  • \$\begingroup\$ stackoverflow.com/questions/14711763/… \$\endgroup\$ – Ali1S232 Aug 16 '15 at 1:25
  • \$\begingroup\$ @AlanWolfe I didn't write the pixel shader code yet (I am porting GLSL code to HLSL) but I need all these variables (63+) available in my pixel shader for raytracing computation. I have 4 C++ structs for that purpose - see the one I posted up there. \$\endgroup\$ – PinkTurtle Aug 16 '15 at 12:25
  • \$\begingroup\$ Seeing nobody answered yet - I dont know much about dx11, but if you used openGl you could use texture or a buffer where usually geometry is stored. \$\endgroup\$ – wondra Aug 16 '15 at 21:51
  • 1
    \$\begingroup\$ This is the classic "Direct3D 9" design where you had to use a global set of constants. This is an extremely inefficient way to use Direct3D 11 Constant Buffers. See Windows to Reality: Getting the Most out of Direct3D 10 Graphics in Your Games--yes this is a Direct3D 10 era talk but it 100% applies to Direct3D 11 too. \$\endgroup\$ – Chuck Walbourn Aug 18 '15 at 3:02
7
\$\begingroup\$

Use several constant buffers and group variables together based on how often they change.

If your variables are fairly static ( or just huge ) you may be better off converting values into a texture and extracting them in the shader.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.