Example #1
0
    // ======================================================================================================================
    // LOOP ---------------------------------------------------------------------------

    private void Update()
    {
        if (numberOfFrames > 2)
        {
            mainC.RemoveCommandBuffer(CameraEvent.AfterDepthTexture, cb_markingIlsdands);
        }

        createMetalicGlossMap.SetTexture("_Smoothness", smoothness.runTimeTexture);
        createMetalicGlossMap.SetTexture("_MainTex", metalic.runTimeTexture);
        Graphics.Blit(metalic.runTimeTexture, metalicGlossMapCombined, createMetalicGlossMap);



        numberOfFrames++;

        // ----------------------------------------------------------------------------
        // This MUST be called to set up the painting with the mouse.
        albedo.UpdateShaderParameters(meshGameobject.transform.localToWorldMatrix);
        metalic.UpdateShaderParameters(meshGameobject.transform.localToWorldMatrix);
        smoothness.UpdateShaderParameters(meshGameobject.transform.localToWorldMatrix);


        // ---------------------------------------------------------------------------
        // Setting up Mouse Parameters

        RaycastHit hit;
        Ray        ray = mainC.ScreenPointToRay(Input.mousePosition);
        Vector4    mwp = Vector3.positiveInfinity;

        if (Physics.Raycast(ray, out hit))
        {
            if (hit.collider.gameObject.tag == "PaintObject")
            {
                mwp = hit.point;
            }
        }

        mwp.w = Input.GetMouseButton(0)? 1 : 0;

        mouseWorldPosition = mwp;
        Shader.SetGlobalVector("_Mouse", mwp);
    }
    // ======================================================================================================================
    // INITIALIZE -------------------------------------------------------------------
    void Start()
    {
        Vector4 mwp = new Vector4(100, 100, 100, 100);

        Shader.SetGlobalVector("_Mouse", mwp);

        // Texture and Mat initalization ---------------------------------------------
        markedIlsandes = new RenderTexture(baseTexture.width, baseTexture.height, 0, RenderTextureFormat.R8);
        albedo         = new PaintableTexture(Color.white, baseTexture.width, baseTexture.height, "_MainTex", UVShader, meshToDraw, fixIlsandEdgesShader, markedIlsandes);


        meshMaterial.SetTexture(albedo.id, albedo.runTimeTexture);

        // Command buffer inialzation ------------------------------------------------

        cb_markingIlsdands      = new CommandBuffer();
        cb_markingIlsdands.name = "markingIlsnads";


        cb_markingIlsdands.SetRenderTarget(markedIlsandes);
        Material mIlsandMarker = new Material(ilsandMarkerShader);

        cb_markingIlsdands.DrawMesh(meshToDraw, Matrix4x4.identity, mIlsandMarker);
        mainCamera.AddCommandBuffer(CameraEvent.AfterEverything, cb_markingIlsdands);


        albedo.SetActiveTexture(mainCamera);

        Shader.SetGlobalFloat("_BrushOpacity", 1);
        Shader.SetGlobalColor("_BrushColor", Color.red);
        Shader.SetGlobalFloat("_BrushSize", .13f);
        Shader.SetGlobalFloat("_BrushHardness", .1f);

        mainCamera.depthTextureMode = DepthTextureMode.Depth;

        albedo.UpdateShaderParameters(meshGameobject.transform.localToWorldMatrix);
    }