void OnRenderObject() { if (!_isInit || !_renderMat) { return; } _renderMat.SetMatrix("_LocalToWorldMatrix", transform.localToWorldMatrix); _renderMat.SetVector("_CameraPosition", Camera.current.transform.position); if (_drawMassParticle) { _renderMat.SetFloat("_ParticleSize", _particleSize); _renderMat.SetColor("_Color", _massParticleColor); _renderMat.SetTexture("_PositionTex", _clothSim.GetPositionBuffer()); _renderMat.SetPass(0); Graphics.DrawProcedural(MeshTopology.Points, _clothSim.GetClothResolution().x *_clothSim.GetClothResolution().y); } if (_drawGrid) { _renderMat.SetColor("_Color", _gridColor); _renderMat.SetTexture("_PositionTex", _clothSim.GetPositionBuffer()); _renderMat.SetBuffer("_SpringIdsBuffer", _gridBuffer); _renderMat.SetPass(1); Graphics.DrawProcedural(MeshTopology.Points, _gridBuffer.count); } if (_drawGridDiagonal) { _renderMat.SetColor("_Color", _gridDiagonalColor); _renderMat.SetTexture("_PositionTex", _clothSim.GetPositionBuffer()); _renderMat.SetBuffer("_SpringIdsBuffer", _gridDiagonalBuffer); _renderMat.SetPass(1); Graphics.DrawProcedural(MeshTopology.Points, _gridDiagonalBuffer.count); } if (_drawGridDiagonalAlternate) { _renderMat.SetColor("_Color", _gridDiagonalAlternateColor); _renderMat.SetTexture("_PositionTex", _clothSim.GetPositionBuffer()); _renderMat.SetBuffer("_SpringIdsBuffer", _gridDiagonalAlternateBuffer); _renderMat.SetPass(1); Graphics.DrawProcedural(MeshTopology.Points, _gridDiagonalAlternateBuffer.count); } }
// 初期化 void Init() { // 初期化済みでなければ if (!_isInit) { // 参照を取得 if (_clothSim == null) { _clothSim = GetComponent <GPUClothSimulation>(); } if (_clothSim != null && _clothSim.IsInit) { // メッシュを生成 GenerateMesh(); // メッシュ描画のためのマテリアルをMeshRendererのセット _meshRenderer.material = MeshMat; MeshMat.SetTexture("_PositionTex", _clothSim.GetPositionBuffer()); MeshMat.SetTexture("_NormalTex", _clothSim.GetNormalBuffer()); // 初期化完了のフラグをセット _isInit = true; } } }