-1
好的,所以我在LWJGL的透明度問題。看起來着色器甚至沒有使用alpha通道。例如,如果我將Alpha通道設置爲0.1,則所有內容仍然顯示爲固定。但是,我創建的程序只需要該對象變得堅實或完全清晰。通常,我會在片段着色器中使用discard命令,但是,我正在渲染多個目標,以便放棄要渲染的兩個目標片段。我也在跟隨ThnMatrix的教程。LWJGL的透明度問題
所以我的問題是,爲什麼在我的着色器中渲染時alpha不能工作?我已經嘗試了所有的GL_BLEND的東西,仍然沒有運氣。謝謝!
P.S.我有另一個渲染GUI和透明度/半透明效果的着色器。我在着色器之間看到的唯一主要區別是頂點着色器。
片段着色器:
#version 330 core
in vec2 pass_textureCoords;
in vec3 surfaceNormal;
in vec3 toLightVector[4];
in vec3 toCameraVector;
in float visibility;
layout (location = 0) out vec4 out_Color;
layout (location = 1)out vec4 out_BrightColour;
uniform sampler2D textureSampler;
uniform vec3 lightColor[4];
uniform vec3 attenuation[4];
uniform float shineDamper;
uniform float reflectivity;
uniform float selected;
//effects
uniform float bloomFactor = 0;
uniform vec3 skyColor;
void main(void){
vec3 unitNormal = normalize(surfaceNormal);
vec3 unitVectorToCamera = normalize(toCameraVector);
vec3 totalDiffuse = vec3(0.0);
vec3 totalSpecular = vec3(0.0);
for(int i = 0; i < 4; i++){
float distance = length(toLightVector[i]);
float attFactor = attenuation[i].x + (attenuation[i].y * distance) + (attenuation[i].z * distance * distance);
vec3 unitLightVector = normalize(toLightVector[i]);
float nDot1 = dot(unitNormal, unitLightVector);
float brightness = max(nDot1, 0.0);
vec3 lightDirection = -unitLightVector;
vec3 reflectedLightDirection = reflect(lightDirection, unitNormal);
float specularFactor = dot(reflectedLightDirection, unitVectorToCamera);
specularFactor = max(specularFactor, 0.0);
float dampedFactor = pow(specularFactor, shineDamper);
totalDiffuse = totalDiffuse + (brightness * lightColor[i])/attFactor;
totalSpecular = totalSpecular + (dampedFactor * lightColor[i] * reflectivity)/attFactor;
}
totalDiffuse = max(totalDiffuse, 0.2);
vec4 textureColor = texture(textureSampler, pass_textureCoords);
out_Color = vec4(totalDiffuse, 1.0) * textureColor + vec4(totalSpecular, 1.0);
out_Color = mix(vec4(skyColor, 1.0), out_Color, visibility);
if(selected > 0.5){
out_Color.r += 0.75;
}
if(out_Color.a<0.5){
discard;
}
//float brightness = (out_Color.r * 0.2126) + (out_Color.g * 0.7152) + (out_Color.b * 0.0722);
out_BrightColour = vec4(0.0);
}
非常感謝!我甚至沒有想過看那個!不過,我仍然遇到同樣的問題。 –