layout (location = 0) in vec3 Position;
layout (location = 1) in vec2 Speed;
out vec3 feedbackPosition;
uniform float pointSize;
void main()
{
gl_Position = vec4(Position, 1.0);
float x = Position.x + Speed.x;
float y = Position.y + Speed.y;
if (1.0 < x) { x = -1.0; }
if (x < -1.0) { x = 1.0; }
if (1.0 < y) { y = -1.0; }
if (y < -1.0) { y = 1.0; }
feedbackPosition = vec3(x, y, 0.0);
gl_PointSize = pointSize;
}
~略~
let c_string = CString::new("feedbackPosition").unwrap();
let c_string_ptr = &c_string.as_ptr();
gl::TransformFeedbackVaryings(program_id, 1, c_string_ptr, gl::SEPARATE_ATTRIBS);
gl::LinkProgram(program_id);
~略~
out vec3 feedbackPositionに、シェーダによる計算結果が格納されます。
位置情報をもう1つ作って、入力と出力用に分けました。
let mut vertices: Vec<f32> = Vec::with_capacity(POINTS * 3);
let mut vertices2: Vec<f32> = Vec::with_capacity(POINTS * 3);
let mut vertices_speed: Vec<f32> = Vec::with_capacity(POINTS * 2);
let mut rng = rand::thread_rng();
for _i in 0..POINTS {
vertices.push(rng.gen_range(-1.0..1.0)); // x
vertices.push(rng.gen_range(-1.0..1.0)); // y
vertices.push(0.0); // z
vertices2.push(0.0); // x
vertices2.push(0.0); // y
vertices2.push(0.0); // z
vertices_speed.push(rng.gen_range(-0.01..0.01)); // speed x
vertices_speed.push(rng.gen_range(-0.01..0.01)); // speed y
}