public override bool PreAddToRenderState( TargetRenderState targetRenderState, Pass srcPass, Pass dstPass ) { TextureUnitState textureUnit; //Create the mask texture unit. textureUnit = dstPass.CreateTextureUnitState(); textureUnit.SetTextureName( this.maskMapTextureName ); this.maskMapSamplerIndex = dstPass.TextureUnitStatesCount - 1; //Create the reflection texture unit. textureUnit = dstPass.CreateTextureUnitState(); if ( this.reflectionMapType == TextureType.TwoD ) { textureUnit.SetTextureName( this.reflectionMapTextureName ); } else { textureUnit.SetCubicTextureName( this.reflectionMapTextureName, true ); } this.reflectionMapSamplerIndex = dstPass.TextureUnitStatesCount - 1; return true; }
protected void InitTextureLighting() { if ( targetRenderSystem.Capabilities.TextureUnitCount < 2 ) LogManager.Instance.Write( "--WARNING--At least 2 available texture units are required for BSP dynamic lighting!" ); Texture texLight = TextureLight.CreateTexture(); textureLightMaterial = (Material)MaterialManager.Instance.GetByName( "Axiom/BspTextureLightMaterial" ); if ( textureLightMaterial == null ) { textureLightMaterial = (Material)MaterialManager.Instance.Create( "Axiom/BspTextureLightMaterial", ResourceGroupManager.DefaultResourceGroupName ); textureLightPass = textureLightMaterial.GetTechnique( 0 ).GetPass( 0 ); // the texture light TextureUnitState tex = textureLightPass.CreateTextureUnitState( texLight.Name ); tex.SetColorOperation( LayerBlendOperation.Modulate ); tex.ColorBlendMode.source2 = LayerBlendSource.Diffuse; tex.SetAlphaOperation( LayerBlendOperationEx.Modulate ); tex.AlphaBlendMode.source2 = LayerBlendSource.Diffuse; tex.TextureCoordSet = 2; tex.SetTextureAddressingMode( TextureAddressing.Clamp ); // The geometry texture without lightmap. Use the light texture on this // pass, the appropriate texture will be rendered at RenderTextureLighting tex = textureLightPass.CreateTextureUnitState( texLight.Name ); tex.SetColorOperation( LayerBlendOperation.Modulate ); tex.SetAlphaOperation( LayerBlendOperationEx.Modulate ); tex.SetTextureAddressingMode( TextureAddressing.Wrap ); textureLightPass.SetSceneBlending( SceneBlendType.TransparentAlpha ); textureLightMaterial.CullingMode = CullingMode.None; textureLightMaterial.Lighting = false; } else { textureLightPass = textureLightMaterial.GetTechnique( 0 ).GetPass( 0 ); } }
public override bool PreAddToRenderState( TargetRenderState targetRenderState, Pass srcPass, Pass dstPass ) { if ( srcPass.LightingEnabled == false ) { return false; } var lightCount = new int[3]; targetRenderState.GetLightCount( out lightCount ); TextureUnitState normalMapTexture = dstPass.CreateTextureUnitState(); normalMapTexture.SetTextureName( this.normalMapTextureName ); normalMapTexture.SetTextureFiltering( this.normalMapMinFilter, this.normalMapMagFilter, this.normalMapMipfilter ); normalMapTexture.TextureAnisotropy = (int)this.normalMapAnisotropy; normalMapTexture.TextureMipmapBias = this.normalMapMipBias; this.normalMapSamplerIndex = dstPass.TextureUnitStatesCount - 1; TrackVertexColorType = ( srcPass.VertexColorTracking ); if ( srcPass.Shininess > 0 && srcPass.Specular != ColorEx.Black ) { SpecularEnable = true; } else { SpecularEnable = false; } //Case this pass should run once per light(s) if ( srcPass.IteratePerLight ) { //This is the preferred case -> only one type of light is handled if ( srcPass.RunOnlyOncePerLightType ) { if ( srcPass.OnlyLightType == LightType.Point ) { lightCount[ 0 ] = srcPass.LightsPerIteration; lightCount[ 1 ] = 0; lightCount[ 2 ] = 0; } else if ( srcPass.OnlyLightType == LightType.Directional ) { lightCount[ 0 ] = 0; lightCount[ 1 ] = srcPass.LightsPerIteration; lightCount[ 2 ] = 0; } else if ( srcPass.OnlyLightType == LightType.Spotlight ) { lightCount[ 0 ] = 0; lightCount[ 1 ] = 0; lightCount[ 2 ] = srcPass.LightsPerIteration; } } //This is wors case -> all light types epected to be handled. //Can not handle this request in efficient way - throw an exception else { throw new AxiomException( "Using iterative lighting method with RT Shader System requires specifying explicit light type." ); } } SetLightCount( lightCount ); return true; }
private void InitShadowReceiverPass() { Material matShadRec = MaterialManager.Instance.GetByName(TEXTURE_SHADOW_RECEIVER_MATERIAL); if (matShadRec == null) { matShadRec = (Material) MaterialManager.Instance.Create(TEXTURE_SHADOW_RECEIVER_MATERIAL); shadowReceiverPass = matShadRec.GetTechnique(0).GetPass(0); shadowReceiverPass.SetSceneBlending(SceneBlendFactor.DestColor, SceneBlendFactor.Zero); // No lighting, one texture unit // everything else will be bound as needed during the receiver pass shadowReceiverPass.LightingEnabled = false; TextureUnitState t = shadowReceiverPass.CreateTextureUnitState(); t.TextureAddressing = TextureAddressing.Clamp; shadowReceiverPass.DepthBias = 1; } else { shadowReceiverPass = matShadRec.GetTechnique(0).GetPass(0); } }
private void InitShadowModulativePass() { Material matModStencil = MaterialManager.Instance.GetByName(STENCIL_SHADOW_MODULATIVE_MATERIAL); if(matModStencil == null) { // Create matModStencil = (Material)MaterialManager.Instance.Create(STENCIL_SHADOW_MODULATIVE_MATERIAL); shadowModulativePass = matModStencil.GetTechnique(0).GetPass(0); shadowModulativePass.SetSceneBlending(SceneBlendFactor.DestColor, SceneBlendFactor.Zero); shadowModulativePass.LightingEnabled = false; shadowModulativePass.DepthWrite = false; shadowModulativePass.DepthCheck = false; TextureUnitState t = shadowModulativePass.CreateTextureUnitState(); t.SetColorOperationEx( LayerBlendOperationEx.Modulate, LayerBlendSource.Manual, LayerBlendSource.Current, shadowColor); } else { shadowModulativePass = matModStencil.GetTechnique(0).GetPass(0); } }
private void InitShadowDebugPass() { Material matDebug = MaterialManager.Instance.GetByName(SHADOW_VOLUMES_MATERIAL); if(matDebug == null) { // Create matDebug = (Material)MaterialManager.Instance.Create(SHADOW_VOLUMES_MATERIAL); shadowDebugPass = matDebug.GetTechnique(0).GetPass(0); shadowDebugPass.SetSceneBlending(SceneBlendType.Add); shadowDebugPass.LightingEnabled = false; shadowDebugPass.DepthWrite = false; TextureUnitState t = shadowDebugPass.CreateTextureUnitState(); t.SetColorOperationEx( LayerBlendOperationEx.Modulate, LayerBlendSource.Manual, LayerBlendSource.Current, new ColorEx(0.7f, 0.0f, 0.2f)); shadowDebugPass.CullMode = CullingMode.None; if(targetRenderSystem.Caps.CheckCap(Capabilities.VertexPrograms)) { ShadowVolumeExtrudeProgram.Initialize(); // Enable the (infinite) point light extruder for now, just to get some params shadowDebugPass.SetVertexProgram( ShadowVolumeExtrudeProgram.GetProgramName(ShadowVolumeExtrudeProgram.Programs.PointLight)); infiniteExtrusionParams = shadowDebugPass.VertexProgramParameters; infiniteExtrusionParams.SetAutoConstant(0, AutoConstants.WorldViewProjMatrix); infiniteExtrusionParams.SetAutoConstant(4, AutoConstants.LightPositionObjectSpace); } matDebug.Compile(); } else { shadowDebugPass = matDebug.GetTechnique(0).GetPass(0); } }