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

Add instanced attributes flags to GLSL prefix #7277

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
17 changes: 14 additions & 3 deletions gdx/res/com/badlogic/gdx/graphics/g3d/shaders/default.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ attribute vec2 a_boneWeight7;

uniform mat4 u_worldTrans;

#ifdef a_worldTrans_instancedFlag
attribute mat4 a_worldTrans;
#endif //a_worldTrans_instancedFlag

#if defined(numBones)
#if numBones > 0
uniform mat4 u_bones[numBones];
Expand Down Expand Up @@ -241,10 +245,17 @@ void main() {
#endif //boneWeight7Flag
#endif //skinningFlag

#ifdef a_worldTrans_instancedFlag
mat4 var_worldTrans = a_worldTrans * u_worldTrans;
#define worldTrans var_worldTrans
#else
#define worldTrans u_worldTrans
#endif //a_worldTrans_instancedFlag

#ifdef skinningFlag
vec4 pos = u_worldTrans * skinning * vec4(a_position, 1.0);
vec4 pos = worldTrans * skinning * vec4(a_position, 1.0);
#else
vec4 pos = u_worldTrans * vec4(a_position, 1.0);
vec4 pos = worldTrans * vec4(a_position, 1.0);
#endif

gl_Position = u_projViewTrans * pos;
Expand All @@ -257,7 +268,7 @@ void main() {

#if defined(normalFlag)
#if defined(skinningFlag)
vec3 normal = normalize((u_worldTrans * skinning * vec4(a_normal, 0.0)).xyz);
vec3 normal = normalize((worldTrans * skinning * vec4(a_normal, 0.0)).xyz);
#else
vec3 normal = normalize(u_normalMatrix * a_normal);
#endif
Expand Down
11 changes: 11 additions & 0 deletions gdx/src/com/badlogic/gdx/graphics/g3d/shaders/DefaultShader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Attribute;
import com.badlogic.gdx.graphics.g3d.Attributes;
Expand Down Expand Up @@ -744,6 +745,16 @@ public static String createPrefix (final Renderable renderable, final Config con
if ((attributesMask & FloatAttribute.AlphaTest) == FloatAttribute.AlphaTest)
prefix += "#define " + FloatAttribute.AlphaTestAlias + "Flag\n";
if (renderable.bones != null && config.numBones > 0) prefix += "#define numBones " + config.numBones + "\n";

final VertexAttributes instancedAttrs = renderable.meshPart.mesh.getInstancedAttributes();
if (instancedAttrs != null) {
final int attrsCount = instancedAttrs.size();
for (int i = 0; i < attrsCount; i++) {
final VertexAttribute attr = instancedAttrs.get(i);
prefix += "#define " + attr.alias + "_instancedFlag\n";
}
}

return prefix;
}

Expand Down