跳到主要内容
← Vertex Transformations

Vertex Transformations

Rotation

shader-learning 自学第 15 课:Rotation

实时渲染 · 网格 HLSL

第 15 课:Rotation

实现

cbuffer Uniforms : register(b0) {
  float iTime;
  float4x4 viewMatrix;
  float4x4 projectionMatrix;
};

struct VSInput {
  float3 position : Position;
};

struct VSOutput {
  float4 position : SV_Position;
};

VSOutput main(VSInput input) {
  VSOutput output;

  // setPosition2D
  float2 pos2D = input.position.xy;
  float delta = (sin(iTime)+1.0)/2.0 * 2.0*3.14;
  float rotatedX = pos2D.x * cos(delta) - pos2D.y * sin(delta);
  float rotatedY = pos2D.y * cos(delta) + pos2D.x * sin(delta);
  float2 rotated = float2(rotatedX, rotatedY);

  float4 viewPos  = mul(viewMatrix, float4(rotated, 0.0, 1.0));
  output.position = mul(projectionMatrix, viewPos);

  return output;
}