Instancing now works with Lighting material, and shadows are supported with instanced geometries

experimental
Nehon 11 years ago
parent a11bfa5e63
commit 7356b727c3
  1. 23
      jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md
  2. 14
      jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert
  3. 15
      jme3-core/src/main/resources/Common/MatDefs/Misc/Unshaded.j3md
  4. 1
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow.j3md
  5. 6
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow.vert
  6. 7
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PostShadow15.vert
  7. 6
      jme3-core/src/main/resources/Common/MatDefs/Shadow/PreShadow.vert
  8. 5
      jme3-core/src/main/resources/Common/ShaderLib/Instancing.glsllib
  9. 1
      jme3-effects/src/main/resources/Common/MatDefs/SSAO/normal.vert

@ -132,6 +132,8 @@ MaterialDef Phong Lighting {
// For hardware skinning
Int NumberOfBones
Matrix4Array BoneMatrices
Boolean UseInstancing
}
Technique {
@ -148,6 +150,7 @@ MaterialDef Phong Lighting {
ViewMatrix
CameraPosition
WorldMatrix
ViewProjectionMatrix
}
Defines {
@ -177,6 +180,8 @@ MaterialDef Phong Lighting {
SPHERE_MAP : SphereMap
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
}
@ -188,12 +193,15 @@ MaterialDef Phong Lighting {
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
COLOR_MAP : ColorMap
DISCARD_ALPHA : AlphaDiscardThreshold
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
ForcedRenderState {
@ -214,6 +222,8 @@ MaterialDef Phong Lighting {
WorldParameters {
WorldViewProjectionMatrix
WorldMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
@ -227,6 +237,7 @@ MaterialDef Phong Lighting {
PSSM : Splits
POINTLIGHT : LightViewProjectionMatrix5
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
ForcedRenderState {
@ -243,6 +254,8 @@ MaterialDef Phong Lighting {
WorldParameters {
WorldViewProjectionMatrix
WorldMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
@ -256,6 +269,7 @@ MaterialDef Phong Lighting {
PSSM : Splits
POINTLIGHT : LightViewProjectionMatrix5
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
ForcedRenderState {
@ -274,11 +288,14 @@ MaterialDef Phong Lighting {
WorldViewProjectionMatrix
WorldViewMatrix
NormalMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
DIFFUSEMAP_ALPHA : DiffuseMap
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
}
@ -293,11 +310,14 @@ MaterialDef Phong Lighting {
WorldViewProjectionMatrix
WorldViewMatrix
NormalMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
DIFFUSEMAP_ALPHA : DiffuseMap
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
}
@ -339,6 +359,8 @@ MaterialDef Phong Lighting {
WorldParameters {
WorldViewProjectionMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
@ -347,6 +369,7 @@ MaterialDef Phong Lighting {
HAS_GLOWCOLOR : GlowColor
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
}

@ -1,12 +1,16 @@
#import "Common/ShaderLib/Instancing.glsllib"
#define ATTENUATION
//#define HQ_ATTENUATION
#import "Common/ShaderLib/Skinning.glsllib"
/*
uniform mat4 g_WorldViewProjectionMatrix;
uniform mat4 g_WorldViewMatrix;
uniform mat3 g_NormalMatrix;
uniform mat4 g_ViewMatrix;
*/
uniform vec4 m_Ambient;
uniform vec4 m_Diffuse;
@ -148,14 +152,14 @@ void main(){
#endif
#endif
gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
gl_Position = TransformWorldViewProjection(modelSpacePos);// g_WorldViewProjectionMatrix * modelSpacePos;
texCoord = inTexCoord;
#ifdef SEPARATE_TEXCOORD
texCoord2 = inTexCoord2;
#endif
vec3 wvPosition = (g_WorldViewMatrix * modelSpacePos).xyz;
vec3 wvNormal = normalize(g_NormalMatrix * modelSpaceNorm);
vec3 wvPosition = TransformWorldView(modelSpacePos).xyz;// (g_WorldViewMatrix * modelSpacePos).xyz;
vec3 wvNormal = normalize(TransformNormal(modelSpaceNorm));//normalize(g_NormalMatrix * modelSpaceNorm);
vec3 viewDir = normalize(-wvPosition);
//vec4 lightColor = g_LightColor[gl_InstanceID];
@ -168,7 +172,7 @@ void main(){
vec4 lightColor = g_LightColor;
#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
vec3 wvTangent = normalize(g_NormalMatrix * modelSpaceTan);
vec3 wvTangent = normalize(TransformNormal(modelSpaceTan));
vec3 wvBinormal = cross(wvNormal, wvTangent);
mat3 tbnMat = mat3(wvTangent, wvBinormal * inTangent.w,wvNormal);
@ -187,7 +191,7 @@ void main(){
lightComputeDir(wvPosition, lightColor, wvLightPos, vLightDir);
#ifdef V_TANGENT
vNormal = normalize(g_NormalMatrix * inTangent.xyz);
vNormal = normalize(TransformNormal(inTangent.xyz));
vNormal = -cross(cross(vLightDir.xyz, vNormal), vNormal);
#endif
#endif

@ -87,10 +87,13 @@ MaterialDef Unshaded {
WorldViewProjectionMatrix
WorldViewMatrix
NormalMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
}
@ -102,12 +105,15 @@ MaterialDef Unshaded {
WorldParameters {
WorldViewProjectionMatrix
WorldViewMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
COLOR_MAP : ColorMap
DISCARD_ALPHA : AlphaDiscardThreshold
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
ForcedRenderState {
@ -128,6 +134,8 @@ MaterialDef Unshaded {
WorldParameters {
WorldViewProjectionMatrix
WorldMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
@ -141,6 +149,7 @@ MaterialDef Unshaded {
PSSM : Splits
POINTLIGHT : LightViewProjectionMatrix5
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
ForcedRenderState {
@ -157,6 +166,8 @@ MaterialDef Unshaded {
WorldParameters {
WorldViewProjectionMatrix
WorldMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
@ -170,6 +181,7 @@ MaterialDef Unshaded {
PSSM : Splits
POINTLIGHT : LightViewProjectionMatrix5
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
ForcedRenderState {
@ -186,6 +198,8 @@ MaterialDef Unshaded {
WorldParameters {
WorldViewProjectionMatrix
ViewProjectionMatrix
ViewMatrix
}
Defines {
@ -193,6 +207,7 @@ MaterialDef Unshaded {
HAS_GLOWMAP : GlowMap
HAS_GLOWCOLOR : GlowColor
NUM_BONES : NumberOfBones
INSTANCING : UseInstancing
}
}
}

@ -29,6 +29,7 @@ MaterialDef Post Shadow {
Float PCFEdge
Float ShadowMapSize
}
Technique {

@ -1,12 +1,10 @@
#import "Common/ShaderLib/Instancing.glsllib"
#import "Common/ShaderLib/Skinning.glsllib"
uniform mat4 m_LightViewProjectionMatrix0;
uniform mat4 m_LightViewProjectionMatrix1;
uniform mat4 m_LightViewProjectionMatrix2;
uniform mat4 m_LightViewProjectionMatrix3;
uniform mat4 g_WorldViewProjectionMatrix;
uniform mat4 g_WorldMatrix;
uniform mat4 g_ViewMatrix;
uniform vec3 m_LightPos;
varying vec4 projCoord0;
@ -52,7 +50,7 @@ void main(){
#ifdef NUM_BONES
Skinning_Compute(modelSpacePos);
#endif
gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
gl_Position = TransformWorldViewProjection(modelSpacePos);
#ifndef POINTLIGHT
#ifdef PSSM

@ -1,11 +1,10 @@
#import "Common/ShaderLib/Instancing.glsllib"
#import "Common/ShaderLib/Skinning.glsllib"
uniform mat4 m_LightViewProjectionMatrix0;
uniform mat4 m_LightViewProjectionMatrix1;
uniform mat4 m_LightViewProjectionMatrix2;
uniform mat4 m_LightViewProjectionMatrix3;
uniform mat4 g_WorldViewProjectionMatrix;
uniform mat4 g_WorldMatrix;
out vec4 projCoord0;
out vec4 projCoord1;
@ -51,7 +50,7 @@ void main(){
#ifdef NUM_BONES
Skinning_Compute(modelSpacePos);
#endif
gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
gl_Position = TransformWorldViewProjection(modelSpacePos);
#ifndef POINTLIGHT
#ifdef PSSM
@ -60,7 +59,7 @@ void main(){
vec4 worldPos=vec4(0.0);
#endif
// get the vertex in world space
worldPos = g_WorldMatrix * modelSpacePos;
worldPos = TransformWorld(modelSpacePos);
#ifdef DISCARD_ALPHA
texCoord = inTexCoord;

@ -1,10 +1,8 @@
#import "Common/ShaderLib/Instancing.glsllib"
#import "Common/ShaderLib/Skinning.glsllib"
attribute vec3 inPosition;
attribute vec2 inTexCoord;
uniform mat4 g_WorldViewProjectionMatrix;
uniform mat4 g_WorldViewMatrix;
varying vec2 texCoord;
void main(){
@ -13,6 +11,6 @@ void main(){
#ifdef NUM_BONES
Skinning_Compute(modelSpacePos);
#endif
gl_Position = g_WorldViewProjectionMatrix * modelSpacePos;
gl_Position = TransformWorldViewProjection(modelSpacePos);
texCoord = inTexCoord;
}

@ -78,6 +78,11 @@ vec3 TransformNormal(vec3 vec)
#else
vec4 TransformWorld(vec4 position)
{
return g_WorldMatrix * position;
}
vec4 TransformWorldView(vec4 position)
{
return g_WorldViewMatrix * position;

@ -1,3 +1,4 @@
#import "Common/ShaderLib/Instancing.glsllib"
#import "Common/ShaderLib/Skinning.glsllib"
uniform mat4 g_WorldViewProjectionMatrix;
uniform mat3 g_NormalMatrix;

Loading…
Cancel
Save