2
$\begingroup$

I'm trying to view tangents used in sceneview and that will be exported. I found two options:

  • Using cycles material:

geometry or just tangent-node but both doesn't work - i got only black screen. (Normals work great)

  • Using glsl shader in BGE:

https://en.wikibooks.org/wiki/GLSL_Programming/Blender/Lighting_of_Bumpy_Surfaces but shader.setAttrib(bge.logic.SHD_TANGENT) doesnt work(same tangent for entire mesh). I also can view everything except tangents :(

So, maybe I miss some ways to do it?

$\endgroup$
1
$\begingroup$

My bad, tangents successfully appears in shader when I switched viewport shading to "Material".

Testing code:

import bge

cont = bge.logic.getCurrentController()

VertexShader = """
    attribute vec4 tangent;
    varying vec4 frag_tangent;
    void main()
    {
        frag_tangent = tangent;
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    }
"""

FragmentShader = """
    varying vec4 frag_tangent;
    void main()
    {
        gl_FragColor = frag_tangent;
    }
"""

mesh = cont.owner.meshes[0]
for mat in mesh.materials:
    shader = mat.getShader()
    if shader != None:
        if not shader.isValid():
            shader.setSource(VertexShader, FragmentShader, 1)
shader.setAttrib(bge.logic.SHD_TANGENT)

It works great when viewport is in right shading mode.

Thanks :)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.