Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved the VSG_BILLBOARD handling so it can now works properly for … #40

Merged
merged 1 commit into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions data/shaders/fbxshader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#extension GL_ARB_separate_shader_objects : enable
layout(push_constant) uniform PushConstants {
mat4 projection;
mat4 modelview;
mat4 modelView;
//mat3 normal;
} pc;
layout(location = 0) in vec3 osg_Vertex;
Expand All @@ -30,22 +30,30 @@ out gl_PerVertex{ vec4 gl_Position; };

void main()
{
mat4 modelView = pc.modelview;
mat4 modelView = pc.modelView;

#ifdef VSG_BILLBOARD
// xaxis
modelView[0][0] = 1.0;
modelView[0][1] = 0.0;
modelView[0][2] = 0.0;
// yaxis
//modelView[1][0] = 0.0;
//modelView[1][1] = 1.0;
//modelView[1][2] = 0.0;
// zaxis
modelView[2][0] = 0.0;
modelView[2][1] = 0.0;
modelView[2][2] = 1.0;
vec3 lookDir = vec3(-modelView[0][2], -modelView[1][2], -modelView[2][2]);

// rotate around local z axis
float l = length(lookDir.xy);
if (l>0.0)
{
float inv = 1.0/l;
float c = lookDir.y * inv;
float s = lookDir.x * inv;

mat4 rotation_z = mat4(c, -s, 0.0, 0.0,
s, c, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);

modelView = modelView * rotation_z;
}
#endif

gl_Position = (pc.projection * modelView) * vec4(osg_Vertex, 1.0);

#ifdef VSG_TEXCOORD0
texCoord0 = osg_MultiTexCoord0.st;
#endif
Expand Down
42 changes: 25 additions & 17 deletions src/osg2vsg/shaders/fbxshader_vert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ char fbxshader_vert[] = "#version 450\n"
"#extension GL_ARB_separate_shader_objects : enable\n"
"layout(push_constant) uniform PushConstants {\n"
" mat4 projection;\n"
" mat4 modelview;\n"
" mat4 modelView;\n"
" //mat3 normal;\n"
"} pc;\n"
"layout(location = 0) in vec3 osg_Vertex;\n"
Expand All @@ -13,15 +13,15 @@ char fbxshader_vert[] = "#version 450\n"
"#endif\n"
"#ifdef VSG_TANGENT\n"
"layout(location = 2) in vec4 osg_Tangent;\n"
"#endif\n\n"
"#endif\n"
"#ifdef VSG_COLOR\n"
"layout(location = 3) in vec4 osg_Color;\n"
"layout(location = 3) out vec4 vertColor;\n"
"#endif\n\n"
"#endif\n"
"#ifdef VSG_TEXCOORD0\n"
"layout(location = 4) in vec2 osg_MultiTexCoord0;\n"
"layout(location = 4) out vec2 texCoord0;\n"
"#endif\n\n"
"#endif\n"
"#ifdef VSG_LIGHTING\n"
"layout(location = 5) out vec3 viewDir;\n"
"layout(location = 6) out vec3 lightDir;\n"
Expand All @@ -30,22 +30,30 @@ char fbxshader_vert[] = "#version 450\n"
"\n"
"void main()\n"
"{\n"
" mat4 modelView = pc.modelview;\n"
" mat4 modelView = pc.modelView;\n"
"\n"
"#ifdef VSG_BILLBOARD\n"
" // xaxis\n"
" modelView[0][0] = 1.0;\n"
" modelView[0][1] = 0.0;\n"
" modelView[0][2] = 0.0;\n"
" // yaxis\n"
" modelView[1][0] = 0.0;\n"
" modelView[1][1] = 1.0;\n"
" modelView[1][2] = 0.0;\n"
" // zaxis\n"
" //modelView[2][0] = 0.0;\n"
" //modelView[2][1] = 0.0;\n"
" //modelView[2][2] = 1.0;\n"
" vec3 lookDir = vec3(-modelView[0][2], -modelView[1][2], -modelView[2][2]);\n"
"\n"
" // rotate around local z axis\n"
" float l = length(lookDir.xy);\n"
" if (l>0.0)\n"
" {\n"
" float inv = 1.0/l;\n"
" float c = lookDir.y * inv;\n"
" float s = lookDir.x * inv;\n"
"\n"
" mat4 rotation_z = mat4(c, -s, 0.0, 0.0,\n"
" s, c, 0.0, 0.0,\n"
" 0.0, 0.0, 1.0, 0.0,\n"
" 0.0, 0.0, 0.0, 1.0);\n"
"\n"
" modelView = modelView * rotation_z;\n"
" }\n"
"#endif\n"
"\n"
" gl_Position = (pc.projection * modelView) * vec4(osg_Vertex, 1.0);\n"
"\n"
"#ifdef VSG_TEXCOORD0\n"
" texCoord0 = osg_MultiTexCoord0.st;\n"
"#endif\n"
Expand Down