Opengl超级宝典 第七章CubeMapped着色器部分编译错误

来源:互联网 发布:网络语不二臣 什么意思 编辑:程序博客网 时间:2024/06/05 15:44

SkyBox 的着色器


// Skybox Shader

// Vertex Shader

// Richard S. Wright Jr.

// OpenGL SuperBible

#version 120


// Incoming per vertex... just the position

attribute vec4 vVertex;


uniform mat4   mvpMatrix;  // Transformation matrix


// Texture Coordinate to fragment program

varying vec3 vVaryingTexCoord;



void main(void) 

    {

    // Pass on the texture coordinates 

    vVaryingTexCoord = normalize(vVertex.xyz);


    // Don't forget to transform the geometry!

    gl_Position = mvpMatrix * vVertex;

    }


// Skybox Shader

// Fragment Shader

// Richard S. Wright Jr.

// OpenGL SuperBible

#version 120


uniform samplerCube cubeMap;


varying vec3 vVaryingTexCoord;


void main(void)

    {

    gl_FragColor = textureCube(cubeMap, vVaryingTexCoord);

    }

    

Reflection的着色器

// Reflection Shader

// Vertex Shader

// Richard S. Wright Jr.

// OpenGL SuperBible

#version 120


// Incoming per vertex... position and normal

attribute vec4 vVertex;

attribute vec3 vNormal;


uniform mat4   mvpMatrix;

uniform mat4   mvMatrix;

uniform mat3   normalMatrix;

uniform mat4   mInverseCamera;


// Texture coordinate to fragment program

varying vec3 vVaryingTexCoord;


void main(void) 

    {

    // Normal in Eye Space

    vec3 vEyeNormal = normalMatrix * vNormal;

    

    // Vertex position in Eye Space

    vec4 vVert4 = mvMatrix * vVertex;

    vec3 vEyeVertex = normalize(vVert4.xyz / vVert4.w);

    

    // Get reflected vector

    vec4 vCoords = vec4(reflect(vEyeVertex, vEyeNormal), 1.0);

   

    // Rotate by flipped camera

    vCoords = mInverseCamera * vCoords;

    vVaryingTexCoord.xyz = normalize(vCoords.xyz);


    // Don't forget to transform the geometry!

    gl_Position = mvpMatrix * vVertex;

    }



// Reflection Shader

// Fragment Shader

// Richard S. Wright Jr.

// OpenGL SuperBible

#version 120


uniform samplerCube cubeMap;

varying vec3 vVaryingTexCoord;


void main(void)

    { 

    gl_FragColor = textureCube(cubeMap, vVaryingTexCoord.stp);

    }

    




0 0