Changed the way indirect lighting is toggled on or of, there was silly problems with previous commit.
This commit is contained in:
		
							parent
							
								
									e438ad0928
								
							
						
					
					
						commit
						31d271d972
					
				| @ -760,6 +760,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { | ||||
|         lightData.setVector4Length(numLights * 3);//8 lights * max 3 | ||||
|         Uniform ambientColor = shader.getUniform("g_AmbientLightColor"); | ||||
|         Uniform lightProbeData = shader.getUniform("g_LightProbeData"); | ||||
|         lightProbeData.setVector4Length(1); | ||||
|         Uniform lightProbeIrrMap = shader.getUniform("g_IrradianceMap"); | ||||
|         Uniform lightProbePemMap = shader.getUniform("g_PrefEnvMap"); | ||||
|          | ||||
| @ -843,12 +844,11 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { | ||||
|                         break; | ||||
|                     case Probe: | ||||
|                         useIBL = true; | ||||
|                         technique.setUseIndirectLighting(true); | ||||
|                         endIndex++; | ||||
|                         LightProbe probe = (LightProbe)l; | ||||
|                         BoundingSphere s = (BoundingSphere)probe.getBounds(); | ||||
|                         tmpVec.set(probe.getPosition().x, probe.getPosition().y, probe.getPosition().z, 1f/s.getRadius()); | ||||
|                         lightProbeData.setValue(VarType.Vector4, tmpVec);                         | ||||
|                         BoundingSphere s = (BoundingSphere)probe.getBounds();                         | ||||
|                         lightProbeData.setVector4InArray(probe.getPosition().x, probe.getPosition().y, probe.getPosition().z, 1f/s.getRadius(), 0); | ||||
|                          | ||||
|                         //assigning new texture indexes if they have never been assigned. | ||||
|                         if( irrUnit == -1 ){ | ||||
|                             irrUnit = nextTexUnit++; | ||||
| @ -865,8 +865,9 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable { | ||||
|         } | ||||
|         vars.release(); | ||||
|          | ||||
|         if(!useIBL ){  | ||||
|             technique.setUseIndirectLighting(false);             | ||||
|         if(!useIBL ){             | ||||
|             //Disable IBL for this pass | ||||
|             lightProbeData.setVector4InArray(0,0,0,-1, 0); | ||||
|         } | ||||
|         //Padding of unsued buffer space | ||||
|         while(lightDataIndex < numLights * 3) { | ||||
|  | ||||
| @ -188,15 +188,6 @@ public class Technique /* implements Savable */ { | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     public void setUseIndirectLighting(boolean useIBL){ | ||||
|         if(useIBL){ | ||||
|             defines.set("INDIRECT_LIGHTING", VarType.Boolean, true); | ||||
|         }else{ | ||||
|             defines.remove("INDIRECT_LIGHTING"); | ||||
|         } | ||||
|         needReload = true; | ||||
|     } | ||||
| 
 | ||||
|     private void loadShader(AssetManager manager,EnumSet<Caps> rendererCaps) { | ||||
|          | ||||
|         ShaderKey key = new ShaderKey(getAllDefines(),def.getShaderProgramLanguages(),def.getShaderProgramNames()); | ||||
|  | ||||
| @ -23,7 +23,7 @@ varying vec3 wPosition; | ||||
| //  uniform sampler2D m_IntegrateBRDF; | ||||
|   uniform samplerCube g_PrefEnvMap; | ||||
|   uniform samplerCube g_IrradianceMap; | ||||
|   uniform vec4 g_ProbeData; | ||||
|   uniform vec4 g_LightProbeData; | ||||
| //#endif | ||||
| 
 | ||||
| #ifdef BASECOLORMAP | ||||
| @ -202,28 +202,26 @@ void main(){ | ||||
|         gl_FragColor.rgb += directLighting * fallOff; | ||||
|     } | ||||
| 
 | ||||
|     #ifdef INDIRECT_LIGHTING | ||||
|         vec3 rv = reflect(-viewDir.xyz, normal.xyz); | ||||
|         //prallax fix for spherical bounds. | ||||
|         rv = g_ProbeData.w * (wPosition - g_ProbeData.xyz) +rv; | ||||
|         | ||||
|          //horizon fade from http://marmosetco.tumblr.com/post/81245981087 | ||||
|         float horiz = dot(rv, wNormal.xyz); | ||||
|         float horizFadePower= 1.0 - Roughness; | ||||
|         horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 ); | ||||
|         horiz *= horiz; | ||||
|          | ||||
|         vec3 indirectDiffuse = vec3(0.0); | ||||
|         vec3 indirectSpecular = vec3(0.0);     | ||||
|         indirectDiffuse = textureCube(g_IrradianceMap, rv.xyz).rgb * albedo.rgb; | ||||
|          | ||||
|         indirectSpecular = ApproximateSpecularIBLPolynomial(g_PrefEnvMap, specularColor.rgb, Roughness, ndotv, rv.xyz); | ||||
|         indirectSpecular *= vec3(horiz); | ||||
|     vec3 rv = reflect(-viewDir.xyz, normal.xyz); | ||||
|     //prallax fix for spherical bounds. | ||||
|     rv = g_LightProbeData.w * (wPosition - g_LightProbeData.xyz) +rv; | ||||
| 
 | ||||
|         vec3 indirectLighting =  indirectDiffuse + indirectSpecular; | ||||
|          | ||||
|         gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting ;         | ||||
|     #endif | ||||
|      //horizon fade from http://marmosetco.tumblr.com/post/81245981087 | ||||
|     float horiz = dot(rv, wNormal.xyz); | ||||
|     float horizFadePower= 1.0 - Roughness; | ||||
|     horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 ); | ||||
|     horiz *= horiz; | ||||
| 
 | ||||
|     vec3 indirectDiffuse = vec3(0.0); | ||||
|     vec3 indirectSpecular = vec3(0.0);     | ||||
|     indirectDiffuse = textureCube(g_IrradianceMap, rv.xyz).rgb * albedo.rgb; | ||||
| 
 | ||||
|     indirectSpecular = ApproximateSpecularIBLPolynomial(g_PrefEnvMap, specularColor.rgb, Roughness, ndotv, rv.xyz); | ||||
|     indirectSpecular *= vec3(horiz); | ||||
| 
 | ||||
|     vec3 indirectLighting =  indirectDiffuse + indirectSpecular; | ||||
| 
 | ||||
|     gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting * step( 0.0, g_LightProbeData.w);         | ||||
|   | ||||
|     #if defined(EMISSIVE) || defined (EMISSIVEMAP) | ||||
|         #ifdef EMISSIVEMAP | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user