Skip to content
Oliver edited this page Sep 21, 2021 · 8 revisions

About

This page will be dedicated to identifying what the input and output parameters are for various shaders are as well as, the various resources that should be included in shaders for various render techniques and preprocessor flags. At the moment I don't have a lot of that kind of information :/

Game Script MapShaderConstant()

You can actually use the MapShaderConstant() built-in function to set the shader contants. I see a lot of scripts set stuff in the GpuShaderConstantSet buffer but, I think this also works on any constants defined by your Techset and GDT file too.

Preprocessor flags

  • TOOLSGFX
  • USING_HLSL
  • IS_VERTEX_SHADER
  • IS_PIXEL_SHADER
  • IS_GEOMETRY_SHADER
  • IS_COMPUTE_SHADER
  • IS_HULL_SHADER
  • IS_DOMAIN_SHADER

Constant Buffers List

From gbuffer_lit.hlsl for TOOLSGFX 0 and other unknown flags

cbuffer PerSceneConsts
{
  row_major float4x4 projectionMatrix; // Does not work on 2D shaders
  row_major float4x4 viewMatrix; 
  row_major float4x4 viewProjectionMatrix; 
  row_major float4x4 inverseProjectionMatrix;
  row_major float4x4 inverseViewMatrix;
  row_major float4x4 inverseViewProjectionMatrix;
  float4 eyeOffset;
  float4 adsZScale;  // Unknown
  float4 hdrControl0; // Unknown
  float4 hdrControl1; // Unknown
  float4 fogColor; // Unknown Context (Global fog color?)
  float4 fogConsts; // Unknown
  float4 fogConsts2; // Unknown
  float4 fogConsts3; // Unknown
  float4 fogConsts4; // Unknown
  float4 fogConsts5; // Unknown
  float4 fogConsts6; // Unknown
  float4 fogConsts7; // Unknown
  float4 fogConsts8; // Unknown
  float4 fogConsts9; // Unknown
  float3 sunFogDir; // Unknown
  float4 sunFogColor; // Unknown Context (Is this the combined sun color + global fog?)
  float2 sunFog; // Unknown
  float4 zNear; // Unknown Context
  float3 clothPrimaryTint; // Unknown
  float3 clothSecondaryTint; // Unknown
  float4 renderTargetSize; 
  float4 upscaledTargetSize; // Unknown
  float4 materialColor; // Unknown Context (What material does this refer to?)
  float4 cameraUp; 
  float4 cameraLook; // Does not work on 2D shaders (Not tested on 3D)
  float4 cameraSide; 
  float4 cameraVelocity; 
  float4 skyMxR; // Unknown
  float4 skyMxG; // Unknown
  float4 skyMxB; // Unknown
  float4 sunMxR; // Unknown
  float4 sunMxG; // Unknown
  float4 sunMxB; // Unknown
  float4 skyRotationTransition; // Unknown
  float4 debugColorOverride; // Unknown, These debug things might get set by some debug commands in the console
  float4 debugAlphaOverride; // Unknown
  float4 debugNormalOverride; // Unknown
  float4 debugSpecularOverride; // Unknown
  float4 debugGlossOverride; // Unknown
  float4 debugOcclusionOverride; // Unknown
  float4 debugStreamerControl; // Unknown
  float4 emblemLUTSelector; // Unknown
  float4 colorMatrixR; // Unknown
  float4 colorMatrixG; // Unknown
  float4 colorMatrixB; // Unknown
  float4 gameTime; // x = Cos(Time), y = Sin(Time) (X and Y might be flipped idk), z = Counts to one sec and resets. w = Time since level load in secs
  float4 gameTick; // Unknown Quantities. This one updates faster than a frame so it is hard to see what is going on. x goes btwn 0 and 1.0999, y goes btwn 1.0999 and -1.0999, z seems to be always 0, w goes btwn 0 and PI. Y is equal to X when X is not 0. Not affected by timescale.
  float4 subpixelOffset; // Unknown
  float4 viewportDimensions; // Does not work on 2D shaders (Not tested on 3D)
  float4 viewSpaceScaleBias; // Unknown
  float4 ui3dUVSetup0; // Unknown
  float4 ui3dUVSetup1; // Unknown
  float4 ui3dUVSetup2; // Unknown
  float4 ui3dUVSetup3; // Unknown
  float4 ui3dUVSetup4; // Unknown
  float4 ui3dUVSetup5; // Unknown
  float4 clipSpaceLookupScale; // Unknown
  float4 clipSpaceLookupOffset; // Unknown
  uint4 computeSpriteControl; // Unknown
  float4 invBcTexSizes; // Unknown
  float4 invMaskTexSizes; // Unknown
  float4 relHDRExposure; // Unknown
  uint4 triDensityFlags; // Unknown, These might be also for debug commands, also maybe some rendering modes in APE and Radiant
  float4 triDensityParams; // Unknown
  float4 voldecalRevealTextureInfo; // Unknown
  float4 extraClipPlane0; // Unknown
  float4 extraClipPlane1; // Unknown
  float4 shaderDebug; // Unknown
  uint isDepthHack; // Unknown
};
cbuffer LightingGlobals { // Unknown Context for a lot of this stuff, I think I tried to get it to work for something but wasn't getting expected results.
  uint numLights;
  uint numRefProbes;
  uint numRefProbeBlends;
  uint numDedicatedLights;
  float4 clearColor;
  float4 sssParams;

  struct CoreFogConstants {
    float4 fogColor;
    float4 sunFogColor;
    float K0;
    float skyK0;
    float expMul;
    float expAdd;
    float heightFalloff;
    float skyHeightFalloff;
    float K0b;
    float padding0;
    float skyK0b;
    float3 wldSunFogDir;
    float2 sunFogAngles;
    float atmospheresunstrength;
    float atmosphereMieSchlickK;
    float2 atmosphereskyfogdensityatcamera;
    float atmosphereExtinctionIntensity;
    float atmosphereInScatterIntensity;
    float3 atmosphereRayleighDensity;
    float atmospherehazebasedist;
    float3 atmosphereMieDensity;
    float atmospherehazefadedist;
    float3 atmosphereTotalDensity;
    float worldfogskysize;
    float3 atmosphereInScatterIntensityOverTotalDensity;
    float blendAmount;
    float2 atmosphereskyfogheightdensityscale;
    float2 atmospherefogdistanceoffset;
    float2 atmospherefogdistancedensityscale;
    float2 atmospherefogheightdensityscale;
    float2 atmospherefogdensityatcamera;
    float2 padding1;

  }fogConstants;

  struct CoreSunConstants {
    float3 wldDir;
    float splitDepthOffset;
    float3 color;
    float specScale;
    float globalProbeExposure;
    float3 avgGlobalProbeColor;
    float4 splitPinTransform[3];
    uint sunCookieIndex;
    float sunCookieIntensity;
    float sunVolumetricCookieIntensity;
    uint toolsGfxDisableSunShadow;
    float4 sunCookieTransform[2];
    float intensity;
    int splitArrayOffset;
    float2 pad0;

    struct SSTLightingConstants {
      struct SSTConstants {
        float2 dimensionInTiles;
        float inchesPerTexel;
        float spanInInches;

      }
      constants;

      row_major float4x4 offToPinTransform;
      float coordScale;
      uint rootOffset;
      uint2 pad0;

    }sstLightingConstants;

  }sunConstants;

  struct SSTMinMaxConstants {
    float2 sstToMinMaxScale;
    float2 pad0;
    float2 halfMinTexelSize;
    float rcpInchesDimLevel0;
    float shadowBiasInches;

  }minMaxConstants;

  struct CoreGlobalProbePack {
    uint4 data[3];

  }globalProbeConstants;

  struct CoreWeatherConsts {
    float rain;
    float windSpeed;
    float windDirSin;
    float windDirCos;
    float weatherTile;
    float3 weatherVector;
    float3 weatherVector2;
    float padding0;
    float3 weatherTint;
    float padding1;
    float3 weatherTint2;
    float padding2;

  }weather;

  struct SSTLightingConstants {
    struct SSTConstants {
      float2 dimensionInTiles;
      float inchesPerTexel;
      float spanInInches;

    }constants;

    row_major float4x4 offToPinTransform;
    float coordScale;
    uint rootOffset;
    uint2 pad0;

  }outdoorSSTConstants;

  float4 pinToWorldZ;

  struct CoreVolumetricConstants {
    uint firstSpotLight;
    uint lastSpotLight;
    uint firstOmniLight;
    uint lastOmniLight;
    uint firstProbe;
    uint lastProbe;
    uint padding0;
    uint padding1;

  }volumetric;

  uint viewID;
  uint enableCountDebug;
  uint centerGroupIDx;
  uint centerGroupIDy;
  uint viewmodelSunShadowRaw;
  uint debugDrawOverlayType;
  float drawNumLighstScale;
  float drawNumLightsAlpha;
  uint probeDebug;
  float probeDebugRadius;
  uint showSunVis;
  uint enableAO;
  uint showAO;
  uint numGpuCullTilesWidth;
  uint numGpuCullTilesHeight;
  int permuteHighlight;
  uint overdrawOverlayMaxValue;
  float overdrawOverlayAlpha;
  uint overdrawDecals;
  uint overdrawDecalsLayers;
  uint permuteStride;
  uint numDecals;
  uint numStaticDecals;
  uint numDynamicDecals;
  uint numOverrideProbes;
  uint enableDitheredShadow;
  uint oitMaxEntries;
  uint numAttenuationVolumes;
};
struct GpuShaderConstantSet  // I think these are values defined by game scripts
{
  float4 scriptVector0;
  float4 scriptVector1;
  float4 scriptVector2;
  float4 scriptVector3;
  float4 scriptVector4;
  float4 scriptVector5;
  float4 scriptVector6;
  float4 scriptVector7;
  float4 weaponParam0;
  float4 weaponParam1;
  float4 weaponParam2;
  float4 weaponParam3;
  float4 weaponParam4;
  float4 weaponParam5;
  float4 weaponParam6;
  float4 weaponParam7;
  float4 characterParam0;
  float4 characterParam1;
  float4 characterParam2;
  float4 characterParam3;
  float4 characterParam4;
  float4 characterParam5;
  float4 characterParam6;
  float4 characterParam7;
};

Instance data

struct ModelInstanceData
{
  uint boneArrayIndex;  // Something to do with animation maybe?
  uint shaderConstantSet; // This seems to be treated as a quantity
  uint flagsAndPrevFrameIndex; // Unknown
  uint worldMatrix;
  uint siegeAnimStateOffset; // Unknown
  uint prevFrameSiegeAnimStateOffset; // Unknown
};

struct GpuBoneData
{
  float4 mat[3] // Unknown
  float4 extra; // Unknown
};