飛行機にガラス球がある屈折シェーダを作成しようとしています。私の問題は、テクスチャがプレーンに表示されないということです。テクスチャがプレーンに表示されない
飛行機コード:
varying vec3 varPosition;
varying vec2 varTexCoords;
uniform vec3 sphere_center;
uniform float sphere_radius;
uniform float sphere_refractive_index;
uniform vec3 eyePosition;
uniform sampler2D texture;
out vec3 fragColor;
void main()
{
vec3 ray_direction = normalize(varPosition - eyePosition);
float a = dot(ray_direction, ray_direction);
float b = 2.0 * dot(ray_direction, eyePosition - sphere_center);
float c = dot(sphere_center, sphere_center) + dot(eyePosition, eyePosition) - 2.0 * dot(sphere_center, eyePosition) - sphere_radius*sphere_radius;
float test = b*b - 4.0*a*c;
if (test >= 0.0) {
//there is an intersection with the sphere
//here I refract the ray
} else {
//no intersection with the sphere
//we test for shadow
if (test >= 0.0) {
//the point is in shadow
vec3 black = vec3(0.0);
fragColor = mix(texture2D(texture, varTexCoords).rgb,black,shadowIntensity).rgb;
} else {
//the point is not in shadow
fragColor = texture2D(texture, varTexCoords).rgb;
}
}
}
状況は球が塗装されることをですが、飛行機はグレーのまま:
GLfloat plane[4][5] = // s, t, x, y, z
{
0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 100.0f,
1.0f, 1.0f, 80.0f, 0.0f, 100.0f,
1.0f, 0.0f, 80.0f, 0.0f, 0.0f,
};
void DrawPlane()
{
glBegin(GL_QUADS);
glVertex3fv(plane[0]+2);
glVertex3fv(plane[1]+2);
glVertex3fv(plane[2]+2);
glVertex3fv(plane[3]+2);
glEnd();
}
そして、私のフラグメントシェーダは、次のようになります。問題は多分私のtexCoordsで、もし私がtexture.x関数のvarTexCoordsパラメータを(position.xzのようなものに)変更すると、それは飛行機をペイントすることになります。しかし、私はそこに必要なことがすべてあると私には思われます。
属性配列:
glVertexAttribPointer(ATTRIB_VERTEX, 3, GL_FLOAT, 0, 5 * sizeof(GLfloat), (GLvoid*)(plane[0]+2));
glVertexAttribPointer(ATTRIB_TEX_COORDS, 2, GL_FLOAT, 0, 5 * sizeof(GLfloat), (GLvoid*)(plane[0]));
私は属性の位置に結合して、私は、頂点属性配列を有効にします。
glBindAttribLocation(program->id(), ATTRIB_VERTEX, "position");
glBindAttribLocation(program->id(), ATTRIB_TEX_COORDS, "texCoords");
glEnableVertexAttribArray(ATTRIB_VERTEX);
glEnableVertexAttribArray(ATTRIB_TEX_COORDS);
私はすべてを試してみました。たぶんエラーは何か些細なもので、私はまっすぐ考えることができませんこの私の心を失うことに近いです。
何かヒントありがとうございます。
glEnable(TEXTURE_2D); OpenGLは州に基づいています。 – Krythic
私はinitGL()関数に持っています。 – Wanderer
@Krythic: 'glEnable(TEXTURE_2D);'はシェーダとはまったく無関係です。固定関数パイプラインにのみ影響します。 – derhass