RadiationManager() { sampler = CustomSampler.Create("RadiationUpdate"); }
void GenerateGaussianMips(CommandBuffer cmd, HDCamera hdCam) { RTHandle source; Vector2Int size = new Vector2Int(hdCam.actualWidth, hdCam.actualHeight); if (targetColorBuffer == TargetBuffer.Camera) { GetCameraBuffers(out source, out _); } else { GetCustomBuffers(out source, out _); } int dstMipWidth = Mathf.Max(1, size.x >> 1); int dstMipHeight = Mathf.Max(1, size.y >> 1); // Scale for downsample float scaleX = ((float)size.x / source.rt.width); float scaleY = ((float)size.y / source.rt.height); if (useMask) { // Save the non blurred color into a copy: cmd.CopyTexture(source, colorCopy); } // Downsample. using (new ProfilingSample(cmd, "Downsample", CustomSampler.Create("Downsample"))) { var downsampleProperties = new MaterialPropertyBlock(); downsampleProperties.SetTexture(ShaderID._BlitTexture, source); downsampleProperties.SetVector(ShaderID._BlitScaleBias, new Vector4(scaleX, scaleY, 0f, 0f)); downsampleProperties.SetFloat(ShaderID._BlitMipLevel, 0); CoreUtils.SetRenderTarget(cmd, downSampleBuffer, ClearFlag.None); cmd.SetViewport(new Rect(0, 0, dstMipWidth, dstMipHeight)); cmd.DrawProcedural(Matrix4x4.identity, HDUtils.GetBlitMaterial(source.rt.dimension), 1, MeshTopology.Triangles, 3, 1, downsampleProperties); } // Horizontal Blur using (new ProfilingSample(cmd, "H Blur", CustomSampler.Create("H Blur"))) { var hBlurProperties = new MaterialPropertyBlock(); CoreUtils.SetRenderTarget(cmd, blurBuffer, ClearFlag.None); hBlurProperties.SetFloat(ShaderID._Radius, radius / 4.0f); // The blur is 4 pixel wide in the shader hBlurProperties.SetTexture(ShaderID._Source, downSampleBuffer); // The blur is 4 pixel wide in the shader hBlurProperties.SetFloat(ShaderID._UVScale, 2); cmd.SetViewport(new Rect(0, 0, dstMipWidth, dstMipHeight)); CoreUtils.DrawFullScreen(cmd, blurMaterial, shaderPassId: 0, properties: hBlurProperties); // Do not forget the shaderPassId: ! or it won't work } // Copy back the result in the color buffer while doing a vertical blur using (new ProfilingSample(cmd, "V Blur + Copy back", CustomSampler.Create("V Blur + Copy back"))) { var vBlurProperties = new MaterialPropertyBlock(); // When we use a mask, we do the vertical blur into the downsampling buffer instead of the camera buffer // We need that because we're going to write to the color buffer and read from this blured buffer which we can't do // if they are in the same buffer CoreUtils.SetRenderTarget(cmd, (useMask) ? downSampleBuffer : source, ClearFlag.None); vBlurProperties.SetFloat(ShaderID._Radius, radius / 4.0f); // The blur is 4 pixel wide in the shader vBlurProperties.SetTexture(ShaderID._Source, blurBuffer); vBlurProperties.SetFloat(ShaderID._UVScale, (useMask) ? 2 : 1); CoreUtils.DrawFullScreen(cmd, blurMaterial, shaderPassId: 1, properties: vBlurProperties); } if (useMask) { using (new ProfilingSample(cmd, "Compose Mask Blur", CustomSampler.Create("Compose Mask Blur"))) { var compositingProperties = new MaterialPropertyBlock(); CoreUtils.SetRenderTarget(cmd, source, ClearFlag.None); compositingProperties.SetFloat(ShaderID._Radius, radius / 4.0f); // The blur is 4 pixel wide in the shader compositingProperties.SetTexture(ShaderID._Source, downSampleBuffer); compositingProperties.SetTexture(ShaderID._ColorBufferCopy, colorCopy); compositingProperties.SetTexture(ShaderID._Mask, maskBuffer); compositingProperties.SetTexture(ShaderID._MaskDepth, maskDepthBuffer); compositingProperties.SetFloat(ShaderID._InvertMask, invertMask ? 1 : 0); CoreUtils.DrawFullScreen(cmd, blurMaterial, shaderPassId: 2, properties: compositingProperties); } } }
/// <inheritdoc /> protected override void Awake() { base.Awake(); gestureSampler = CustomSampler.Create("[TouchScript] Screen Transform Gesture"); }
private void OnEnable() { m_CustomSampler = CustomSampler.Create("TEST_MARKER"); }
void GenerateGaussianMips(CommandBuffer cmd, HDCamera hdCam) { RTHandle source; // Retrieve the target buffer of the blur from the UI: if (targetColorBuffer == TargetBuffer.Camera) { GetCameraBuffers(out source, out _); } else { GetCustomBuffers(out source, out _); } // Save the non blurred color into a copy if the mask is enabled: if (useMask) { cmd.CopyTexture(source, colorCopy); } // Downsample using (new ProfilingSample(cmd, "Downsample", CustomSampler.Create("Downsample"))) { // This Blit will automatically downsample the color because our target buffer have been allocated in half resolution HDUtils.BlitCameraTexture(cmd, source, downSampleBuffer, 0); } // Horizontal Blur using (new ProfilingSample(cmd, "H Blur", CustomSampler.Create("H Blur"))) { var hBlurProperties = new MaterialPropertyBlock(); hBlurProperties.SetFloat(ShaderID._Radius, radius / 4.0f); // The blur is 4 pixel wide in the shader hBlurProperties.SetTexture(ShaderID._Source, downSampleBuffer); // The blur is 4 pixel wide in the shader SetViewPortSize(cmd, hBlurProperties, blurBuffer); HDUtils.DrawFullScreen(cmd, blurMaterial, blurBuffer, hBlurProperties, shaderPassId: 0); // Do not forget the shaderPassId: ! or it won't work } // Copy back the result in the color buffer while doing a vertical blur using (new ProfilingSample(cmd, "V Blur + Copy back", CustomSampler.Create("V Blur + Copy back"))) { var vBlurProperties = new MaterialPropertyBlock(); // When we use a mask, we do the vertical blur into the downsampling buffer instead of the camera buffer // We need that because we're going to write to the color buffer and read from this blured buffer which we can't do // if they are in the same buffer vBlurProperties.SetFloat(ShaderID._Radius, radius / 4.0f); // The blur is 4 pixel wide in the shader vBlurProperties.SetTexture(ShaderID._Source, blurBuffer); var targetBuffer = (useMask) ? downSampleBuffer : source; SetViewPortSize(cmd, vBlurProperties, targetBuffer); HDUtils.DrawFullScreen(cmd, blurMaterial, targetBuffer, vBlurProperties, shaderPassId: 1); // Do not forget the shaderPassId: ! or it won't work } if (useMask) { // Merge the non blur copy and the blurred version using the mask buffers using (new ProfilingSample(cmd, "Compose Mask Blur", CustomSampler.Create("Compose Mask Blur"))) { var compositingProperties = new MaterialPropertyBlock(); compositingProperties.SetFloat(ShaderID._Radius, radius / 4.0f); // The blur is 4 pixel wide in the shader compositingProperties.SetTexture(ShaderID._Source, downSampleBuffer); compositingProperties.SetTexture(ShaderID._ColorBufferCopy, colorCopy); compositingProperties.SetTexture(ShaderID._Mask, maskBuffer); compositingProperties.SetTexture(ShaderID._MaskDepth, maskDepthBuffer); compositingProperties.SetFloat(ShaderID._InvertMask, invertMask ? 1 : 0); SetViewPortSize(cmd, compositingProperties, source); HDUtils.DrawFullScreen(cmd, blurMaterial, source, compositingProperties, shaderPassId: 2); // Do not forget the shaderPassId: ! or it won't work } } }
/// <inheritdoc /> protected override void Awake() { base.Awake(); gestureSampler = CustomSampler.Create("[TouchScript] Release Gesture"); }
public DisposableStruct(CustomSampler customSampler) { _sampler = customSampler; _sampler.Begin(); }
// Update is called once per frame void FixedUpdate( ) { #region FrameSkip FrameCount++; // 最初の200フレームはロードで負荷がかかる bool isSlow = fps < 30.0f; if (isSlow //&& FrameCount > 30 ) { if (FrameCount % 15 == 0) { SkipCount++; //Debug.Log( $"TexEditor SkipAdd : {SkipCount} fps {fps} FrameCount {FrameCount}" ); } } if (FrameCount % SkipCount != 0) { return; } #endregion #if MOUSEDEBUG Vector3 screenPos = Input.mousePosition; Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPos); Debug.Log(worldPos); DrawTexByWorld(worldPos); #endif #if SCANLINE CustomSampler sampler = CustomSampler.Create("fillpoly"); CustomSampler setPixelSample = CustomSampler.Create("setPixelSample"); //"パスをピクセル空間に持っていく" // AddPointするときに持っていく -> AddPoint座標系が複雑になる // ここらで32倍 -> 2回Addしちゃうが大きく負荷はなかった if (IsFill) { sampler.Begin( ); var colorList = Path.FillPoly(WorldToPixel); //Path.StrokePath( WorldToPixel ); sampler.End( ); setPixelSample.Begin( ); #if NOOPE EditTex.SetPixels(BaseColor, 0); for (int i = 0; i < enumerable.Count; i++) { Scanline item = enumerable[i]; //Debug.Log( "itemW =" + item.W ); //var colorList = Enumerable.Range( 0 , item.W ).Select( i => Color.green ).ToArray(); int v = item.X + item.W; bool xInBound = 0 < item.X && v < Size; bool yInBound = 0 < item.Y && item.Y < Size; if (xInBound && yInBound) { EditTex.SetPixels(item.X, item.Y, item.W, 1, FillColor); } } //EditTex.SetPixels( BaseColor , 0 ); #else EditTex.SetPixels(colorList, 0); #endif setPixelSample.End( ); #else int height = EditTex.height; // 1の大きさになる for (int y = 0; y < height; y++) { int width = EditTex.width; for (int x = 0; x < width; x++) { var widOff = x / (float)width; var heiOff = y / (float)height; var localPos = new Vector3(widOff - 0.5f, heiOff - 0.5f, 0); var worldMat = transform.localToWorldMatrix; var worldPos = worldMat.MultiplyPoint(localPos); var drawColor = Color.green; if (Path.IsContain(worldPos)) { drawColor = Color.red; } TexDataList[x + height * y] = drawColor; } } EditTex.SetPixels(TexDataList); #endif EditTex.Apply( ); } else { EditTex.SetPixels(BaseColor); Path.StrokePathOCV(WorldToPixel, EditTex); } }
public DisposableStruct Sample(string samplerName) { return(new DisposableStruct(CustomSampler.Create(samplerName))); }
/// <summary> /// CustomSampler を生成してサンプリングを開始します /// </summary> public CustomSamplerScope(string name, UnityEngine.Object targetObject) { m_sampler = CustomSampler.Create(name); m_sampler.Begin(targetObject); }
//================================================================================ // 関数 //================================================================================ /// <summary> /// CustomSampler を生成してサンプリングを開始します /// </summary> public CustomSamplerScope(string name) { m_sampler = CustomSampler.Create(name); m_sampler.Begin(); }
//========================================================================================= /// <summary> /// 初期設定 /// </summary> public override void Create() { // 拘束の作成 // ※この並び順が実行順番となります。 // 移動制限 //ClampDistance = new ClampDistanceConstraint(); //constraints.Add(ClampDistance); // コリジョン ColliderExtrusion = new ColliderExtrusionConstraint(); constraints.Add(ColliderExtrusion); Penetration = new PenetrationConstraint(); constraints.Add(Penetration); Collision = new ColliderCollisionConstraint(); constraints.Add(Collision); // 移動制限 ClampDistance = new ClampDistanceConstraint(); constraints.Add(ClampDistance); //ClampDistance2 = new ClampDistance2Constraint(); //constraints.Add(ClampDistance2); //Penatration = new ColliderPenetrationConstraint(); //constraints.Add(Penatration); // コリジョン //EdgeCollision = new EdgeCollisionConstraint(); //constraints.Add(EdgeCollision); //Penetration = new PenetrationConstraint(); //constraints.Add(Penetration); //Collision = new ColliderCollisionConstraint(); //constraints.Add(Collision); // 移動制限 //Penetration = new ColliderPenetrationConstraint(); // コリジョンの前はだめ //constraints.Add(Penetration); //ClampDistance = new ClampDistanceConstraint(); //constraints.Add(ClampDistance); //Penatration = new ColliderPenetrationConstraint(); //constraints.Add(Penatration); // 主なクロスシミュレーション Spring = new SpringConstraint(); constraints.Add(Spring); RestoreDistance = new RestoreDistanceConstraint(); constraints.Add(RestoreDistance); RestoreRotation = new RestoreRotationConstraint(); constraints.Add(RestoreRotation); // コリジョン //EdgeCollision = new EdgeCollisionConstraint(); //constraints.Add(EdgeCollision); //Penetration = new PenetrationConstraint(); //constraints.Add(Penetration); //Collision = new ColliderCollisionConstraint(); //constraints.Add(Collision); //Penetration = new PenetrationConstraint(); //constraints.Add(Penetration); // 形状維持 TriangleBend = new TriangleBendConstraint(); constraints.Add(TriangleBend); //Volume = new VolumeConstraint(); //constraints.Add(Volume); // 移動制限2 //Penetration = new ColliderPenetrationConstraint(); //constraints.Add(Penetration); ClampPosition = new ClampPositionConstraint(); constraints.Add(ClampPosition); ClampRotation = new ClampRotationConstraint(); constraints.Add(ClampRotation); // コリジョン2 //AfterCollision = new ColliderAfterCollisionConstraint(); //constraints.Add(AfterCollision); //EdgeCollision = new EdgeCollisionConstraint(); //constraints.Add(EdgeCollision); //Collision = new ColliderCollisionConstraint(); //constraints.Add(Collision); //Penetration = new PenetrationConstraint(); //constraints.Add(Penetration); foreach (var con in constraints) { con.Init(manager); } // ワーカーの作成 // ※この並び順は変更してはいけません。 RenderMeshWorker = new RenderMeshWorker(); workers.Add(RenderMeshWorker); VirtualMeshWorker = new VirtualMeshWorker(); workers.Add(VirtualMeshWorker); MeshParticleWorker = new MeshParticleWorker(); workers.Add(MeshParticleWorker); SpringMeshWorker = new SpringMeshWorker(); workers.Add(SpringMeshWorker); AdjustRotationWorker = new AdjustRotationWorker(); workers.Add(AdjustRotationWorker); LineWorker = new LineWorker(); workers.Add(LineWorker); TriangleWorker = new TriangleWorker(); workers.Add(TriangleWorker); //BaseSkinningWorker = new BaseSkinningWorker(); //workers.Add(BaseSkinningWorker); foreach (var worker in workers) { worker.Init(manager); } // プロファイラ用 SamplerWriteMesh = CustomSampler.Create("WriteMesh"); }
// TODO: probably need to spam some unit tests on this to make sure we get all the edge cases correct for top-level get and set // TODO: add a benchmarking project to test other performance optimisations private void Start() { _isSolidAtChecksCustomSampler = CustomSampler.Create("IsSolidAt checks"); _marchingCubesSwitchCustomSampler = CustomSampler.Create("MarchingCubesSwitch"); StartCoroutine(GenerateMap()); }