首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GLSL中球图计算的制导

GLSL中球图计算的制导
EN

Computer Graphics用户
提问于 2016-03-14 18:38:52
回答 1查看 1.3K关注 0票数 4

我试图在OpenGL/GLSL中实现与Blender添加纹理时相同的效果,将其设置为“反射”

如果我做得对的话,这最终是一种伪造细节的方法,或者是“金属性”。

我遵循了本教程(中间页,"Sphere“部分):http://www.ozone3d.net/tutorials/glsl_变形_p04.php

下面是问题(一些严重的工件):https://www.youtube.com/watch?v=hx66_xWhVu4&feature=youtu.be

一切都发生在顶点Sahder的底部

代码语言:javascript
复制
#version 330 core

layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV;
layout(location = 2) in vec3 vertexNormal_modelspace;
layout(location = 3) in vec3 vertexTangent_modelspace;

out vec2 uv;
out vec3 toLightVector[4];
out vec3 toCameraVector;
out float fog_Visibility;

uniform mat4 FTM;
uniform mat4 P;
uniform mat4 V;
uniform vec3 LP[4];

const float fog_Density = 0.2;
const float fog_Gradient = 0.9;

void main(){

    vec4 worldPosition = FTM * vec4(vertexPosition_modelspace, 1.0);
    uv = vertexUV;

    vec3 surfaceNormal = (FTM * vec4(vertexNormal_modelspace, 0.0)).xyz;

    vec3 norm = normalize(surfaceNormal);
    vec3 tang = normalize((FTM * vec4(vertexTangent_modelspace, 0.0)).xyz);
    vec3 bitang = normalize(cross(norm, tang));

    mat3 toTangentSpace = mat3(tang.x, bitang.x, norm.x, tang.y, bitang.y, norm.y, tang.z, bitang.z, norm.z);

    for (int i = 0; i < 4; i++) {
        toLightVector[i] = toTangentSpace * (LP[i] - worldPosition.xyz);
    }

    toCameraVector = toTangentSpace * ((inverse(V) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz);

    vec4 positionRelativeToCam = V * worldPosition;
    gl_Position = P * positionRelativeToCam;

    // Fog
    float fog_Distance = length(positionRelativeToCam.xyz);
    fog_Visibility = exp(-pow((fog_Distance * fog_Density), fog_Gradient));
    fog_Visibility = clamp(fog_Visibility, 0.0, 1.0);

    // Reflection Map
    vec3 u = normalize(toCameraVector);
    vec3 r = reflect(u, norm);
    float m = 2.0 * sqrt(r.x*r.x + r.y*r.y + (r.z + 1.0)*(r.z + 1.0));

    gl_TexCoord[0].s = r.x / m + 0.5;
    gl_TexCoord[0].t = r.y / m + 0.5;
}

在碎片阴影中,我所做的就是:

代码语言:javascript
复制
out_color = texture(reflectionSampler, gl_TexCoord[0].st);

倒影地图看起来和在搅拌机中看到的情况类似,但不完全是这样。

我需要在不计算灯光的情况下做到这一点。这是Blender做的,它的工作模式是无阴影的,所以它只需要相机的矢量.

EN

回答 1

Computer Graphics用户

发布于 2016-03-14 21:29:39

您可能需要计算每个像素的反射向量,而不是每个顶点。计算是非线性的,因此,如果模型没有精确的关联,每一个顶点和插值就不能得到很好的结果。

normtoCameraVector发送到像素着色器,将它们归一化,并将// Reflection Map下的所有计算结果移到像素着色器。这会给你一些更好的结果。

票数 3
EN
页面原文内容由Computer Graphics提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://computergraphics.stackexchange.com/questions/2184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档