【发布时间】:2017-01-06 21:03:22
【问题描述】:
我目前正在开发一款飞行游戏,它完全在片段着色器中处理基于 perlin 的岛屿渲染,因此我可以尽可能地缩小。我现在也想在着色器中将草等小细节渲染为对象,因为在较大的缩放级别上使用四边形渲染它们对性能的影响太大。
我唯一的问题是,我似乎无法弄清楚如何处理相机旋转,因此我的对象总是像广告牌一样面向相机。我将如何实现这一目标?
截图:
代码:
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