如何在OpenGL ES 2.0中更改光的方向

时间:2018-12-12 22:07:10

标签: android opengl-es-2.0 light

嘿,我正在尝试在opengl es 2.0中旋转光的方向,但是它没有旋转,请为英语感到抱歉

这些是我的片段着色器

re.sub('[^>]+>', '', y)

这些是顶点着色器

   precision mediump float;         // Set the default precision to medium. We don't need as high of a 
// precision in the fragment shader.
uniform vec3 u_LightPos;        // The position of the light in eye space.
uniform vec4 u_Texture;    // The input texture.

varying vec3 v_Position;        // Interpolated position for this fragment.
varying vec3 v_Normal;          // Interpolated normal for this fragment.
varying vec2 v_TexCoordinate;   // Interpolated texture coordinate per fragment.

// The entry point for our fragment shader.
void main()                         
{                              
// Will be used for attenuation.

float distance = length(u_LightPos - v_Position);                  

// Get a lighting direction vector from the light to the vertex.
vec3 lightVector = normalize(u_LightPos - v_Position);                  

// Calculate the dot product of the light vector and vertex normal. If the normal and light vector are
// pointing in the same direction then it will get max illumination.
float diffuse = max(dot(v_Normal, lightVector), 0.0);                                                                                 

// Add attenuation. 
diffuse = diffuse * (1.0 / (1.0 + (0.25 * distance)));

// Add ambient lighting
diffuse = diffuse + 0.7;  

// Multiply the color by the diffusoie illumination level and texture value to get final output color.
gl_FragColor = u_Texture*diffuse;                                       
}               

光仅在Xy轴上起作用,并且只能向上向下

我想把这1,1,1反射到0,0,0

0 个答案:

没有答案