我正在尝试将顶点着色器转换为在iOS 7上工作,但我无法弄清楚gl_LightSource [0] .position.xyz应该是什么。
这是OpenGL ES 1.0顶点着色器
我已将所有gl_xxx内容换成了统一的mat4 / vec4等,我可以从我的代码中传入但我不知道该如何处理这行
vec4 eyeLightPos = gl_LightSource [0] .position;
这是要转换的顶点着色器代码
varying vec3 N;
varying vec3 L;
varying vec3 E;
attribute float meanK;
attribute float meanKS;
attribute float gaussian;
attribute float gaussianS;
varying float meanCurvature;
attribute float keyAttrib;
attribute float keyUni;
varying float keyShader;
attribute float cuSS;
varying float cuSSF;
attribute float guSS;
varying float guSSF;
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
vec4 eyePosition = gl_ModelViewMatrix * gl_Vertex;
vec4 eyeLightPos = gl_LightSource[0].position;
N = normalize(gl_NormalMatrix * gl_Normal); L = eyeLightPos.xyz - eyePosition.xyz;
E = -eyePosition.xyz;
if(keyAttrib == 0.0)
meanCurvature = meanK;
if(keyAttrib == 1.0)
meanCurvature = meanKS;
if(keyAttrib == 2.0)
meanCurvature = gaussian;
if(keyAttrib == 3.0)
meanCurvature = gaussianS;
keyShader = keyUni;
cuSSF = cuSS;
guSSF = guSS;
}
这是片段着色器代码
varying vec3 N;
varying vec3 L;
varying vec3 E;
varying float meanCurvature;
varying float keyShader;
varying float cuSSF;
varying float guSSF;
void main() {
vec3 Normal = normalize(N);
vec3 Light = normalize(L);
vec3 Eye = normalize(E);
vec3 Half = normalize(Eye + Light);
vec4 baseColor = vec4(0.5,0.5,0.5,0.0);
vec4 white = vec4(1.0,1.0,1.0,0.0);
vec4 red = vec4(1.0,0.0,0.0,0.0);
vec4 blue = vec4(0.0,0.0,1.0,0.0);
float f = 1.0;
//Locally backscattered light
float alpha = 0.43;
float mu = 1.0;
float delta = 0.35;
float muss = 0.25;
float deltass = 0.01;
float Gd;
if(meanCurvature >= 0)
Gd = 1.0 + (alpha * exp(-1.0 * pow((meanCurvature - mu),2.0) / delta));
else
Gd = 1.0;
//Ambient occlusion
float landa = 0.6;
float gamma = 1.0;
float Aa = 1.0 - pow((landa * meanCurvature), (2.0 * gamma));
float lDotv = dot(Light, Eye); float epsilon = 20.0;
float lv;
if(lDotv >= 0.0)
lv = 0.0;
//Subsurface scatter
else
float nv = exp(-1.0 * pow(dot(Normal, Eye) - muss, 2.0) / deltass);
lv = pow((-1.0 * lDotv),epsilon); float GSS = -1.0 * meanCurvature * lv * nv;
float Kd = max(dot(Normal, Light), 0.0); float Ks = pow(max(dot(Half, Normal), 0.0),
gl_FrontMaterial.shininess);
vec4 diffuse = Kd * gl_FrontLightProduct[0].diffuse;
if(dot(Normal, Light) < 0.0) f = 0.0;
vec4 specular = f * Ks * gl_FrontLightProduct[0].specular;
vec4 ambient = gl_FrontLightProduct[0].ambient;
vec4 Css = vec4(1.0,1.0,1.0,1.0);
if(keyShader == 1.0)
gl_FragColor = (ambient) + (Gd * dot(Normal, Light) * diffuse) - (GSS * Css);
else if(keyShader == 2.0)
gl_FragColor = Aa * ambient;
else if(keyShader == 3.0)
gl_FragColor = (Gd * dot(Normal, Light) * diffuse) - (GSS * Css);
else if(keyShader == 4.0)
gl_FragColor = ambient;
else if(keyShader == 5.0)
gl_FragColor = (Aa * ambient) + (dot(Normal, Light) * diffuse)
- (GSS * Css);
else if(keyShader == 6.0)
gl_FragColor = Gd * dot(Normal, Light) * diffuse; else if(keyShader == 7.0)
gl_FragColor = (Aa * ambient) - (GSS * Css);
else if(keyShader == 8.0)
gl_FragColor = diffuse;
else if(keyShader == 9.0)
gl_FragColor = (Aa * ambient) + (Gd * dot(Normal, Light) * diffuse) - (Css);
else if(keyShader == 10.0)
gl_FragColor = GSS * baseColor;
else if(keyShader == 0.0)
gl_FragColor = (Aa * ambient) + (Gd * dot(Normal, Light) *
diffuse) - (GSS * Css);
else if(keyShader == 11.0) {
if(meanCurvature == 0.0)
gl_FragColor = baseColor;
else if(meanCurvature < 0.0)
gl_FragColor = baseColor + ((-1.0 * meanCurvature) *
else blue);
gl_FragColor = baseColor + (meanCurvature * red);
}
else if(keyShader == 12.0)
gl_FragColor = ambient + diffuse + specular;
else if(keyShader == 13.0) {
if(cuSSF == 0)
gl_FragColor = baseColor;
else if(cuSSF < 0.0)
else gl_FragColor = baseColor + ((-1.0 * cuSSF) * blue);
} gl_FragColor = baseColor + (cuSSF * red);
else if(keyShader == 14.0) {
if(guSSF == 0)
gl_FragColor = baseColor;
else if(guSSF < 0.0)
else gl_FragColor = baseColor + ((-1.0 * guSSF ) * blue);
} gl_FragColor = baseColor + (guSSF * red);
else if(keyShader == 15.0)
gl_FragColor = Gd * diffuse;
else if(keyShader == 16.0)
gl_FragColor = Gd * dot(Normal, Light) * white;
else if(keyShader == 17.0)
gl_FragColor = dot(Normal, Light) * diffuse;
else if(keyShader == 18.0)
gl_FragColor = Gd * baseColor;
else if(keyShader == 19.0)
gl_FragColor = Aa * baseColor;
}
答案 0 :(得分:3)
OpenGL ES 2不使用像OpenGL ES 1.0这样的固定功能管道。您必须将光源数据作为统一或属性传递。
查看this page以获取示例。
您还必须自己实现法线和任何其他功能。
有关您在OpenGL ES 2.0中可以访问的所有内置插件的列表,请查看this reference card。在第4页的顶部,您将找到一个列表和说明。