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 |      * The light color when rendering in multi pass mode | ||||||
|      * Type: vec4 |      * 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; |     String glslType; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -36,6 +36,7 @@ import com.jme3.math.*; | |||||||
| import com.jme3.renderer.Camera; | import com.jme3.renderer.Camera; | ||||||
| import com.jme3.renderer.RenderManager; | import com.jme3.renderer.RenderManager; | ||||||
| import com.jme3.system.Timer; | import com.jme3.system.Timer; | ||||||
|  | 
 | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
| @ -66,6 +67,7 @@ public class UniformBindingManager { | |||||||
|     private Matrix4f worldViewMatrix = new Matrix4f(); |     private Matrix4f worldViewMatrix = new Matrix4f(); | ||||||
|     private Matrix4f worldViewProjMatrix = new Matrix4f(); |     private Matrix4f worldViewProjMatrix = new Matrix4f(); | ||||||
|     private Matrix3f normalMatrix = new Matrix3f(); |     private Matrix3f normalMatrix = new Matrix3f(); | ||||||
|  |     private Matrix3f worldNormalMatrix = new Matrix3f(); | ||||||
|     private Matrix4f worldMatrixInv = new Matrix4f(); |     private Matrix4f worldMatrixInv = new Matrix4f(); | ||||||
|     private Matrix3f worldMatrixInvTrsp = new Matrix3f(); |     private Matrix3f worldMatrixInvTrsp = new Matrix3f(); | ||||||
|     private Matrix4f viewMatrixInv = new Matrix4f(); |     private Matrix4f viewMatrixInv = new Matrix4f(); | ||||||
| @ -114,6 +116,13 @@ public class UniformBindingManager { | |||||||
|                     normalMatrix.transposeLocal(); |                     normalMatrix.transposeLocal(); | ||||||
|                     u.setValue(VarType.Matrix3, normalMatrix); |                     u.setValue(VarType.Matrix3, normalMatrix); | ||||||
|                     break; |                     break; | ||||||
|  |                 case WorldNormalMatrix: | ||||||
|  |                     tempMatrix.set(worldMatrix); | ||||||
|  |                     tempMatrix.toRotationMatrix(worldNormalMatrix); | ||||||
|  |                     worldNormalMatrix.invertLocal(); | ||||||
|  |                     worldNormalMatrix.transposeLocal(); | ||||||
|  |                     u.setValue(VarType.Matrix3, worldNormalMatrix); | ||||||
|  |                     break; | ||||||
|                 case WorldViewProjectionMatrix: |                 case WorldViewProjectionMatrix: | ||||||
|                     worldViewProjMatrix.set(viewProjMatrix); |                     worldViewProjMatrix.set(viewProjMatrix); | ||||||
|                     worldViewProjMatrix.multLocal(worldMatrix); |                     worldViewProjMatrix.multLocal(worldMatrix); | ||||||
|  | |||||||
| @ -130,6 +130,7 @@ MaterialDef PBR Lighting { | |||||||
|             WorldViewProjectionMatrix |             WorldViewProjectionMatrix | ||||||
|             CameraPosition |             CameraPosition | ||||||
|             WorldMatrix |             WorldMatrix | ||||||
|  |             WorldNormalMatrix | ||||||
|             ViewProjectionMatrix |             ViewProjectionMatrix | ||||||
|             ViewMatrix |             ViewMatrix | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -25,6 +25,7 @@ uniform mat4 g_WorldViewMatrix; | |||||||
| uniform mat4 g_WorldViewProjectionMatrix; | uniform mat4 g_WorldViewProjectionMatrix; | ||||||
| uniform mat4 g_ViewProjectionMatrix; | uniform mat4 g_ViewProjectionMatrix; | ||||||
| uniform mat3 g_NormalMatrix; | uniform mat3 g_NormalMatrix; | ||||||
|  | uniform mat3 g_WorldNormalMatrix; | ||||||
| 
 | 
 | ||||||
| #if defined INSTANCING | #if defined INSTANCING | ||||||
| 
 | 
 | ||||||
| @ -101,7 +102,7 @@ vec3 TransformNormal(vec3 normal) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| vec3 TransformWorldNormal(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