ゲームを複製したい。ゲームの目標は、同じ色の2つの正方形の間にパスを作成することです。ここでopengl glsl glslを使用してモデルが見えなくなるバグ異なるパラメータでテクスチャ関数を使用する
はゲームである:
www.mypuzzle.org/3d-logic-2キューブは6つの顔を持っています。各顔は3x3の正方形を持つ。
空白の四角形(環境を反映)、壁の四角形(色付けできません)、開始/終了の四角形(中央は黒い四角形ですが、残りは色付きです) 。
私はプロジェクトを終えていますが、私はバグに悩まされています。私はC++、sfml、opengl、glmを使用しました。
問題はシェーダにあります。
頂点シェーダ:
#version 330 core
layout (location = 0) in vec3 vPosition;
layout (location = 1) in vec3 vColor;
layout (location = 2) in vec2 vTexCoord;
layout (location = 3) in float vType;
layout (location = 4) in vec3 vNormal;
out vec3 Position;
out vec3 Color;
out vec2 TexCoord;
out float Type;
out vec3 Normal;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(vPosition, 1.0f);
Position = vec3(model * vec4(vPosition, 1.0f));
Color=vColor;
TexCoord=vTexCoord;
Type=vType;
Normal = mat3(transpose(inverse(model))) * vNormal;
}
フラグメントシェーダ:私は特定の型を持つ正方形のピクセルを描画するフラグメントシェーダで
#version 330 core
in vec3 Color;
in vec3 Normal;
in vec3 Position;
in vec2 TexCoord;
in float Type;
out vec4 color;
uniform samplerCube skyboxTexture;
uniform sampler2D faceTexture;
uniform sampler2D centerTexture;
void main()
{
color=vec4(0.0,0.0,0.0,1.0);
if(Type==0.0)
{
vec3 I = normalize(Position);
vec3 R = reflect(I, normalize(Normal));
if(texture(faceTexture, TexCoord)==vec4(1.0,1.0,1.0,1.0))
color=mix(texture(skyboxTexture, R),vec4(1.0,1.0,1.0,1.0),0.3);*/
}
else if(Type==1.0)
{
if(texture(centerTexture, TexCoord)==vec4(1.0,1.0,1.0,1.0))
color=vec4(Color,1.0);
}
else if(Type==-1.0)
{
color=vec4(0.0,0.0,0.0,1.0);
}
else if(Type==2.0)
{
if(texture(faceTexture, TexCoord)==vec4(1.0,1.0,1.0,1.0))
color=mix(vec4(Color,1.0),vec4(1.0,1.0,1.0,1.0),0.5);
}
}
/*
Type== 0 ---> blank square(reflects light)
Type== 1 ---> start/finish square
Type==-1 ---> wall square
Type== 2 ---> colored square that was once a black square
*/
、シェーダのみの1に入射するよう各四角形の場合は4です。私が同じテクスチャでglsl関数texture
を使用するだけで、プログラムは正常に動作します。異なるテクスチャでこの関数を2回使用した場合、2つの異なる場合、私のモデルは見えなくなります。なぜそれが起こっているのですか?
https://postimg.org/image/lximpl0bz/
https://postimg.org/image/5dzvqz2r7/
赤い四角は私のモデルが見えなく行き、その後ならば、私はタイプ== 0のコードを変更したタイプ1です。