使用 GLSL 的立方体贴图实现 [英] cube map implementation using GLSL

查看:72
本文介绍了使用 GLSL 的立方体贴图实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用一些着色器代码,但其中一些让我感到困惑.它使用传入的 gl_vertex 计算出眼向量,然后反射向量.最后传递给片段着色器.通过frag着色器,通过textureCube提取一个texl.我的问题是每个 gl_Vertex 是否只有一个像素?那些着色器的插值在哪里?

i currently work with some shader codes, but some of them makes me confused. it used incoming gl_vertex to calculate out eyevector,then refelect vector.finally pass to frag shader. in pass of frag shader, extracting a texl through textureCube. my question is is there getting only an pixel per gl_Vertex? where is the interpolation happened to those shaders?

 vertex shader:
    uniform vec4 eyepos;  
    varying vec3 reflectvec;
    void main(void)  { 

    vec4 pos = normalize(gl_ModelViewMatrix * gl_Vertex);     
    pos = pos / pos.w;          
    vec3 eyevec = normalize(eyepos.xyz - pos.xyz);     
    vec3 norm = normalize(gl_NormalMatrix * gl_Normal);          
    reflectvec = reflect(-eyevec, norm);          
    gl_Position = ftransform(); 

    }

    frag shader:
    uniform samplerCube cubemap;  
    varying vec3 reflectvec; 

    void main(void)  {     
    vec4 texcolor = textureCube(cubemap, reflectvec);      
    gl_FragColor = texcolor;  
    }

推荐答案

那些着色器的插值在哪里?

where is the interpolation happened to those shaders?

为每个片段执行片段着色器.一个像素至少由 1 个片段组成.在顶点和片段着色器之间,向片段着色器变化的输入是重心插值的.

The fragment shader is executed for every fragment. A pixel consists of at least 1 fragment. Between the vertex and the fragment shader, the input varyings toward the fragment shader are barycentrically interpolated.

这篇关于使用 GLSL 的立方体贴图实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆