Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6624519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:39:47+00:00 2026-05-25T21:39:47+00:00

I’m trying to clip a texture by hardcoding the texture coordinates through 0 and

  • 0

I’m trying to clip a texture by hardcoding the texture coordinates through 0 and 1, and then sending a constantbuffer containing a 3×3 texture transform matrix to the vertexshader.

However, the texture is not rendering as I expected it to. I’m not sure where I went wrong. Could someone help? See code below.

For testing, I’m trying to use an Identity matrix to keep the texture coordinates untouched, but the texture shows up transformed in a very weird way.

This is the texture: (the colours showing up are actually transparent areas, except the black colour and the softer red colour of the heart)

normal

Transformed texture:

transformed


HLSL:

cbuffer cbChangesPerFrame : register( b0 )
{
    matrix g_Mvp;
};

cbuffer cbTexTransform : register( b2 )
{
    float3x3 g_TexTransform;
};

Texture2D g_ColorMap : register(t0);
SamplerState g_ColorSampler : register(s0);

struct VS_Input
{
    float4 pos : POSITION0;
    float2 tex0 : TEXCOORD0;
};

struct PS_Input
{
    float4 pos : SV_POSITION0;
    float2 tex0 : TEXCOORD0;
};

PS_Input VS_Main(VS_Input vertex)
{
    PS_Input vsOut = (PS_Input)0;
    vsOut.pos = mul(vertex.pos,g_Mvp);

    //vsOut.tex0 = vertex.tex0;
    float3 coord = float3(vertex.tex0, 1.0);
    coord = mul(coord, g_TexTransform);
    vsOut.tex0 = coord.xy ;

    return vsOut;
}

float4 PS_Main( PS_Input frag ) : SV_TARGET
{
    return g_ColorMap.Sample( g_ColorSampler, frag.tex0 );
}

VBuffer hardcoded:

Vertex::PosTex vertices[]=
{
    {XMFLOAT3( 0.5f, 0.5f, 1.0f ),  XMFLOAT2( 1.0f, 0.0f )},
    {XMFLOAT3( 0.5f, -0.5f, 1.0f ), XMFLOAT2( 1.0f, 1.0f )},
    {XMFLOAT3( -0.5f, -0.5f, 1.0f ), XMFLOAT2( 0.0f, 1.0f )},

    {XMFLOAT3( -0.5f, -0.5f, 1.0f ), XMFLOAT2( 0.0f, 1.0f )},
    {XMFLOAT3( -0.5f, 0.5f, 1.0f ), XMFLOAT2( 0.0f, 0.0f )},
    {XMFLOAT3( 0.5f, 0.5f, 1.0f ),  XMFLOAT2( 1.0f, 0.0f )}
};

Matrix definition:

XMFLOAT3X3 f3x3;
f3x3.m[0][0] = 1.0f;    f3x3.m[0][1] = 0.0f;    f3x3.m[0][2] = 0.0f;
f3x3.m[1][0] = 0.0f;    f3x3.m[1][1] = 1.0f;    f3x3.m[1][2] = 0.0f;
f3x3.m[2][0] = 0.0f;    f3x3.m[2][1] = 0.0f;    f3x3.m[2][2] = 1.0f;
GAME_MANAGER->GMSetTexTransformMatrix(f3x3);

Game_Manager GMSetTransformMatrix() definition:

void GameManager::GMSetTexTransformMatrix( const XMFLOAT3X3& rkTexTransform )
{
    m_pContext->UpdateSubresource(m_pTexTransformCB,0,0,&rkTexTransform,0,0);
    m_pContext->VSSetConstantBuffers(2,1,&m_pTexTransformCB);
}

Buffer Initialisation:

ZeroMemory(&constDesc, sizeof(constDesc));
constDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
constDesc.ByteWidth = 48;
constDesc.Usage = D3D11_USAGE_DEFAULT;

result = m_pDevice->CreateBuffer(&constDesc,0,&m_pTexTransformCB);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:39:48+00:00Added an answer on May 25, 2026 at 9:39 pm

    The problem is the 16 byte alignment. An XMFLOAT3X3 is just 9 floats in a row. When this gets stored in registers, its just going to take the first four floats and put them in c0, the next four in c1, and the remaining float in c2.x. You can see this yourself with the following:

    cbuffer cbChangesEveryFrame : register( b1 )
    {
    
        float a1 : packoffset(c0.x);
        float a2 : packoffset(c0.y);
        float a3 : packoffset(c0.z);
    
        float b1 : packoffset(c0.w);
        float b2 : packoffset(c1.x);
        float b3 : packoffset(c1.y);
    
        float c1 : packoffset(c1.z);
        float c2 : packoffset(c1.w);
        float c3 : packoffset(c2.x);
    
    };
    
    PS_INPUT VS( VS_INPUT input )
    {
        PS_INPUT output = (PS_INPUT)0;
        output.Pos = mul( input.Pos, World );
        output.Pos = mul( output.Pos, View );
        output.Pos = mul( output.Pos, Projection );
    
        float3 coord = float3(input.Tex, 1.0);
    
        float3x3 g_TexTransform = {a1, a2, a3, b1, b2, b3, c1, c2, c3};
    
        coord = mul(coord, g_TexTransform);
    
        output.Tex = coord.xy;
    
        return output;
    }
    

    Now when you pass your XMFLOAT3X3, the texture appears normally. The problem was that because of the register allocation, your texture transform matrix became screwed up. When you look at the registers, this is how your data looks coming in:

    c0: 1 0 0 0
    c1: 1 0 0 0
    c2: 1
    

    float3x3’s are probably an array of float3’s, so it would take the first three components of each register, giving you:

    1, 0, 0
    1, 0, 0
    1, 0, 0
    

    Its scaling your Y to 0, which is giving that wierd stretchy look. To solve this, you’re going to either have to store your transform in a 4×4 matrix, or manually assign each part of the register. Switching to three float3’s wouldn’t work either, because they can’t cross the 16-byte boundary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.