Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public class RenderManager {
private boolean handleTranslucentBucket = true;
private AppProfiler prof;
private LightFilter lightFilter = new DefaultLightFilter();
private TechniqueDef.LightMode preferredLightMode = TechniqueDef.LightMode.MultiPass;
private TechniqueDef.LightMode preferredLightMode = TechniqueDef.LightMode.SinglePass;
private int singlePassLightBatchSize = 1;
private final MatParamOverride boundDrawBufferId = new MatParamOverride(VarType.Int, "BoundDrawBuffer", 0);
private Predicate<Geometry> renderFilter;
Expand Down
13 changes: 7 additions & 6 deletions jme3-core/src/main/resources/Common/MatDefs/Light/GBuf.vert
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ void main(){
gl_Position = g_WorldViewProjectionMatrix * pos;
texCoord = inTexCoord;

#if defined(NORMALMAP)
vec4 wvNormal, wvTangent, wvBinormal;
#if defined(NORMALMAP)
vec4 wvNormal, wvTangent, wvBinormal;

wvNormal = vec4(inNormal, 0.0);
wvTangent = vec4(inTangent, 0.0);

wvNormal.xyz = normalize( (g_WorldMatrix * wvNormal).xyz );
wvTangent.xyz = normalize( (g_WorldMatrix * wvTangent).xyz );
wvBinormal.xyz = cross(wvNormal.xyz, wvTangent.xyz);
tbnMat = mat3(wvTangent.xyz, wvBinormal.xyz, wvNormal.xyz);
wvNormal.xyz = normalize( (g_WorldMatrix * wvNormal).xyz );
wvTangent.xyz = normalize( (g_WorldMatrix * wvTangent).xyz );
wvTangent.xyz = normalize(wvTangent.xyz - wvNormal.xyz * dot(wvTangent.xyz, wvNormal.xyz));
wvBinormal.xyz = normalize(cross(wvNormal.xyz, wvTangent.xyz));
tbnMat = mat3(wvTangent.xyz, wvBinormal.xyz, wvNormal.xyz);

vNormal = wvNormal.xyz;
#else
Expand Down
12 changes: 7 additions & 5 deletions jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.vert
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,13 @@ void main(){
wvLightPos.w = g_LightPosition.w;
vec4 lightColor = g_LightColor;

#if (defined(NORMALMAP) || defined(PARALLAXMAP)) && !defined(VERTEX_LIGHTING)
vec3 wvTangent = normalize(TransformNormal(modelSpaceTan));
vec3 wvBinormal = cross(wvNormal, wvTangent);
mat3 tbnMat = mat3(wvTangent, wvBinormal * inTangent.w,wvNormal);
#endif
#if (defined(NORMALMAP) || defined(PARALLAXMAP)) && !defined(VERTEX_LIGHTING)
vec3 tbnNormal = normalize(wvNormal);
vec3 wvTangent = normalize(TransformNormal(modelSpaceTan));
wvTangent = normalize(wvTangent - tbnNormal * dot(wvTangent, tbnNormal));
vec3 wvBinormal = normalize(cross(tbnNormal, wvTangent)) * inTangent.w;
mat3 tbnMat = mat3(wvTangent, wvBinormal, tbnNormal);
#endif

#if defined(NORMALMAP) && !defined(VERTEX_LIGHTING)
vViewDir = -wvPosition * tbnMat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ uniform float m_Shininess;
void main(){
#if !defined(VERTEX_LIGHTING)
#if defined(NORMALMAP)
mat3 tbnMat = mat3(vTangent.xyz, vTangent.w * cross( (vNormal), (vTangent.xyz)), vNormal.xyz);
vec3 tbnNormal = normalize(vNormal.xyz);
vec3 tbnTangent = normalize(vTangent.xyz - tbnNormal * dot(vTangent.xyz, tbnNormal));
vec3 tbnBinormal = normalize(cross(tbnNormal, tbnTangent)) * vTangent.w;
mat3 tbnMat = mat3(tbnTangent, tbnBinormal, tbnNormal);

if (!gl_FrontFacing)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ void lightComputeDir(in vec3 worldPos, in float lightType, in vec4 position, out
vec3 tempVec = position.xyz * sign(posLight - 0.5) - (worldPos * posLight);
lightVec = tempVec;
float dist = length(tempVec);
if (dist <= 0.0) {
lightDir = vec4(0.0);
return;
}
#ifdef SRGB
lightDir.w = (1.0 - position.w * dist) / (1.0 + position.w * dist * dist);
lightDir.w = clamp(lightDir.w, 1.0 - posLight, 1.0);
Expand Down
37 changes: 21 additions & 16 deletions jme3-core/src/main/resources/Common/ShaderLib/Math.glsllib
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
#ifndef __MATH_GLSLLIB__
#define __MATH_GLSLLIB__

/// Multiplies the vector by the quaternion, then returns the resultant vector.
vec3 Math_QuaternionMult(in vec4 quat, in vec3 vec){
return vec + 2.0 * cross(quat.xyz, cross(quat.xyz, vec) + quat.w * vec);
}

void Math_lengthAndNormalize(in vec3 vec,out float outLength,out vec3 outNormal){
float dotv=dot(vec,vec);
float invl=inversesqrt(dotv);
outNormal=vec*invl;
outLength=invl*dotv;
}


#ifndef __MATH_GLSLLIB__
#define __MATH_GLSLLIB__

/// Multiplies the vector by the quaternion, then returns the resultant vector.
vec3 Math_QuaternionMult(in vec4 quat, in vec3 vec){
return vec + 2.0 * cross(quat.xyz, cross(quat.xyz, vec) + quat.w * vec);
}

void Math_lengthAndNormalize(in vec3 vec,out float outLength,out vec3 outNormal){
float dotv=dot(vec,vec);
if(dotv <= 0.0){
outNormal = vec3(0.0);
outLength = 0.0;
return;
}
float invl=inversesqrt(dotv);
outNormal=vec*invl;
outLength=invl*dotv;
}


#endif
10 changes: 6 additions & 4 deletions jme3-core/src/main/resources/Common/ShaderLib/Tangent.glsllib
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ void Tangent_ComputeVS(out vec3 outNormal, out vec3 outTangent){
outTangent = normalize(g_NormalMatrix * inTangent);
}

mat3 Tangent_GetBasis(){
vec3 wvBinormal = cross(wvNormal, wvTangent);
return mat3(wvTangent, wvBinormal, wvNormal);
}
mat3 Tangent_GetBasis(){
vec3 n = normalize(wvNormal);
vec3 t = normalize(wvTangent - n * dot(wvTangent, n));
vec3 b = normalize(cross(n, t));
return mat3(t, b, n);
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,10 @@
surface.envLightContribution = vec3(0.0);

#ifdef ENABLE_PBRLightingUtils_getWorldTangent
vec3 tan = normalize(wTangent.xyz);
surface.tbnMat = mat3(tan, wTangent.w * cross( surface.geometryNormal, tan), surface.geometryNormal);
vec3 n = normalize(surface.geometryNormal);
vec3 tan = normalize(wTangent.xyz - n * dot(wTangent.xyz, n));
vec3 bitan = normalize(cross(n, tan)) * wTangent.w;
surface.tbnMat = mat3(tan, bitan, n);
surface.hasTangents = true;
#endif

Expand Down
2 changes: 2 additions & 0 deletions jme3-core/src/test/java/com/jme3/system/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.jme3.asset.AssetConfig;
import com.jme3.asset.AssetManager;
import com.jme3.asset.DesktopAssetManager;
import com.jme3.material.TechniqueDef;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.Renderer;

Expand Down Expand Up @@ -63,6 +64,7 @@ public static RenderManager createRenderManager() {

public static RenderManager createRenderManager(Renderer renderer) {
RenderManager rm = new RenderManager(renderer);
rm.setPreferredLightMode(TechniqueDef.LightMode.MultiPass);
rm.setPassDrawBufferTargetIdToShaders(false);
return rm;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,10 @@ void main(){
#else
vec3 normal = calculateNormal(texCoord);
#endif
mat3 tbnMat = mat3(normalize(vTangent.xyz) , normalize(vBinormal.xyz) , normalize(vNormal.xyz));
vec3 tbnNormal = normalize(vNormal.xyz);
vec3 tbnTangent = normalize(vTangent.xyz - tbnNormal * dot(vTangent.xyz, tbnNormal));
vec3 tbnBinormal = normalize(cross(tbnNormal, tbnTangent)) * sign(dot(vBinormal.xyz, cross(tbnNormal, tbnTangent)));
mat3 tbnMat = mat3(tbnTangent, tbnBinormal, tbnNormal);
#else
vec3 normal = vNormal;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ void main(){
// specific to normal maps:
//--------------------------
#if defined(NORMALMAP) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7) || defined(NORMALMAP_8) || defined(NORMALMAP_9) || defined(NORMALMAP_10) || defined(NORMALMAP_11)
vTangent = g_NormalMatrix * inTangent.xyz;
vBinormal = cross(wvNormal, vTangent)* inTangent.w;
vTangent = normalize(g_NormalMatrix * inTangent.xyz);
vTangent = normalize(vTangent - wvNormal * dot(vTangent, wvNormal));
vBinormal = normalize(cross(wvNormal, vTangent)) * inTangent.w;
#endif

//-------------------------
Expand All @@ -64,4 +65,4 @@ void main(){
wNormal = inNormal;
#endif

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@ void main(){
wvLightPos.w = g_LightPosition.w;
vec4 lightColor = g_LightColor;

//--------------------------
// specific to normal maps:
//--------------------------
#if defined(NORMALMAP) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7) || defined(NORMALMAP_8) || defined(NORMALMAP_9) || defined(NORMALMAP_10) || defined(NORMALMAP_11)
vec3 wvTangent = normalize(g_NormalMatrix * inTangent.xyz);
vec3 wvBinormal = cross(wvNormal, wvTangent);

mat3 tbnMat = mat3(wvTangent, wvBinormal * inTangent.w,wvNormal);

vPosition = wvPosition * tbnMat;
vViewDir = viewDir * tbnMat;
//--------------------------
// specific to normal maps:
//--------------------------
#if defined(NORMALMAP) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7) || defined(NORMALMAP_8) || defined(NORMALMAP_9) || defined(NORMALMAP_10) || defined(NORMALMAP_11)
vec3 tbnNormal = normalize(wvNormal);
vec3 wvTangent = normalize(g_NormalMatrix * inTangent.xyz);
wvTangent = normalize(wvTangent - tbnNormal * dot(wvTangent, tbnNormal));
vec3 wvBinormal = normalize(cross(tbnNormal, wvTangent)) * inTangent.w;

mat3 tbnMat = mat3(wvTangent, wvBinormal, tbnNormal);

vPosition = wvPosition * tbnMat;
vViewDir = viewDir * tbnMat;

lightComputeDir(wvPosition, lightColor.w, wvLightPos, vLightDir, lightVec);
vLightDir.xyz = (vLightDir.xyz * tbnMat).xyz;
Expand All @@ -92,4 +94,4 @@ void main(){
wNormal = inNormal;
#endif

}
}
Loading