public void CustomMaterialRenderer(ScriptableRenderContext context, HDCamera hdCamera)
    {
        //Initialize the values for the scene renderers and override material.
        Initialize(ref cachedSceneRenderers, ref targetMaterial);

        //Pool a command buffer instead of creating one each frame.
        CommandBuffer cameraBuffer = CommandBufferPool.Get("Render Camera");

        //This function sets up view, projection and clipping planes global shader variables.
        context.SetupCameraProperties(hdCamera.camera);

        //Identifier when measuring CPU and GPU time spent on this command buffer.
        cameraBuffer.BeginSample("Render Camera");

        //Clear the values on the render target if any
        cameraBuffer.ClearRenderTarget(true, true, Color.clear);

        //Execute and clear the command buffer.
        ExecuteCommandBuffer(ref context, ref cameraBuffer);

        //Create material replacement settings.
        MaterialReplacer replacementMaterialRenderer = new MaterialReplacer();

        replacementMaterialRenderer.ReplacementMaterialRenderer(ref targetMaterial);

        //Restore the previous material properties on the replaced material.
        cachedSceneRenderers.SetCachedProperties();

        //Draw all of the objects with the replaced material.
        replacementMaterialRenderer.Draw(ref context, ref hdCamera);

        //Draw the skybox.
        context.DrawSkybox(hdCamera.camera);

        //End the sample.
        cameraBuffer.EndSample("Render Camera");

        //Execute and clear the command buffer.
        ExecuteCommandBuffer(ref context, ref cameraBuffer);

        //Submit the custom render to be rendered
        context.Submit();
    }
예제 #2
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        MaterialReplacer mr = (MaterialReplacer)target;

        if (!mr)
        {
            return;
        }
        if (GUILayout.Button("Generate Colliders"))
        {
            mr.AddMeshColliders();
        }

        if (!mr.material)
        {
            return;
        }
        if (GUILayout.Button("Replace"))
        {
            mr.Replace();
        }
    }
예제 #3
0
    public void Init()
    {
        //Generates circle, arrow, and replace materials
        CheckIfHeldByPlayer();

        datas = Resources.Load <HighlighterDatas>("HighlighterDatas");
        Shader.SetGlobalFloat("_MinEmissiveIntensity", datas.minEmissionForce);
        Shader.SetGlobalFloat("_MaxEmissiveIntensity", datas.maxEmissionForce);
        Shader.SetGlobalFloat("_EmissiveLerpSpeed", datas.emissionLerpSpeed);
        materialReplacers = new List <MaterialReplacer>();
        foreach (Renderer renderer in GetComponentsInChildren <Renderer>())
        {
            if (renderer.GetType() == typeof(ParticleSystemRenderer))
            {
                continue;
            }
            MaterialReplacer newReplacer = renderer.gameObject.AddComponent <MaterialReplacer>();
            materialReplacers.Add(newReplacer);
            newReplacer.ReplaceMaterial(Resources.Load <Material>("HighlightResource/M_HighlightedObject"));
        }

        circle = Instantiate(Resources.Load <GameObject>("HighlightResource/HighlightCircle"));
        circle.transform.SetParent(transform);
        circle.transform.localPosition = Vector3.zero + new Vector3(0, datas.circleZOffset, 0);
        circle.transform.localRotation = Quaternion.identity;
        circle.transform.localScale    = Vector3.one * datas.circleMinSize;

        arrow = Instantiate(Resources.Load <GameObject>("HighlightResource/HighlightArrow"));
        arrow.transform.SetParent(transform);
        arrow.transform.localPosition = Vector3.zero + new Vector3(0, datas.arrowMinZOffset, 0);
        arrow.transform.localRotation = Quaternion.identity;
        arrow.transform.localScale    = Vector3.one;

        previousParent = transform.parent;
        passedTime     = 0;
        fadeCoroutine  = StartCoroutine(FadeIn_C());
    }
예제 #4
0
 	static void Init()
 	{
 		// Get existing open window or if none, make a new one:
 		MaterialReplacer materialWindow = (MaterialReplacer)EditorWindow.GetWindow( typeof(MaterialReplacer) );
 		materialWindow.position = new Rect( 200, 200, 750, 430 );
 	}