圣者
精华
|
战斗力 鹅
|
回帖 0
注册时间 2003-11-24
|
我要求不高,谁来说说下面这段程序拿啥来编译就行了 - #version 150
- uniform ivec2 LightNums;
- uniform sampler2D DiffuseTex;
- uniform float DiffuseTexTurnY;
- uniform vec4 OmniLight_Pos[8];
- uniform vec4 OmniLight_Color[8];
- uniform vec4 Material[3];
- #define Material_diffuse Material[0]
- #define Material_specular Material[1]
- #define Material_ambient Material[2].xyz
- #define Material_shininess Material[2].w
- in vec4 VertexEyeDir;
- in vec3 Normal;
- in vec2 TexCoord0;
- in vec4 Color;
- vec2 OmniLight(vec4 LightPosEyeIn)
- {
- vec3 Nor=normalize(Normal);
- vec3 LightDir = normalize( LightPosEyeIn.xyz - VertexEyeDir.xyz );
- float NdotL = dot(Nor,LightDir);
- float specular = 0.0;
- vec3 HightLight =normalize( LightDir - normalize(VertexEyeDir.xyz));
- specular = pow(max(dot(Nor, HightLight), 0.0), Material_shininess);
- NdotL = max(0.0,NdotL);
- return vec2(NdotL,specular);
- }
- vec2 SpotLight(vec4 LightPosEyeIn,vec3 LightTGTPosEyeIn,float spotCosCutoff,float spotExponent)
- {
- vec3 Nor=normalize(Normal);
- vec3 LightDir = normalize( LightPosEyeIn.xyz - VertexEyeDir.xyz );
- float NdotL = dot(Nor,LightDir);
- float specular = 0.0;
- float spotEffect = dot(normalize(LightTGTPosEyeIn),-LightDir);
-
- if(spotEffect > spotCosCutoff)
- {
- spotEffect = pow(spotEffect,spotExponent);
- vec3 HightLight =normalize( LightDir - normalize(VertexEyeDir.xyz));
- specular = pow(max(dot(Nor, HightLight), 0.0), gl_FrontMaterial.shininess);
- NdotL = max(0.0,NdotL);
- NdotL = NdotL*spotEffect;
- specular = specular*spotEffect;
- }
- else
- {
- NdotL = 0.0;
- }
- return vec2(NdotL,specular);
- }
- void main()
- {
- vec4 DiffuseTexColor = texture2D(DiffuseTex, TexCoord0.xy);
- vec2 LightVal=vec2(0.0,0.0);
- vec4 AmbientColor=vec4(0.0,0.0,0.0,0.0);
- vec4 DiffuseColor=vec4(0.0,0.0,0.0,0.0);
- vec4 SpecularColor=vec4(0.0,0.0,0.0,0.0);
- for(int i=0;i<8;i++)
- {
- if(i<LightNums.x)
- {
- LightVal=OmniLight (OmniLight_Pos[i]);
- }
- AmbientColor += gl_FrontLightProduct[i].ambient;
- DiffuseColor += LightVal.x * gl_FrontLightProduct[i].diffuse ;
- SpecularColor += LightVal.y * gl_FrontLightProduct[i].specular ;
- }
- gl_FragColor = DiffuseTexColor * (AmbientColor + gl_FrontLightModelProduct.sceneColor + DiffuseColor)*Color +SpecularColor ;
- gl_FragColor.w=DiffuseTexColor.w;
- //gl_FragColor+=SpecularColor;
-
- //gl_FragColor.xyz=Normal;
- //gl_FragColor = DiffuseTexColor;
- return;
- }
复制代码 |
|