/// <summary> /// Load constructor. /// </summary> /// <param name="info"></param> private OgreSceneManagerDefinition(LoadInfo info) { name = info.GetString(NAME); SceneTypeMask = info.GetValue <SceneType>(SCENE_TYPE); ShadowTechnique = info.GetValue <ShadowTechnique>(SHADOW_TECHNIQUE, OgrePlugin.ShadowTechnique.SHADOWTYPE_NONE); ogreRoot = Root.getSingleton(); }
public ShadowConfig(SceneManager scene) { this.scene = scene; GetShaderSupport(); shadowTechnique = ShadowTechnique.None; ParameterRegistry.RegisterSubsystemHandlers("Shadows", setShadowParameterHandler, getShadowParameterHandler); }
public BasicScene(MeshRenderer meshRend, Camera cam, ShadowTechnique shadTech) { meshRenderer = meshRend; camera = cam; shadowTech = shadTech; lights = new List <Light>(); sceneObjects = new HashSet <SceneObject>(); meshes = new HashSet <Mesh>(); materials = new HashSet <Material>(); }
public IEnumerator GetShadowVolumeRenderableIterator(ShadowTechnique shadowTechnique, Light light, HardwareIndexBuffer indexBuffer, bool extrudeVertices, float extrusionDistance, ulong flags) { Debug.Assert(indexBuffer != null, "Only external index buffers are supported right now"); Debug.Assert(indexBuffer.Type == IndexType.Size16, "Only 16-bit indexes supported for now"); // Calculate the object space light details var lightPos = light.GetAs4DVector(); var world2Obj = parentNode.FullTransform.Inverse(); lightPos = world2Obj * lightPos; // We need to search the edge list for silhouette edges if (this.edgeList == null) { throw new Exception("You enabled stencil shadows after the buid process! In " + "Region.GetShadowVolumeRenderableIterator"); } // Init shadow renderable list if required var init = this.shadowRenderables.Count == 0; RegionShadowRenderable esr = null; //bool updatedSharedGeomNormals = false; for (var i = 0; i < this.edgeList.EdgeGroups.Count; i++) { var group = (EdgeData.EdgeGroup) this.edgeList.EdgeGroups[i]; if (init) { // Create a new renderable, create a separate light cap if // we're using a vertex program (either for this model, or // for extruding the shadow volume) since otherwise we can // get depth-fighting on the light cap esr = new RegionShadowRenderable(this, indexBuffer, group.vertexData, this.vertexProgramInUse || !extrudeVertices); this.shadowRenderables.Add(esr); } else { esr = (RegionShadowRenderable)this.shadowRenderables[i]; } // Extrude vertices in software if required if (extrudeVertices) { ExtrudeVertices(esr.PositionBuffer, group.vertexData.vertexCount, lightPos, extrusionDistance); } } return((IEnumerator)this.shadowRenderables); }
public void SetTechnique(ShadowTechnique type) { switch (type) { case ShadowTechnique.PCF2x2: m_D3DEffect.Technique = m_createShadowTerm2x2; break; case ShadowTechnique.PCF3x3: m_D3DEffect.Technique = m_createShadowTerm3x3; break; case ShadowTechnique.PCF5x5: m_D3DEffect.Technique = m_createShadowTerm5x5; break; case ShadowTechnique.PCF7x7: m_D3DEffect.Technique = m_createShadowTerm7x7; break; case ShadowTechnique.GenerateShadow: m_D3DEffect.Technique = m_generateShadowMap; break; case ShadowTechnique.GenerateShadowForVoxels: m_D3DEffect.Technique = m_generateVoxelShadowMap; break; case ShadowTechnique.GenerateShadowInstanced: m_D3DEffect.Technique = m_generateShadowMapInstanced; break; case ShadowTechnique.GenerateShadowInstancedGeneric: m_D3DEffect.Technique = m_generateShadowMapInstancedGeneric; break; case ShadowTechnique.GenerateShadowForSkinned: m_D3DEffect.Technique = m_generateShadowSkinned; break; case ShadowTechnique.Clear: m_D3DEffect.Technique = m_clearTechnique; break; } }
protected void ValidateShadowTechnique() { switch (shadowTechnique) { case ShadowTechnique.None: break; case ShadowTechnique.Simple: break; case ShadowTechnique.Depth: // fall back to simple if we don't have shader model 2.0 if (maxFragmentProgramModel < 2) { shadowTechnique = ShadowTechnique.Simple; } break; } }
public IEnumerator GetShadowVolumeRenderableEnumerator( ShadowTechnique technique, Light light, HardwareIndexBuffer indexBuffer, float extrusionDistance, bool extrudeVertices ) { return GetShadowVolumeRenderableEnumerator( technique, light, indexBuffer, extrudeVertices, extrusionDistance, 0 ); }
public override IEnumerator GetShadowVolumeRenderableEnumerator(ShadowTechnique technique, Light light, HardwareIndexBuffer indexBuffer, bool extrudeVertices, float extrusionDistance, int flags) { return dummyList.GetEnumerator(); }
public IEnumerator GetShadowVolumeRenderableEnumerator(ShadowTechnique technique, Light light, HardwareIndexBuffer indexBuffer, float extrusionDistance, bool extrudeVertices) { return(GetShadowVolumeRenderableEnumerator(technique, light, indexBuffer, extrudeVertices, extrusionDistance, 0)); }
/// <summary> /// Gets an iterator over the renderables required to render the shadow volume. /// </summary> /// <remarks> /// Shadowable geometry should ideally be designed such that there is only one /// ShadowRenderable required to render the the shadow; however this is not a necessary /// limitation and it can be exceeded if required. /// </remarks> /// <param name="technique">The technique being used to generate the shadow.</param> /// <param name="light">The light to generate the shadow from.</param> /// <param name="indexBuffer">The index buffer to build the renderables into, /// the current contents are assumed to be disposable.</param> /// <param name="extrudeVertices">If true, this means this class should extrude /// the vertices of the back of the volume in software. If false, it /// will not be done (a vertex program is assumed).</param> /// <param name="extrusionDistance"></param> /// <param name="flags">Technique-specific flags, see <see cref="ShadowRenderableFlags"/></param> /// <returns>An iterator that will allow iteration over all renderables for the full shadow volume.</returns> public abstract IEnumerator GetShadowVolumeRenderableEnumerator( ShadowTechnique technique, Light light, HardwareIndexBuffer indexBuffer, bool extrudeVertices, float extrusionDistance, int flags );
/// <summary> /// Gets an iterator over the renderables required to render the shadow volume. /// </summary> /// <remarks> /// Shadowable geometry should ideally be designed such that there is only one /// ShadowRenderable required to render the the shadow; however this is not a necessary /// limitation and it can be exceeded if required. /// </remarks> /// <param name="technique">The technique being used to generate the shadow.</param> /// <param name="light">The light to generate the shadow from.</param> /// <param name="indexBuffer">The index buffer to build the renderables into, /// the current contents are assumed to be disposable.</param> /// <param name="extrudeVertices">If true, this means this class should extrude /// the vertices of the back of the volume in software. If false, it /// will not be done (a vertex program is assumed).</param> /// <param name="flags">Technique-specific flags, see <see cref="ShadowRenderableFlags"/></param> /// <returns>An iterator that will allow iteration over all renderables for the full shadow volume.</returns> public abstract IEnumerator GetShadowVolumeRenderableEnumerator(ShadowTechnique technique, Light light, HardwareIndexBuffer indexBuffer, bool extrudeVertices, float extrusionDistance, int flags);
public BasicScene(MeshRenderer meshRend, Camera cam, Light light, ShadowTechnique shadTech) : this(meshRend, cam, shadTech) { AddLight(light); }
private static extern void SceneManager_setShadowTechnique(IntPtr ogreSceneManager, ShadowTechnique technique);
public void setShadowTechnique(ShadowTechnique technique) { SceneManager_setShadowTechnique(ogreSceneManager, technique); }
public SceneManager( string name ) : base() { this.cameraList = new CameraCollection(); this.sceneNodeList = new SceneNodeCollection(); this.animationList = new AnimationCollection(); this.animationStateList = new AnimationStateSet(); this.regionList = new List<StaticGeometry.Region>(); this.shadowCasterQueryListener = new ShadowCasterSceneQueryListener( this ); // create the root scene node this.rootSceneNode = new SceneNode( this, "Root" ); this.rootSceneNode.SetAsRootNode(); this.defaultRootNode = this.rootSceneNode; this.name = name; // default to no fog this.fogMode = FogMode.None; // no shadows by default this.shadowTechnique = ShadowTechnique.None; // setup default shadow camera setup this._defaultShadowCameraSetup = new DefaultShadowCameraSetup(); this.illuminationStage = IlluminationRenderStage.None; this.renderingNoShadowQueue = false; this.renderingMainGroup = false; this.shadowColor.a = this.shadowColor.r = this.shadowColor.g = this.shadowColor.b = 0.25f; this.shadowDirLightExtrudeDist = 10000; this.shadowIndexBufferSize = 51200; this.shadowTextureOffset = 0.6f; this.shadowTextureFadeStart = 0.7f; this.shadowTextureFadeEnd = 0.9f; this.shadowTextureSize = 512; this.shadowTextureCount = 1; this.findVisibleObjects = true; this.suppressRenderStateChanges = false; this.suppressShadows = false; this.shadowUseInfiniteFarPlane = true; }
public override SWIGTYPE_p_Ogre__VectorIteratorT_std__vectorT_Ogre__ShadowRenderable_p_t_t getShadowVolumeRenderableIterator(ShadowTechnique shadowTechnique, Light light, HardwareIndexBufferPtr indexBuffer, SWIGTYPE_p_size_t indexBufferUsedSize, bool extrudeVertices, float extrusionDist) { SWIGTYPE_p_Ogre__VectorIteratorT_std__vectorT_Ogre__ShadowRenderable_p_t_t ret = new SWIGTYPE_p_Ogre__VectorIteratorT_std__vectorT_Ogre__ShadowRenderable_p_t_t(OgrePINVOKE.ManualObject_getShadowVolumeRenderableIterator__SWIG_1(swigCPtr, (int)shadowTechnique, Light.getCPtr(light), HardwareIndexBufferPtr.getCPtr(indexBuffer), SWIGTYPE_p_size_t.getCPtr(indexBufferUsedSize), extrudeVertices, extrusionDist), true); if (OgrePINVOKE.SWIGPendingException.Pending) { throw OgrePINVOKE.SWIGPendingException.Retrieve(); } return(ret); }
public IEnumerator GetShadowVolumeRenderableIterator( ShadowTechnique shadowTechnique, Light light, HardwareIndexBuffer indexBuffer, bool extrudeVertices, float extrusionDistance, ulong flags ) { Debug.Assert( indexBuffer != null, "Only external index buffers are supported right now" ); Debug.Assert( indexBuffer.Type == IndexType.Size16, "Only 16-bit indexes supported for now" ); // Calculate the object space light details var lightPos = light.GetAs4DVector(); var world2Obj = parentNode.FullTransform.Inverse(); lightPos = world2Obj*lightPos; // We need to search the edge list for silhouette edges if ( this.edgeList == null ) { throw new Exception( "You enabled stencil shadows after the buid process! In " + "Region.GetShadowVolumeRenderableIterator" ); } // Init shadow renderable list if required var init = this.shadowRenderables.Count == 0; RegionShadowRenderable esr = null; //bool updatedSharedGeomNormals = false; for ( var i = 0; i < this.edgeList.EdgeGroups.Count; i++ ) { var group = (EdgeData.EdgeGroup)this.edgeList.EdgeGroups[ i ]; if ( init ) { // Create a new renderable, create a separate light cap if // we're using a vertex program (either for this model, or // for extruding the shadow volume) since otherwise we can // get depth-fighting on the light cap esr = new RegionShadowRenderable( this, indexBuffer, group.vertexData, this.vertexProgramInUse || !extrudeVertices ); this.shadowRenderables.Add( esr ); } else { esr = (RegionShadowRenderable)this.shadowRenderables[ i ]; } // Extrude vertices in software if required if ( extrudeVertices ) { ExtrudeVertices( esr.PositionBuffer, group.vertexData.vertexCount, lightPos, extrusionDistance ); } } return (IEnumerator)this.shadowRenderables; }
public SceneManager(string smName) { this.smName = smName; cameraList = new Dictionary<string, Camera>(); //lightList = new LightList(); //entityList = new EntityList(); movableObjectCollectionMap = new Dictionary<string, Dictionary<string, MovableObject>>(); sceneNodeList = new Dictionary<string, SceneNode>(); //billboardSetList = new Dictionary<string, BillboardSet>(); animationList = new Dictionary<string, Animation>(); animationStateList = new AnimationStateSet(); regionList = new List<Region>(); // create the root scene node rootSceneNode = new SceneNode(this, "Root"); defaultRootNode = rootSceneNode; // default to no fog fogMode = FogMode.None; // no shadows by default shadowTechnique = ShadowTechnique.None; illuminationStage = IlluminationRenderStage.None; renderingNoShadowQueue = false; renderingMainGroup = false; shadowColor = new ColorEx(0.25f, 0.25f, 0.25f); shadowDirLightExtrudeDist = 10000; shadowIndexBufferSize = 51200; shadowTextureOffset = 0.6f; shadowTextureFadeStart = 0.7f; shadowTextureFadeEnd = 0.9f; shadowTextureSize = 512; shadowTextureConfigDirty = true; ShadowTextureCount = 1; findVisibleObjects = true; suppressRenderStateChanges = false; suppressShadows = false; shadowUseInfiniteFarPlane = true; shadowCasterRenderBackFaces = true; defaultShadowCameraSetup = new DefaultShadowCameraSetup(); }
public override IEnumerator GetShadowVolumeRenderableEnumerator(ShadowTechnique technique, Light light, HardwareIndexBuffer indexBuffer, bool extrudeVertices, float extrusionDistance, int flags) { return(dummyList.GetEnumerator()); }
public override IEnumerator GetShadowVolumeRenderableEnumerator( ShadowTechnique technique, Light light, HardwareIndexBuffer indexBuffer, bool extrudeVertices, float extrusionDistance, int flags ) { Debug.Assert( indexBuffer != null, "Only external index buffers are supported right now" ); Debug.Assert( indexBuffer.Type == IndexType.Size16, "Only 16-bit indexes supported for now" ); // Potentially delegate to LOD entity if ( this.meshLodIndex > 0 && this.mesh.IsLodManual ) { Debug.Assert( this.meshLodIndex - 1 < this.lodEntityList.Count, "No LOD EntityList - did you build the manual LODs after creating the entity?" ); var lodEnt = this.lodEntityList[ this.meshLodIndex - 1 ]; // index - 1 as we skip index 0 (original LOD) if ( HasSkeleton && lodEnt.HasSkeleton ) { // Copy the animation state set to lod entity, we assume the lod // entity only has a subset animation states CopyAnimationStateSubset( lodEnt.animationState, this.animationState ); } return lodEnt.GetShadowVolumeRenderableEnumerator( technique, light, indexBuffer, extrudeVertices, extrusionDistance, flags ); } // Prep mesh if required // NB This seems to result in memory corruptions, having problems // tracking them down. For now, ensure that shadows are enabled // before any entities are created if ( !this.mesh.IsPreparedForShadowVolumes ) { this.mesh.PrepareForShadowVolume(); // reset frame last updated to force update of buffers this.frameAnimationLastUpdated = 0; // re-prepare buffers PrepareTempBlendedBuffers(); } // Update any animation UpdateAnimation(); // Calculate the object space light details var lightPos = light.GetAs4DVector(); // Only use object-space light if we're not doing transforms // Since when animating the positions are already transformed into // world space so we need world space light position var isAnimated = HasSkeleton || this.mesh.HasVertexAnimation; if ( !isAnimated ) { var world2Obj = parentNode.FullTransform.Inverse(); lightPos = world2Obj*lightPos; } // We need to search the edge list for silhouette edges var edgeList = GetEdgeList(); // Init shadow renderable list if required var init = ( this.shadowRenderables.Count == 0 ); if ( init ) { this.shadowRenderables.Capacity = edgeList.edgeGroups.Count; } var updatedSharedGeomNormals = false; EntityShadowRenderable esr = null; EdgeData.EdgeGroup egi; // note: using capacity for the loop since no items are in the list yet. // capacity is set to how large the collection will be in the end for ( var i = 0; i < this.shadowRenderables.Capacity; i++ ) { egi = (EdgeData.EdgeGroup)edgeList.edgeGroups[ i ]; var data = ( isAnimated ? FindBlendedVertexData( egi.vertexData ) : egi.vertexData ); if ( init ) { // Try to find corresponding SubEntity; this allows the // linkage of visibility between ShadowRenderable and SubEntity var subEntity = FindSubEntityForVertexData( egi.vertexData ); // Create a new renderable, create a separate light cap if // we're using hardware skinning since otherwise we get // depth-fighting on the light cap esr = new EntityShadowRenderable( this, indexBuffer, data, subEntity.VertexProgramInUse || !extrudeVertices, subEntity ); this.shadowRenderables.Add( esr ); } else { esr = (EntityShadowRenderable)this.shadowRenderables[ i ]; if ( HasSkeleton ) { // If we have a skeleton, we have no guarantee that the position // buffer we used last frame is the same one we used last frame // since a temporary buffer is requested each frame // therefore, we need to update the EntityShadowRenderable // with the current position buffer esr.RebindPositionBuffer( data, isAnimated ); } } // For animated entities we need to recalculate the face normals if ( isAnimated ) { if ( egi.vertexData != this.mesh.SharedVertexData || !updatedSharedGeomNormals ) { // recalculate face normals edgeList.UpdateFaceNormals( egi.vertexSet, esr.PositionBuffer ); // If we're not extruding in software we still need to update // the latter part of the buffer (the hardware extruded part) // with the latest animated positions if ( !extrudeVertices ) { var srcPtr = esr.PositionBuffer.Lock( BufferLocking.Normal ); var destPtr = srcPtr + ( egi.vertexData.vertexCount*12 ); // 12 = sizeof(float) * 3 Memory.Copy( srcPtr, destPtr, 12*egi.vertexData.vertexCount ); esr.PositionBuffer.Unlock(); } if ( egi.vertexData == this.mesh.SharedVertexData ) { updatedSharedGeomNormals = true; } } } // Extrude vertices in software if required if ( extrudeVertices ) { ExtrudeVertices( esr.PositionBuffer, egi.vertexData.vertexCount, lightPos, extrusionDistance ); } // Stop suppressing hardware update now, if we were esr.PositionBuffer.SuppressHardwareUpdate( false ); } // Calc triangle light facing UpdateEdgeListLightFacing( edgeList, lightPos ); // Generate indexes and update renderables GenerateShadowVolume( edgeList, indexBuffer, light, this.shadowRenderables, flags ); return this.shadowRenderables.GetEnumerator(); }
public RenderScene(Window window, TextureInfo reflectionTexture, ShaderProgram postVertProg, ShaderProgram bloomFragProg, ShaderProgram aoFragProg, ShaderProgram gaussBlurFragProg, ShaderProgram boxBlurFragProg, ShaderProgram compositionFragProg, Logger logger = null) { if (window == null) { throw new ArgumentNullException(nameof(window)); } if (reflectionTexture.Texture == null) { throw new ArgumentNullException(nameof(reflectionTexture)); } if (postVertProg == null) { throw new ArgumentNullException(nameof(postVertProg)); } if (bloomFragProg == null) { throw new ArgumentNullException(nameof(bloomFragProg)); } if (aoFragProg == null) { throw new ArgumentNullException(nameof(aoFragProg)); } if (gaussBlurFragProg == null) { throw new ArgumentNullException(nameof(gaussBlurFragProg)); } if (boxBlurFragProg == null) { throw new ArgumentNullException(nameof(boxBlurFragProg)); } if (compositionFragProg == null) { throw new ArgumentNullException(nameof(compositionFragProg)); } this.window = window; this.logger = logger; camera = new Camera(); //Create resources executor = new TransientExecutor(window.LogicalDevice, window.GraphicsFamilyIndex); memoryPool = new Memory.Pool(window.LogicalDevice, window.HostDevice, logger); stagingBuffer = new Memory.HostBuffer( window.LogicalDevice, memoryPool, BufferUsages.TransferSrc, size: ByteUtils.MegabyteToByte(16)); sceneDataBuffer = new Memory.HostBuffer( window.LogicalDevice, memoryPool, BufferUsages.UniformBuffer, size: SceneData.SIZE * window.SwapchainCount); inputManager = new ShaderInputManager(window.LogicalDevice, logger); //Create techniques gbufferTechnique = new GBufferTechnique(this, logger); shadowTechnique = new ShadowTechnique(this, logger); bloomTechnique = new BloomTechnique( gbufferTechnique, postVertProg, bloomFragProg, gaussBlurFragProg, this, logger); aoTechnique = new AmbientOcclusionTechnique( gbufferTechnique, postVertProg, aoFragProg, boxBlurFragProg, this, logger); deferredTechnique = new DeferredTechnique( gbufferTechnique, shadowTechnique, bloomTechnique, aoTechnique, reflectionTexture, postVertProg, compositionFragProg, this, logger); }