I have some Vertex Shader, I post follow.
It receives angle, scaling and width and height of destination texture, that might include rotated source texture.
The problem is, that while saling for some angles image go outside of destination texture.
Follow I have result of two rotations.
For 10 grads and for -20 grads.
Vertex Shader
cbuffer VS_ROTATE : register (b0)
{
float fxAngle;
float fyAngle;
float fzAngle;
float fScale;
float fWidthSrc;
float fHeightSrc;
float offset;
};
struct VS_INPUT
{
float4 Pos : POSITION;
float2 Tex : TEXCOORD;
uint TexIdx : TEXINDEX;
};
struct VS_OUTPUT
{
float4 Pos : SV_POSITION;
float2 Tex : TEXCOORD;
uint TexIdx : TEXINDEX;
};
VS_OUTPUT VS(VS_INPUT input)
{
VS_OUTPUT output;
output.Pos = input.Pos;
output.Tex = input.Tex;
output.TexIdx = input.TexIdx;
if (fxAngle == 0.0 && fyAngle == 0.0 && fzAngle == 0.0)
return output;
float fxRadAngle = radians(fxAngle);
float fyRadAngle = radians(fyAngle);
float fzRadAngle = radians(fzAngle);
float2 ptPos = input.Pos.xy;
float2 ptOrigin = ptPos;
ptOrigin.x = (ptOrigin.x - 0.5) * fWidthSrc;
ptOrigin.y = (ptOrigin.y - 0.5) * fHeightSrc;
ptPos.x = ptOrigin.x * cos(fzRadAngle) - ptOrigin.y * sin(fzRadAngle);
ptPos.y = ptOrigin.x * sin(fzRadAngle) + ptOrigin.y * cos(fzRadAngle);
ptPos.x = ptPos.x / fWidthSrc;
ptPos.y = ptPos.y / fHeightSrc;
ptPos.x = ptPos.x * fScale + 0.5;
ptPos.y = ptPos.y * fScale + 0.5;
output.Pos.xy = ptPos.xy;
return output;
};
10 grads
-20 grdas