所以我一直在做一个涉及自定义着色器的项目,在这里的人们的帮助下,我已经能够在Rabbid76的帮助下用lambert和phong glsl代码实现一个着色器。

现在,我想在glsl代码和libgdx中利用光的位置。
Rabbid76把这个代码借给了我一个带有结构灯点的phong shade。我试了一下,结果只看到一个黑屏。有一个统一的PointLight num_pointLights,我假设它指向这个结构。我不确定如何在libgdx代码中将其作为统一的,或者作为libgdx中的变量。
顶点:
attribute vec3 a_position;
attribute vec3 a_normal;
attribute vec2 a_texCoord0;
uniform mat4 u_worldTrans;
uniform mat4 u_projViewTrans;
varying vec2 v_texCoords;
varying vec3 v_vertPosWorld;
varying vec3 v_vertNVWorld;
void main()
{
vec4 vertPos = u_worldTrans * vec4(a_position, 1.0);
v_vertPosWorld = vertPos.xyz;
v_vertNVWorld = normalize(mat3(u_worldTrans) * a_normal);
v_texCoords = a_texCoord0;
gl_Position = u_projViewTrans * vertPos;
}片段:
varying vec2 v_texCoords;
varying vec3 v_vertPosWorld;
varying vec3 v_vertNVWorld;
uniform sampler2D u_texture;
struct PointLight
{
vec3 color;
vec3 position;
float intensity;
};
uniform PointLight u_pointLights[1];
void main()
{
vec3 toLightVector = normalize(u_pointLights[0].position - v_vertPosWorld.xyz);
float lightIntensity = max( 1.0, dot(v_vertNVWorld, toLightVector));
vec4 texCol = texture( u_texture, v_texCoords.st );
vec3 finalCol = texCol.rgb * lightIntensity * u_pointLights[0].color;
gl_FragColor = vec4( finalCol.rgb * lightIntensity, 10.0 );
}有人建议我可以像这样初始化PointLight类: environment.add(pointLight =新的PointLight().set( .....);,但我不确定这是如何工作的,因为我必须使用环境类变量而不是我的着色器。
我感觉就快拿到这个了。但我甚至不确定是否可以使用这种方法。如果有人能够分享一些关于如何以有意义的方式使用light位置或struct的经验和知识,我将非常感激。:)
这是我当前项目的链接:here
发布于 2017-10-04 19:56:21
https://stackoverflow.com/questions/46535871
复制相似问题