Dynamic Cubemap的正常和深度

时间:2017-12-17 17:20:29

标签: opengl glsl shader fragment-shader vertex-shader

如何使用动态立方体贴图从二次反射中获取深度和法线?

按照我当前的代码:

顶点着色器

#version 130

uniform mat4 osg_ViewMatrixInverse;
uniform vec3 cameraPos;

void main() {
    gl_Position = ftransform();
    gl_TexCoord[0] = gl_MultiTexCoord0;
    mat4 ModelWorld4x4 = osg_ViewMatrixInverse * gl_ModelViewMatrix;
    mat3 ModelWorld3x3 = mat3( ModelWorld4x4 );
    vec4 WorldPos = ModelWorld4x4 *  gl_Vertex;
    vec3 N = normalize( ModelWorld3x3 * gl_Normal );
    vec3 E = normalize( WorldPos.xyz - cameraPos.xyz );
    gl_TexCoord[1].xyz = reflect( E, N );
}

片段着色器

#version 130

uniform samplerCube cubeMap;
uniform sampler2D colorMap;
const float reflect_factor = 0.5;

void main (void)                                                            
{
    vec3 base_color = texture2D(colorMap, gl_TexCoord[0].xy).rgb;
    vec3 cube_color = textureCube(cubeMap, gl_TexCoord[1].xyz).rgb;
    gl_FragColor = vec4( mix(cube_color, base_color, reflect_factor).rgb, 1.0);
}

0 个答案:

没有答案