2012-12-07 124 views
-1

由於我的項目的一部分,我在OpenGL窗口中顯示的3D動畫模型GLSL版本錯誤

我發現用於此目的的示例代碼上http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html

我成功編譯的代碼,但同時運行時我是得到以下錯誤

Status: VSmain shader compiled with errors 
    Compilation details for VSmain shader: 
    0:3(1): error: syntax error, unexpected VERSION 

    Status: FSmain shader compiled with errors 
    Compilation details for FSmain shader: 
    0:3(1): error: syntax error, unexpected VERSION 

    Status: Link failed 
    Linkage details: 
    linking with uncompiled shaderlinking with uncompiled shader 
    Errors in shader compilation 
    Error initializing the lighting technique 

,也爲

printf("%s \n",glGetString(GL_SHADING_LANGUAGE_VERSION)); 

它返回空

我覺得這個誤差與skinning.glsl文件,該文件是如下

#version 120 
#define VERTEX_IN attribute 


const int MAX_POINT_LIGHTS = 2; 
const int MAX_SPOT_LIGHTS = 2; 
struct VSInput 
{ 
vec3 Position;            
vec2 TexCoord;            
vec3 Normal;  
ivec4 BoneIDs; 
vec4 Weights; 
}; 

interface VSOutput 
{                      
vec2 TexCoord;                 
vec3 Normal;                 
vec3 WorldPos;                 
}; 

struct VSOutput1 
{                      
vec2 TexCoord;                 
vec3 Normal;                 
vec3 WorldPos;                 
}; 

const int MAX_BONES = 100; 

uniform mat4 gWVP; 
uniform mat4 gWorld; 
uniform mat4 gBones[MAX_BONES]; 

shader VSmain(in VSInput VSin:0, out VSOutput VSout) 
{  
mat4 BoneTransform = gBones[VSin.BoneIDs[0]] * VSin.Weights[0]; 
BoneTransform  += gBones[VSin.BoneIDs[1]] * VSin.Weights[1]; 
BoneTransform  += gBones[VSin.BoneIDs[2]] * VSin.Weights[2]; 
BoneTransform  += gBones[VSin.BoneIDs[3]] * VSin.Weights[3]; 

vec4 PosL  = BoneTransform * vec4(VSin.Position, 1.0); 
gl_Position = gWVP * PosL; 
VSout.TexCoord = VSin.TexCoord; 
vec4 NormalL = BoneTransform * vec4(VSin.Normal, 0.0); 
VSout.Normal = (gWorld * NormalL).xyz; 
VSout.WorldPos = (gWorld * PosL).xyz;         
} 



const int MAX_POINT_LIGHTS = 2; 
const int MAX_SPOT_LIGHTS = 2; 

struct BaseLight 
{ 
vec3 Color; 
float AmbientIntensity; 
float DiffuseIntensity; 
}; 

struct DirectionalLight 
{ 
struct BaseLight Base; 
vec3 Direction; 
}; 

struct Attenuation                 
{                     
float Constant;                 
float Linear;                 
float Exp;                  
};                     

struct PointLight                   
{                       
struct BaseLight Base;                 
vec3 Position;                   
Attenuation Atten;                  
};                       

struct SpotLight                    
{                       
struct PointLight Base;                 
vec3 Direction;                   
float Cutoff;                   
};                       

uniform int gNumPointLights;                 
uniform int gNumSpotLights;                 
uniform DirectionalLight gDirectionalLight;             
uniform PointLight gPointLights[MAX_POINT_LIGHTS];           
uniform SpotLight gSpotLights[MAX_SPOT_LIGHTS];            
uniform sampler2D gColorMap;                 
uniform vec3 gEyeWorldPos;                 
uniform float gMatSpecularIntensity;               
uniform float gSpecularPower; 


vec4 CalcLightInternal(struct BaseLight Light, vec3 LightDirection, VSOutput1 In)    
{                       
vec4 AmbientColor = vec4(Light.Color, 1.0f) * Light.AmbientIntensity;     
float DiffuseFactor = dot(In.Normal, -LightDirection);          

vec4 DiffuseColor = vec4(0, 0, 0, 0);             
vec4 SpecularColor = vec4(0, 0, 0, 0);             

if (DiffuseFactor > 0) {                 
    DiffuseColor = vec4(Light.Color, 1.0f) * Light.DiffuseIntensity * DiffuseFactor;  

    vec3 VertexToEye = normalize(gEyeWorldPos - In.WorldPos);        
    vec3 LightReflect = normalize(reflect(LightDirection, In.Normal));      
    float SpecularFactor = dot(VertexToEye, LightReflect);        
    SpecularFactor = pow(SpecularFactor, gSpecularPower);        
    if (SpecularFactor > 0) {               
     SpecularColor = vec4(Light.Color, 1.0f) *          
         gMatSpecularIntensity * SpecularFactor;       
    }                     
}                      

return (AmbientColor + DiffuseColor + SpecularColor);         
}                       

vec4 CalcDirectionalLight(VSOutput1 In)              
{                       
return CalcLightInternal(gDirectionalLight.Base, gDirectionalLight.Direction, In); 
}                       

vec4 CalcPointLight(struct PointLight l, VSOutput1 In)          
{                       
vec3 LightDirection = In.WorldPos - l.Position;           
float Distance = length(LightDirection);             
LightDirection = normalize(LightDirection);            

vec4 Color = CalcLightInternal(l.Base, LightDirection, In);       
float Attenuation = l.Atten.Constant +             
        l.Atten.Linear * Distance +           
        l.Atten.Exp * Distance * Distance;         

return Color/Attenuation;                
}                       

vec4 CalcSpotLight(struct SpotLight l, VSOutput1 In)           
{                       
vec3 LightToPixel = normalize(In.WorldPos - l.Base.Position);        
float SpotFactor = dot(LightToPixel, l.Direction);          

if (SpotFactor > l.Cutoff) {                
    vec4 Color = CalcPointLight(l.Base, In);           
    return Color * (1.0 - (1.0 - SpotFactor) * 1.0/(1.0 - l.Cutoff));     
}                      
else {                     
    return vec4(0,0,0,0);                
}                      
}                       

shader FSmain(in VSOutput FSin, out vec4 FragColor) 
{          
VSOutput1 In; 
In.TexCoord = FSin.TexCoord; 
In.Normal = normalize(FSin.Normal); 
In.WorldPos = FSin.WorldPos;                 

vec4 TotalLight = CalcDirectionalLight(In);           

for (int i = 0 ; i < gNumPointLights ; i++) {           
    TotalLight += CalcPointLight(gPointLights[i], In);        
}                      

for (int i = 0 ; i < gNumSpotLights ; i++) {            
    TotalLight += CalcSpotLight(gSpotLights[i], In);         
}                      

FragColor = texture(gColorMap, In.TexCoord.xy) * TotalLight;  
} 

program Lighting 
{ 
vs(120)=VSmain(); 
fs(120)=FSmain(); 
}; 

你可以在上面給出的鏈接的全部代碼。

+3

「*我覺得這個誤差與skinning.glsl文件*「我有類似的感覺。但是由於我們不具有透視性,因此實際上看不到*「skinning.glsl」,除非您向我們展示它,否則它將不得不保持一種感覺,您的問題將無法解答。 –

+0

也許我已經過了最近的最新發展,但是這個'skinning.glsl'文件(只能通過鏈接發現)對我來說甚至不像是有效的GLSL,而是某種* GLSL的「FXization」*。 –

+0

您使用的是什麼GPU /驅動程序組合? GL Extensions Viewer(http://www.realtech-vr.com/glview/)對你的機器支持GLSL有什麼看法? – Ani

回答

0

它適用於Nvidia顯卡 問題在於OpenGL和glsl的版本。這段代碼在特定似乎支持僅版本#330或更高

運行使用Nvidia的支持代碼: optirun ./{executable}