我的著色器類中有一個方法,用于獲取我的統一變數位置,但它似乎在特定變數上無緣無故地失敗......
這是我的 getUnfiform 位置方法(在除錯模式下):
public int getUniformLocation(String uniform){
int a = GLES30.glGetUniformLocation(programID,uniform);
if(a == -1){
Log.e("gul","an error occured : " uniform );
//Log.e("gul", "here's the program : " GLES30.glGetShaderSource(fragmentShader));
}
if(a > -1){
Log.e("gul","it's fine " uniform);
}
return a;
}
這是我的片段著色器代碼中的統一變數部分:
#version 300 es
precision mediump float;
#define ALPHA_CLIP //in my specific case I erase, at runtime, this one;
#define MAP_ROUGHNESS
#define MAP_METALINESS //this one;
#define MAP_SPECULAR //this one;
#define TEXTURE
#define MAP_EMISSION //and this one.
#define NORMAL_MAP
#ifdef MAP_ROUGHNESS
uniform mediump sampler2D roughnessSampler;
#else
uniform mediump float roughness;
#endif
#ifdef MAP_METALINESS
uniform mediump sampler2D MetalinessSampler;
#else
uniform mediump float Metaliness;
#endif
#ifdef MAP_SPECULAR
uniform mediump sampler2D specularSampler;
#else
uniform mediump float specular;
#endif
#ifdef TEXTURE
uniform mediump sampler2D textureSampler;
#endif
#ifdef MAP_EMISSION
uniform mediump sampler2D emissionSampler;
#else
uniform mediump vec3 emission;
#endif
#ifdef NORMAL_MAP
uniform mediump sampler2D normalMap;
#endif
以下是輸入:
- 粗糙度采樣器
- 金屬感
- 鏡面反射
- 排放
- IOR
這是日志輸出:
E/cleanEntity: about to build shader
E/gul: an error occured : roughnessSampler
E/gul: an error occured : Metaliness
E/gul: it's fine specular
E/gul: an error occured : emission
E/gul: it's fine IOR
E/cleanEntity: built shader
如您所見,其中三個失敗了,但它們的情況似乎與另外兩個不同。為什么會這樣,我該如何解決?
uj5u.com熱心網友回復:
A uniform variable does not become an active program resource until it is used in the shader program. The shader program is optimized and unnecessary code and resources are skipped. If you try to get the location of an unnecessary uniform that is not an active program resource, glGetUniformLocation returns -1.
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/427907.html
