/* CPU */
glUniformMatrix4fv(glGetUniformLocation(proH, "VM_bakeDEBUG"), 1, GL_FALSE, &myGL->VM_bakeDEBUG[0][0]);
glm::mat4 MV_bakeDEBUG = myGL->VM_bakeDEBUG * MM;
glm::mat3 NM_bakeDEBUG = glm::mat3(glm::transpose(glm::inverse(MV_bakeDEBUG)));
glUniformMatrix3fv(glGetUniformLocation(proH, "NM_bakeDEBUG"), 1, GL_FALSE, &NM_bakeDEBUG[0][0]);
glm::mat4 ProjectorM = biasM * myGL->selCamLi->PM * myGL->VM_bakeDEBUG * MM;
glUniformMatrix4fv(glGetUniformLocation(proH, "ProjectorM"), 1, GL_FALSE, &ProjectorM[0][0]);
/* VERT */
layout(location = 0) in vec3 pE;
layout(location = 1) in vec2 uvE;
layout(location = 3) in vec3 nE;
uniform mat3 NM_bakeDEBUG;
uniform mat4 MVP, ProjectorM;
out Vert
{
vec3 N_VS_bakeDEBUG;
vec4 bakeCoord;
} v;
void main()
{
vec2 transformUV = uvE * 2.f - 1.f;
gl_Position = vec4(transformUV, 0.f, 1.f);
v.N_VS_bakeDEBUG = normalize(NM_bakeDEBUG * nE);
v.bakeCoord = ProjectorM * vec4(pE, 1.f);
}
/* FRAG */
in Vert
{
vec3 N_VS_bakeDEBUG;
vec4 bakeCoord;
} v;
layout(bindless_sampler, location = 0) uniform sampler2D toProject_64;
layout(location = 0) out vec4 Ci;
uniform mat4 VM_bakeDEBUG;
void main()
{
vec3 V_VS_bakeDEBUG = normalize(VM_bakeDEBUG * vec4(10.f, 10.f, 10.f, 0.f)).xyz;
if (v.bakeCoord.q > 0.f) // prevents reverse projection
{
if (dot(v.N_VS_bakeDEBUG, V_VS_bakeDEBUG) > 0.f) //NdotV prevents backfacing proj
{
Ci = textureProj(toProject_64, v.bakeCoord);
}
else
Ci = vec4(0.f); //existing texture
}
}