Jump to content
  • Advertisement
ritzmax72

DX12 Texture transformation matrix has last two row set to “not used”

Recommended Posts

Hi All, my constant buffer structure for per pass looks like this

struct PerPass{

XMFLOAT4X4 projectionMat;

XMFLOAT4X4 viewMat;

XMFLOAT4X4 textureMat;

Lights maxLights[MAX_LIGHTS]

float3 cameraPosition;

};

 

I am aware of packing rules so first three variables should be fine since they are all multiple of 4D vectors. My “Light” structure is also a multiple of 4D vector. cameraPosition is last variable so its will be fine too. 

 

I have tried moving textureMat up and down but it always give me last two rows as “not used” when I do graphics debug in Visual Studio. 

I am initialising it with an identity matrix but it doesn’t come up completely. Setting textureTransform(0,0) = 7; and textureTransform(1,1) = 9 scale the texture along x and y direction. These two changes reflects in first two rows correctly. I wanted to move the coordinates so I am supposed to utilise last row for translation. textureTransform(3,0) and textureTransform(3,1). This row is mentioned “not used”. Maybe I will move textureTransform to different constant buffer but what is going on here? What is my mistake?

 

Share this post


Link to post
Share on other sites
Advertisement

A look at the shader would be clarifying. The shader compiler optimizes unused values away, no matter the optimization settings. Chances are, you made a mistake with the texture transformation calculation. Does the compiler issue a warning ?

Share this post


Link to post
Share on other sites

Hi unbird, Here is my full hlsl content.

 

#include "LightingFunctions.hlsl.txt"
struct VertexIn
{
  float3 Position : POSITION;
  float3 Normal   : NORMAL;
  float4 Color    : COLOR;
  float2 TexCord  : TEXCORD;
  float2 FunData  : FUNDATA;
};

struct VertexOut
{
  float4 OutVertex: SV_POSITION;
  float4 Color : COLOR;
  float3 Position : POSITION;
  float3 Normal : NORMAL;
  float2 TexCord : TEXCORD;
};
cbuffer CbObject : register(b0)
{
  float4x4 gWorld;
};

//Texturing
Texture2D gDiffuseMap:register(t0);

SamplerState gsamLinear  : register(s0);


cbuffer CbPass : register(b1)
{
  float4x4 gView;
  float4x4 gProj;
  float4x4 gTexTransform;
  Light gLights[MaxLights];
  float3 gCameraPosition;

};
cbuffer CbMat : register(b2)
{
  float4 diffuseAlbedo;
  float3 fresnelRo;
  float roughness;
};
VertexOut VS(VertexIn In)
{
  VertexOut out1;
  float4 intermediate = mul(float4(In.Position,1.0f), gWorld);
  out1.OutVertex = mul(intermediate,mul(gView,gProj));
  out1.Position = intermediate.rgb;
  //float4 intermediate = mul(gWorld,float4(In.Position,1.0f));
  //out1.OutVertex = mul(mul(gView,gProj),intermediate);
  out1.Normal = In.Normal;
  out1.Color = In.Color;
  out1.TexCord = In.TexCord;
  return out1;
}
float4 PS(VertexOut in1):SV_Target
{
  in1.Normal = normalize(in1.Normal);
  float4 texT = mul(float4(in1.TexCord,0.0f,0.0f),gTexTransform);
  float3 toEye = normalize(gCameraPosition - in1.Position);
  float4 texDiffuseAlbedo = gDiffuseMap.Sample(gsamLinear,texT.rg);
  float4 tDiffuse = diffuseAlbedo*texDiffuseAlbedo;

  float4 ambient = float4(1.0f,1.0f,1.0f,1.0f)*tDiffuse;
  const float shininess = 1.0f - roughness;
  Material mat = { tDiffuse, fresnelRo, shininess };
  float3 shadowFactor = 1.0f;
  float4 directLight = ComputeLighting(gLights, mat, in1.Position,
      in1.Normal, toEye, shadowFactor);
   float4 litColor = ambient +  directLight;
   // Common convention to take alpha from diffuse material.
  //float4 litColor = tDiffuse;
  litColor.a = diffuseAlbedo.a;
  return litColor;
  //return in1.Color;
}

The bold line in Pixel shader doesn't work as expeced. See the attachment. 

Notused.PNG

Share this post


Link to post
Share on other sites

The last two elements of your float4 are both zero. The compiler knows that 0 * anything is 0 and therefore it doesn't need to fetch the last two rows of the matrix or do the work involved in multiplying 0 by gTexTransform[2] and [3].

Share this post


Link to post
Share on other sites
1 hour ago, ajmiles said:

The last two elements of your float4 are both zero. The compiler knows that 0 * anything is 0 and therefore it doesn't need to fetch the last two rows of the matrix or do the work involved in multiplying 0 by gTexTransform[2] and [3].

Thanks ajmiles! That was he issue. 

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

  • 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!