Tuesday, November 29, 2022
HomeGame Developmentdirectx11 - Little downside with offsetting reworked vertex in a vertex shader

directx11 – Little downside with offsetting reworked vertex in a vertex shader


I’m engaged on some home-made menu stuff underneath DX11. I’m creating the rect menus at begin all situated at place 0,0. Every menu comprises some strains of choices. Every little thing is created as reworked vertex (e.g. -1..1 coordinates).
Now I need the menu to look the place I click on the mouse. So I have to offset the mesh vertices and I’m making an attempt to do it inside the vertex shader.

Right here the code

The shader fixed to retailer the offset in Rectshow
cbuffer cbMesh : register(b8)
{
 float4 FactorColor;
 float4 RectShow;
}

The offsetting on the vertex degree
PS_INPUT_FONT VS_FONT(VS_INPUT_FONT enter) 
{
  PS_INPUT_FONT output = (PS_INPUT_FONT)0;
  output.Pos = float4(enter.Pos.xy + RectShow.xy, enter.Pos.z, 1);
  output.Tex = enter.Tex;
  return output;
}

Inside my app the letters positions are calculated this manner with Rect.xy being in coordinate [0..Screensize]:

FLOAT tX = Rect->x * 2 / gViewPort.width -1;
FLOAT tY = 1 - Rect->y * 2/ gViewPort.Top;

For every letter and features I exploit some tX/tY offsetting throughout mesh creation.

Now logically I’m calculating the offset from mouse place Pt in coordinate [0..Screensize]:

gCBFont.RectShow.x = Pt.x * 2 / gViewPort.Width - 1;
gCBFont.RectShow.y = (1 - Pt.y * 2 / gViewPort.Top);
gpDC11->UpdateSubresource(gpCBBufferFont, 0, NULL, &gCBFont, 0, 0);
gpDC11->VSSetConstantBuffers(dwSlotFont, 1, &gpCBBufferFont);

if I set arbitrarily RectShow.xy to 0,0 the menu seems at it ought to on the 0,0 display location. However once I use the calculated offset I see nothing.

Earlier than doing it this manner I used to be creating the menu upon click on straight on the mouse place and it was working advantageous nevertheless it appeared much less straightforward to handle as it is advisable to destroy and recreate the meshes for every click on.
With this second choice I can present/cover the meshes when wanted and the menu is created solely as soon as. However I’ve to maneuver it on the mouse place.

I’m lacking one thing right here in all probability. Perhaps I ought to use map/unmap to replace the menu meshes as an alternative of the shader nevertheless it sounds bizarre.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments