Fixes normal lighting in world space for PBR
This commit is contained in:
		
							parent
							
								
									435f2d4d05
								
							
						
					
					
						commit
						fc8135412f
					
				| @ -195,7 +195,14 @@ public enum UniformBinding { | ||||
|      * The light color when rendering in multi pass mode | ||||
|      * Type: vec4 | ||||
|      */ | ||||
|     LightColor("vec4"); | ||||
|     LightColor("vec4"), | ||||
| 
 | ||||
|     /** | ||||
|      * The normal matrix in world space for World space lighting. The inverse transpose of the world matrix. | ||||
|      * Converts normals from model space to world space. | ||||
|      * Type: mat3 | ||||
|      */ | ||||
|     WorldNormalMatrix("mat3"); | ||||
|      | ||||
|     String glslType; | ||||
| 
 | ||||
|  | ||||
| @ -36,6 +36,7 @@ import com.jme3.math.*; | ||||
| import com.jme3.renderer.Camera; | ||||
| import com.jme3.renderer.RenderManager; | ||||
| import com.jme3.system.Timer; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| /** | ||||
| @ -66,6 +67,7 @@ public class UniformBindingManager { | ||||
|     private Matrix4f worldViewMatrix = new Matrix4f(); | ||||
|     private Matrix4f worldViewProjMatrix = new Matrix4f(); | ||||
|     private Matrix3f normalMatrix = new Matrix3f(); | ||||
|     private Matrix3f worldNormalMatrix = new Matrix3f(); | ||||
|     private Matrix4f worldMatrixInv = new Matrix4f(); | ||||
|     private Matrix3f worldMatrixInvTrsp = new Matrix3f(); | ||||
|     private Matrix4f viewMatrixInv = new Matrix4f(); | ||||
| @ -114,6 +116,13 @@ public class UniformBindingManager { | ||||
|                     normalMatrix.transposeLocal(); | ||||
|                     u.setValue(VarType.Matrix3, normalMatrix); | ||||
|                     break; | ||||
|                 case WorldNormalMatrix: | ||||
|                     tempMatrix.set(worldMatrix); | ||||
|                     tempMatrix.toRotationMatrix(worldNormalMatrix); | ||||
|                     worldNormalMatrix.invertLocal(); | ||||
|                     worldNormalMatrix.transposeLocal(); | ||||
|                     u.setValue(VarType.Matrix3, worldNormalMatrix); | ||||
|                     break; | ||||
|                 case WorldViewProjectionMatrix: | ||||
|                     worldViewProjMatrix.set(viewProjMatrix); | ||||
|                     worldViewProjMatrix.multLocal(worldMatrix); | ||||
|  | ||||
| @ -130,6 +130,7 @@ MaterialDef PBR Lighting { | ||||
|             WorldViewProjectionMatrix | ||||
|             CameraPosition | ||||
|             WorldMatrix | ||||
|             WorldNormalMatrix | ||||
|             ViewProjectionMatrix | ||||
|             ViewMatrix | ||||
|         } | ||||
|  | ||||
| @ -25,6 +25,7 @@ uniform mat4 g_WorldViewMatrix; | ||||
| uniform mat4 g_WorldViewProjectionMatrix; | ||||
| uniform mat4 g_ViewProjectionMatrix; | ||||
| uniform mat3 g_NormalMatrix; | ||||
| uniform mat3 g_WorldNormalMatrix; | ||||
| 
 | ||||
| #if defined INSTANCING | ||||
| 
 | ||||
| @ -101,7 +102,7 @@ vec3 TransformNormal(vec3 normal) { | ||||
| } | ||||
| 
 | ||||
| vec3 TransformWorldNormal(vec3 normal) { | ||||
|     return normalize((g_WorldMatrix * vec4(normal,0.0)).xyz); | ||||
|     return normalize(g_WorldNormalMatrix * normal); | ||||
| } | ||||
| 
 | ||||
|   | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user