public async Task <GActor> CreateActor(Editor.PlantableItemCreateActorParam param) { await EngineNS.Thread.AsyncDummyClass.DummyFunc(); var rc = EngineNS.CEngine.Instance.RenderContext; var actor = new EngineNS.GamePlay.Actor.GActor(); actor.ActorId = Guid.NewGuid(); var placement = new EngineNS.GamePlay.Component.GPlacementComponent(); actor.Placement = placement; placement.Location = param.Location; placement.Rotation = EngineNS.Quaternion.GetQuaternion(Vector3.UnitZ, -Vector3.UnitY); actor.SpecialName = "SunActor"; var initializer = new GDirLightComponentInitializer(); initializer.SpecialName = "LightData"; await SetInitializer(rc, actor, actor, initializer); this.View = param.View; var meshComp = new EngineNS.GamePlay.Component.GMeshComponent(); var meshCompInit = new EngineNS.GamePlay.Component.GMeshComponent.GMeshComponentInitializer(); meshCompInit.SpecialName = "VisualMesh"; meshCompInit.MeshName = EngineNS.RName.GetRName("editor/sun.gms", EngineNS.RName.enRNameType.Game); var test = meshComp.SetInitializer(rc, actor, actor, meshCompInit); actor.AddComponent(meshComp); actor.AddComponent(this); return(actor); }
//public static Profiler.TimeScope ScopeAffectLightsStatic = Profiler.TimeScopeManager.GetTimeScope(typeof(GSceneGraph), "GetAffectLights.Static", Profiler.TimeScope.EProfileFlag.Windows); //public static Profiler.TimeScope ScopeAffectLightsDynamic = Profiler.TimeScopeManager.GetTimeScope(typeof(GSceneGraph), "GetAffectLights.Dynamic", Profiler.TimeScope.EProfileFlag.Windows); //public static Profiler.TimeScope ScopeAffectLightsSetCBuffer = Profiler.TimeScopeManager.GetTimeScope(typeof(GSceneGraph), "GetAffectLights.CBuffer", Profiler.TimeScope.EProfileFlag.Windows); public void GetAffectLights(Graphics.View.CGfxSceneView view, Actor.GActor actor, bool bSet2CBuffer) { if (view == null) { return; } //ScopeAffectLightsStatic.Begin(); var staticlights = actor.StaticLights; if (actor.StaticObject) { if (actor.PointLightsSerialId != actor.Scene.PointLightsSerialId) { staticlights.Clear(); for (int i = 0; i < PointLights.Count; i++) { if (PointLights[i] == null) { continue; } if (PointLights[i].Host.StaticObject == false) { continue; } float factor = PointLights[i].GetPointLightEffectFactor(actor); if (factor < 0) { continue; } TryAddLight(staticlights, PointLights[i], factor); } actor.PointLightsSerialId = actor.Scene.PointLightsSerialId; } } else { staticlights.Clear(); } var effectLights = actor.AffectLights; effectLights.Clear(); if (staticlights.Count > 0) { //effectLights.AddRange(staticlights);//不能这样操作,查看List源代码,这里会有一次new T[]的操作,导致GC,Add因为Capacity足够反而不会 for (int i = 0; i < staticlights.Count; i++) { effectLights.Add(staticlights[i]); } } //ScopeAffectLightsStatic.End(); if (actor.StaticObject) { //ScopeAffectLightsStatic.Begin(); for (int i = 0; i < DynPointLights.Count; i++) { if (DynPointLights[i] == null) { continue; } float factor = DynPointLights[i].GetPointLightEffectFactor(actor); if (factor < 0) { continue; } TryAddLight(effectLights, DynPointLights[i], factor); } //ScopeAffectLightsStatic.End(); } else { //ScopeAffectLightsDynamic.Begin(); for (int i = 0; i < PointLights.Count; i++) { if (PointLights[i] == null) { continue; } float factor = PointLights[i].GetPointLightEffectFactor(actor); if (factor < 0) { continue; } TryAddLight(effectLights, PointLights[i], factor); } //ScopeAffectLightsDynamic.End(); } if (bSet2CBuffer) { //ScopeAffectLightsSetCBuffer.Begin(); SetMeshAffectLights(view, actor); //ScopeAffectLightsSetCBuffer.End(); } }
public void SetMeshAffectLights(Graphics.View.CGfxSceneView view, Actor.GActor actor) { actor.VisitChildComponents(mOnVisitComponent_SetPointLights, view); }
public void DrawScene(CRenderContext rc, CCommandList cmd, Graphics.CGfxCamera Camera, Graphics.View.CGfxSceneView view) { if (EnableDraw == false) { return; } if (mNeedUpdateGpuBuffer) { mNeedUpdateGpuBuffer = false; UpdateGpuBuffer(rc, cmd, Camera); } var program = mPass.Effect.ShaderProgram; if (UseComputeShader == false) { UpdateIndexBufferCPU(cmd, Camera); } else { ComputeDispatch(rc, cmd, Camera); } if (UseVTF) { CTextureBindInfo tbInfo = new CTextureBindInfo(); if (program.FindTextureBindInfo(null, "gVertexTexture", ref tbInfo)) { mPass.ShaderResources.VSBindTexture(tbInfo.VSBindPoint, mVertexTextureView); } if (program.FindTextureBindInfo(null, "gInstanceDataTexture", ref tbInfo)) { mPass.ShaderResources.VSBindTexture(tbInfo.VSBindPoint, mInstanceDataTextureView); } var spInfo = new CSamplerBindInfo(); if (program.FindSamplerBindInfo(null, "Samp_gVertexTexture", ref spInfo)) { mPass.ShaderSamplerBinder.VSBindSampler(spInfo.VSBindPoint, mSamplerState); } if (program.FindSamplerBindInfo(null, "Samp_gInstanceDataTexture", ref spInfo)) { mPass.ShaderSamplerBinder.VSBindSampler(spInfo.VSBindPoint, mSamplerState); } } else { //CTextureBindInfo tbInfo = new CTextureBindInfo(); //if(program.FindTextureBindInfo(null, "AllVertexArray", ref tbInfo)) //{ // mPass.ShaderResources.VSBindTexture(tbInfo.VSBindPoint, mAllVertexSRV); //} //if (program.FindTextureBindInfo(null, "MeshInstanceArray", ref tbInfo)) //{ // mPass.ShaderResources.VSBindTexture(tbInfo.VSBindPoint, mMeshInstanceSRV); //} mPass.ShaderResources.VSBindTexture(14, mAllVertexSRV); mPass.ShaderResources.VSBindTexture(13, mMeshInstanceSRV); } CConstantBufferDesc cbInfo = new CConstantBufferDesc(); if (mCBMeshBatch != null && program.GetCBufferDesc(program.FindCBuffer("cbMeshBatch"), ref cbInfo)) { mPass.BindCBufferVS(cbInfo.VSBindPoint, mCBMeshBatch); } mPass.ViewPort = Camera.SceneView.Viewport; mPass.BindCBuffer(mPass.Effect.ShaderProgram, mPass.Effect.CacheData.CBID_Camera, Camera.CBuffer); if (view != null) { mPass.BindCBuffer(mPass.Effect.ShaderProgram, mPass.Effect.CacheData.CBID_View, view.SceneViewCB); } //mPass.ViewPort = view.Viewport; if (UseComputeShader == false) { mPass.AttachIndexBuffer = mCpuDrawIndexBuffer; var dpDesc = new CDrawPrimitiveDesc(); dpDesc.SetDefault(); dpDesc.NumPrimitives = mDrawArgs.IndexCountPerInstance / 3; mPass.GeometryMesh.SetAtom(0, 0, ref dpDesc); } else { mPass.AttachIndexBuffer = mDrawIndexBuffer; mPass.SetIndirectDraw(bufferIndirectDrawArgs, 0); } cmd.PushPass(mPass); }