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

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值