【问题标题】:How to rotate parts of a repeated texture at the parts pivot?如何在部件枢轴处旋转重复纹理的部件?
【发布时间】:2017-01-06 21:03:22
【问题描述】:

我目前正在开发一款飞行游戏,它完全在片段着色器中处理基于 perlin 的岛屿渲染,因此我可以尽可能地缩小。我现在也想在着色器中将草等小细节渲染为对象,因为在较大的缩放级别上使用四边形渲染它们对性能的影响太大。

我唯一的问题是,我似乎无法弄清楚如何处理相机旋转,因此我的对象总是像广告牌一样面向相机。我将如何实现这一目标?

截图:

Grass without rotation

Grass with rotation

代码:

pos -= vec2(0.5);
pos = rotate(pos, CameraRotation);
pos += vec2(0.5);

vec2 fraction = vec2(fract(pos.x), fract(pos.y));
vec4 texColor = texture2D(tex, fraction);

我的旋转功能:

vec2 rotate(vec2 position, float degrees)
{
    float rotation = degrees * Pi / 180.0f;

    float rx = position.x * cos(rotation) - position.y * sin(rotation);
    float ry = position.x * sin(rotation) + position.y * cos(rotation);

    return vec2(rx, ry);
}

提前感谢您对此提供的任何帮助!

【问题讨论】:

    标签: opengl glsl shader fragment-shader 2d-games


    【解决方案1】:

    如果您希望矩阵不旋转顶点,则需要采用模型视图矩阵并将左上角 3*3 部分设置为 3*3 单位矩阵,因为这是处理旋转的地方。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-17
      • 1970-01-01
      • 2019-10-16
      • 1970-01-01
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多