Skip to main content
deleted 12 characters in body
Source Link
user68817
user68817

Im using a deffered shading technique and here is my g-pass Vertex shader code:

Im using a deffered shading technique and here is my g-pass Vertex shader code:

Im using deffered shading and here is my g-pass Vertex shader code:

added 909 characters in body
Source Link
user68817
user68817

[![][1]][1] [1]: https://i.sstatic.net/g1Cjw.png There is a point light "attached" to the camera (which clearly isnt working) and the reflection is wrong.

[![][1]][1] [1]: https://i.sstatic.net/g1Cjw.png There is a point light "attached" to the camera (which clearly isnt working) and the reflection is wrong.

added 909 characters in body
Source Link
user68817
user68817

Im using a deffered shading technique and here is my g-pass Vertex shader code:

vec3 T = normalize(vec3(transform * vec4(tangent, 0.0)));
vec3 N = normalize(vec3(transform * vec4(normal, 0.0)));
vec3 B = cross(T, N);
vs_out.TBN = mat3(T, B, N);

And my Fragment shader code...

gNormal.xyz = normalize(fs_in.TBN * (texture(normal, fs_in.uv).rgb * 2.0 - 1.0));

Usually, you would times your light direction and/or view direction with TBN. However, my g buffers are taking up more bandwidth than they should, and i would prefer to get world space normals from the normal map. How should i go about doing so?

EDIT: Apparently, this should output world space... but it isnt. So i guess something here is wrong.

Tangent generation function:

void CalculateTangents() {
        tangents.clear();
        for (int i = 0; i < vertices.size(); i += 3) {
            glm::vec3 edge1 = vertices[i + 1] - vertices[i];
            glm::vec3 edge2 = vertices[i + 2] - vertices[i];
            glm::vec2 deltaUV1 = uvs[i + 1] - uvs[i];
            glm::vec2 deltaUV2 = uvs[i + 2] - uvs[i];

            GLfloat f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);
            glm::vec3 tangent;
            tangent.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
            tangent.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
            tangent.z = f * (deltaUV2.y * edge1.z - deltaUV1.y * edge2.z);
            tangent = glm::normalize(tangent);

            tangents.push_back(tangent);
            tangents.push_back(tangent);
            tangents.push_back(tangent);
        }
    }

Im using a deffered shading technique and here is my g-pass Vertex shader code:

vec3 T = normalize(vec3(transform * vec4(tangent, 0.0)));
vec3 N = normalize(vec3(transform * vec4(normal, 0.0)));
vec3 B = cross(T, N);
vs_out.TBN = mat3(T, B, N);

And my Fragment shader code...

gNormal.xyz = normalize(fs_in.TBN * (texture(normal, fs_in.uv).rgb * 2.0 - 1.0));

Usually, you would times your light direction and/or view direction with TBN. However, my g buffers are taking up more bandwidth than they should, and i would prefer to get world space normals from the normal map. How should i go about doing so?

Im using a deffered shading technique and here is my g-pass Vertex shader code:

vec3 T = normalize(vec3(transform * vec4(tangent, 0.0)));
vec3 N = normalize(vec3(transform * vec4(normal, 0.0)));
vec3 B = cross(T, N);
vs_out.TBN = mat3(T, B, N);

And my Fragment shader code...

gNormal.xyz = normalize(fs_in.TBN * (texture(normal, fs_in.uv).rgb * 2.0 - 1.0));

Usually, you would times your light direction and/or view direction with TBN. However, my g buffers are taking up more bandwidth than they should, and i would prefer to get world space normals from the normal map. How should i go about doing so?

EDIT: Apparently, this should output world space... but it isnt. So i guess something here is wrong.

Tangent generation function:

void CalculateTangents() {
        tangents.clear();
        for (int i = 0; i < vertices.size(); i += 3) {
            glm::vec3 edge1 = vertices[i + 1] - vertices[i];
            glm::vec3 edge2 = vertices[i + 2] - vertices[i];
            glm::vec2 deltaUV1 = uvs[i + 1] - uvs[i];
            glm::vec2 deltaUV2 = uvs[i + 2] - uvs[i];

            GLfloat f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);
            glm::vec3 tangent;
            tangent.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);
            tangent.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);
            tangent.z = f * (deltaUV2.y * edge1.z - deltaUV1.y * edge2.z);
            tangent = glm::normalize(tangent);

            tangents.push_back(tangent);
            tangents.push_back(tangent);
            tangents.push_back(tangent);
        }
    }
deleted 39 characters in body
Source Link
user68817
user68817
Loading
deleted 74 characters in body
Source Link
user68817
user68817
Loading
edited body
Source Link
user68817
user68817
Loading
Source Link
user68817
user68817
Loading