Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (805)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Vertex Skinning Issues  (Read 1213 times)
0 Members and 1 Guest are viewing this topic.
Offline Coldstream24

JGO Ninja


Medals: 82
Projects: 1
Exp: 4 years


You can fill that void inside with programming, but you'll never return a value.


« Posted 2020-02-16 05:36:58 »

Hey all,
I've been working on a 3d project involving Source Engine models and have gotten stuck with vertex skinning in GLSL.
I've tried a few approaches based on resources I've seen - examples from Khronos, Nvidia, even other projects with a similar aim, which don't seem to have problems, and yet here I am, and I can't get it to work.
It seems that for no real reason, most vertices have their position set to (0, 0, 0) when I try to render them despite nothing really appearing to be the cause - I've even tried passing identity matrices through to the shader and it still doesn't work right.
Currently the code I've landed on is this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
#version 330

const int MAX_JOINTS = 150;

attribute vec3 aPosition;
attribute vec3 aNormal;
attribute vec2 aTexCoord0;
attribute vec2 aTexCoord1;
attribute vec3 aTangent;
attribute vec3 aBoneWeights;
attribute ivec4 aBoneIDs;

uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
uniform vec3 viewPos;
uniform mat4 jointMatrices[MAX_JOINTS];

out VS_OUT{
    vec2 texCoord0;
    vec2 texCoord1;
    vec3 fragPos;
    vec3 viewPos;
    vec3 normal;
} vs_out;

mat4 getBoneMatrix(int boneID){    
    return jointMatrices[boneID];
}
mat4 accumulateSkinMatrix(){
    mat4 result;
    vec3 boneWeights = aBoneWeights;
    result = boneWeights.x * getBoneMatrix(int(aBoneIDs.x));
    result = result + boneWeights.y * getBoneMatrix(int(aBoneIDs.y));
    result = result + boneWeights.z * getBoneMatrix(int(aBoneIDs.z));
    return result;
}

void main(){
    vec4 newVertex = vec4(0.0);
    vec4 newNormal = vec4(0.0);
   
    mat4 skinMatrix = accumulateSkinMatrix();
    newVertex = skinMatrix * vec4(aPosition, 1.0);
    newNormal = skinMatrix * vec4(aNormal, 0.0);

    vs_out.fragPos = vec3(modelMatrix * newVertex);

    vs_out.texCoord0 = aTexCoord0;
    vs_out.texCoord1 = aTexCoord1;

    vs_out.normal = mat3(transpose(inverse(modelMatrix))) * newNormal.xyz;
    vs_out.viewPos = viewPos;

    gl_Position = projectionMatrix * viewMatrix * modelMatrix * newVertex;
}


I won't bother including the fragment shader as it's very simplistic and only really renders the texture at the given TexCoords, which aren't causing issues.

The result I get with passing data from the file itself is:


And when I set all vertex weights to be 1.0 (by changing boneWeights to be equal to vec3(1.0) instead of aBoneWeights, I get a mostly working but still obviously broken render:


Debugging in RenderDoc hasn't given me too much of a hint either. I know that I'm correctly calculating the bone positions as the lines beneath the model are being rendered after the model itself for debugging and are in the right place. It shows that I'm passing matrices correctly for the bones each time but for some inexplicable reason the vertex position is being set to 0.

I've made the most progress on it today after weeks of scratching my head and doing other things but I'd really like to get this right and move onto other things. Any insights would be greatly appreciated.

My website: http://www.onedropgames.com/
My soundcloud: http://www.soundcloud.com/coldstream24
Creator of the Morningside Engine, co-founder of Onedrop Games.
Offline NegativeZero

JGO Kernel


Medals: 357
Exp: 1 month or less


Zero but not.


« Reply #1 - Posted 2020-02-17 23:00:48 »

Nothing strikes me as obviously wrong with the shader code you've provided. Given that you have some vertices outputting as a zeroed vector, it's probably that for those verticies either
skinMatrix
is a zeroed matrix or
aPosition
is a zeroed vector. As a sanity check I'd start by setting
skinMatrix
to the identity matrix to make sure
aPosition
is what you expect. If it's still distorted, there's an issue with the vertex data you're passing in. Otherwise, I'd try and output your skinning data as the fragment colour to see if that data is being passed in correctly. It seems likely that the issue would be there.

Pages: [1]
  ignore  |  Print  
 
 

 
Riven (585 views)
2019-09-04 15:33:17

hadezbladez (5526 views)
2018-11-16 13:46:03

hadezbladez (2407 views)
2018-11-16 13:41:33

hadezbladez (5788 views)
2018-11-16 13:35:35

hadezbladez (1228 views)
2018-11-16 13:32:03

EgonOlsen (4666 views)
2018-06-10 19:43:48

EgonOlsen (5685 views)
2018-06-10 19:43:44

EgonOlsen (3200 views)
2018-06-10 19:43:20

DesertCoockie (4102 views)
2018-05-13 18:23:11

nelsongames (5118 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!