I'm new to using shaders to do some fancy effects and I'm struggling with them. I'm using DirectX 11 and HLSL. I have this square in the middle of the screen:
It's just a square that I've created using 4 vertices. I want to give it this waving effect on the sides, but I don't know how to do it.
This is for a little 2D game I'm making, so I have an orthogonal projection matrix which is the one I use. View matrix is set to identity.
DirectX::XMMATRIX view = DirectX::XMMatrixIdentity();
DirectX::XMMATRIX projection = DirectX::XMMatrixOrthographicOffCenterLH(0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, 0.0f, 1.0f);
This is the constant buffer I set each frame, so I can pass a float time variable to the shader:
struct constant_buffer {
DirectX::XMMATRIX WVP;
// this value starts in 0 and increases by 1 each frame until 359 degrees
float time;
};
constant_buffer cbuffer;
The shader that I'm currently using is very simple, it just applies the matrix to each vertex to transform it.
struct in_pshader
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
cbuffer constant_buffer
{
float4x4 WVP;
float time;
};
in_pshader vshader(float4 position : POSITION, float4 color : COLOR)
{
in_pshader output;
output.position = mul(position, WVP);
output.color = color;
return output;
}
float4 pshader(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET
{
return color;
}
I'm guessing there's some sine function involved around, so that's why I decided to pass angles per frame as input. I tried many combinations, but I'm such a newbie and can't get it right. :( Any help on this would be very appreciated.