protected void Awake()
 {
     // Retrieve with provider
     provider              = gameObject.GetComponent <PointCloudProvider>();
     drawBuffer            = Material.Instantiate(drawBuffer);
     vertexBufferGenerator = ComputeShader.Instantiate(vertexBufferGenerator);
 }
예제 #2
0
 public PaintPointCloudShaderAPI(Vector3 canvasWorldPosition)
 {
     //Set up shader
     paintShader = ComputeShader.Instantiate(Resources.Load <ComputeShader>("Shaders/PaintPointCloudShader"));
     paintShader.SetFloat("BrushAmount", 0);
     paintShader.SetFloat("BrushRadius", 1);
     paintShader.SetVector("BrushPosition", Vector3.zero);
     paintShader.SetVector("WorldPos", canvasWorldPosition);
     pointCloud_buf = new ComputeBuffer(8 * 8 * 8 * sizeof(float), sizeof(float), ComputeBufferType.Default);
     paintShader.SetBuffer(paintShader.FindKernel("CSMain"), "PointCloud", pointCloud_buf);
 }
예제 #3
0
    /// <summary>
    /// Remove shared vertices and generate the collider based on the triangles
    /// </summary>
    public void initializeData()
    {
#if UNITY_EDITOR
        //Mesh newMesh = Mesh.Instantiate(avoidVertexSharing());
        //AssetDatabase.CreateAsset(newMesh, "Assets/Scenes/scene1/models/walls/" + newMesh.name + gameObject.name + ".asset");
        //AssetDatabase.SaveAssets();
        //GetComponent<MeshFilter>().mesh = newMesh;
        //GetComponent<WallCol>().generatePolygonCollider(GetComponent<MeshFilter>().sharedMesh);
        mSimulationShader = ComputeShader.Instantiate(mSimulationShader);
        EditorUtility.SetDirty(this);
#endif
    }
예제 #4
0
 public MarchingCubeShaderAPI(out float[] pointCloud, out Vector3[] verts, out int[] tris)
 {
     //Set up shader
     marchShader    = ComputeShader.Instantiate(Resources.Load <ComputeShader>("Shaders/MarchingCubeShader"));
     pointCloud     = new float[9 * 9 * 9];
     verts          = new Vector3[8 * 8 * 8 * 15];
     tris           = new int[8 * 8 * 8 * 15];
     pointCloud_buf = new ComputeBuffer(pointCloud.Length * sizeof(float), sizeof(float), ComputeBufferType.Default);
     vert_buf       = new ComputeBuffer(verts.Length * sizeof(float) * 3, sizeof(float) * 3, ComputeBufferType.Default);
     tris_buf       = new ComputeBuffer(tris.Length * sizeof(int), sizeof(int), ComputeBufferType.Default);
     marchShader.SetFloat("IsoSurface", 0);
     marchShader.SetBuffer(marchShader.FindKernel("CSMain"), "PointCloud", pointCloud_buf);
     marchShader.SetBuffer(marchShader.FindKernel("CSMain"), "Verts", vert_buf);
     marchShader.SetBuffer(marchShader.FindKernel("CSMain"), "Tris", tris_buf);
 }
예제 #5
0
        public void Initialise(SoftBodyMesh _mesh)
        {
            m_softBody    = _mesh;
            m_gpuSoftBody = ComputeShader.Instantiate(Resources.Load <ComputeShader>("GPUSoftBody"));

            GeneralForces.s_instance.m_sphereColliderUpdate += UpdateSphereColliders;
            if (GeneralForces.s_instance.GetSphereColliderCount() > 0)
            {
                UpdateSphereColliders();
            }

            if (m_softBody)
            {
                GenerateGPUData();
                SetupShader();
                m_initialise = true;
            }
            else
            {
                m_initialise = false;
            }
        }
예제 #6
0
    private IEnumerator CreateFocusStackImg(List <string> imgFilePaths, int convWindowSize, string saveFilePath)
    {
        if (imgFilePaths.Count == 0)
        {
            yield break;
        }

        Texture2D tex = ImageLoader.ReadTextureByFile(imgFilePaths[0]);

        Debug.Log(tex.format.ToString());

        //読み込み専用と書き込み専用を交互に使い分ける
        var contrastMaps = new RenderTexture[2];

        for (int i = 0; i < 2; ++i)
        {
            contrastMaps[i] = new RenderTexture(tex.width
                                                , tex.height
                                                , 0
                                                , RenderTextureFormat.RFloat
                                                );
            contrastMaps[i].enableRandomWrite = true;
            contrastMaps[i].Create();
        }

        var focusStackImg = new RenderTexture(tex.width
                                              , tex.height
                                              , 0
                                              , RenderTextureFormat.ARGBFloat
                                              );

        focusStackImg.enableRandomWrite = true;
        focusStackImg.Create();

        Object.Destroy(tex);
        tex = null;

        var sw = new System.Diagnostics.Stopwatch();

        sw.Start();

        for (int i = 0; i < imgFilePaths.Count; ++i)
        {
            ComputeShader focusStackingShader = ComputeShader.Instantiate(Resources.Load <ComputeShader>("FocusStacking"));

            int kernelFuncID = focusStackingShader.FindKernel("FocusStacking_MaxContrast");
            focusStackingShader.SetInt("LocalWinSize", convWindowSize);
            focusStackingShader.SetInt("TexWidth", focusStackImg.width);
            focusStackingShader.SetInt("TexHeight", focusStackImg.height);
            focusStackingShader.SetTexture(kernelFuncID, "ContrastMap", contrastMaps[i % 2]);
            focusStackingShader.SetTexture(kernelFuncID, "NewContrastMap", contrastMaps[(i + 1) % 2]);

            focusStackingShader.SetTexture(kernelFuncID, "FocusStackingImg", focusStackImg);

            Texture2D srcTex = ImageLoader.ReadTextureByFile(imgFilePaths[i]);
            focusStackingShader.SetTexture(kernelFuncID, "SrcTex", srcTex);

            focusStackingShader.Dispatch(kernelFuncID, srcTex.width / 2, srcTex.height / 2, 1);

            Destroy(srcTex);
            srcTex = null;
            Resources.UnloadUnusedAssets();

            yield return(null);
        }

        sw.Stop();
        Debug.Log("focus stacking execute time");
        Debug.Log($"{sw.ElapsedMilliseconds}ミリ秒");
        SaveRendTexAsJPEG(focusStackImg, saveFilePath, TextureFormat.RGBAFloat);

        focusStackImg.Release();
        contrastMaps[0].Release();
        contrastMaps[1].Release();
    }
 public void Awake()
 {
     TextureGenerator = ComputeShader.Instantiate(TextureGenerator);
 }