SetReplacementShader() private method

private SetReplacementShader ( Shader shader, string replacementTag ) : void
shader Shader
replacementTag string
return void
    // Use this for initialization
    void Awake()
    {
        GameObject go = new GameObject("depthCamera");
        depthCamera = go.AddComponent<Camera>();
        depthCamera.transform.position = Vector3.zero;
        depthCamera.transform.rotation = transform.rotation;
        depthCamera.transform.localPosition += transform.forward * Near;
        depthCamera.transform.parent = transform;
        depthCamera.isOrthoGraphic = true;

        depthCamera.clearFlags = CameraClearFlags.SolidColor;
        depthCamera.backgroundColor = Color.white;
        depthTexture = new RenderTexture(TextureSize,TextureSize, 16, RenderTextureFormat.ARGB32);
        depthTexture.filterMode = FilterMode.Point;
        depthCamera.targetTexture = depthTexture;
        depthCamera.SetReplacementShader(shader, null);
        depthCamera.enabled = false;
        biasMatrix = Matrix4x4.identity;
        biasMatrix[ 0, 0 ] = 0.5f;
        biasMatrix[ 1, 1 ] = 0.5f;
        biasMatrix[ 2, 2 ] = 0.5f;
        biasMatrix[ 0, 3 ] = 0.5f;
        biasMatrix[ 1, 3 ] = 0.5f;
        biasMatrix[ 2, 3 ] = 0.5f;
    }
Example #2
0
		public static void SetupRadarCamera()
		{
			if(radarRT && radarTex2D && radarCam && radarShader)
			{
				return;
			}

			//setup shader first
			if(!radarShader)
			{
				radarShader = BDAShaderLoader.UnlitBlackShader;//.LoadManifestShader("BahaTurret.UnlitBlack.shader");
			}

			//then setup textures
			radarRT = new RenderTexture(radarResolution,radarResolution,16);
			radarTex2D = new Texture2D(radarResolution,radarResolution, TextureFormat.ARGB32, false);

			//set up camera
			radarCam = (new GameObject("RadarCamera")).AddComponent<Camera>();
			radarCam.enabled = false;
			radarCam.clearFlags = CameraClearFlags.SolidColor;
			radarCam.backgroundColor = Color.white;
			radarCam.SetReplacementShader(radarShader, string.Empty);
			radarCam.cullingMask = 1<<0;
			radarCam.targetTexture = radarRT;
			//radarCam.nearClipPlane = 75;
			//radarCam.farClipPlane = 40000;
		}
 void Start()
 {
     cam = GetComponent<Camera> ();
     cam.SetReplacementShader (Shader.Find("Sprites/Default"), null);
     boarder = GameObject.Find("Minimap-Image");
     Input.ResetInputAxes ();
 }
Example #4
0
    void Awake()
    {
        if (_normal_camera == null){
            //create clipping mask for normals;
            _normal_mask =
                    1 << 1 |
                    1 << 2 |
                    1 << 3 |
                    1 << 4 |
                    1 << 5 |
                    1 << 6 |
                    1 << 7 |
                    1 << 8 |
                    1 << 9 |
                    1 << 10 |
                    1 << 11 |
                    1 << 12 |
                    1 << 13 |
                    1 << 14 |
        //				1 << 15 |
        //				1 << 16 |
                    1 << 17 |
        //				1 << 18;
                    1 << 22;

            //create a new camera;
            _normal_camera =  new GameObject("normal_camera");

            //add camera and copy attributes of original camera
            _normal_camera_camera_component = _normal_camera.AddComponent<Camera>();
            _normal_camera_camera_component.CopyFrom(camera);
            _normal_camera_camera_component.depth = -1;
            _normal_camera_camera_component.cullingMask = _normal_mask;

            //add blur shader
            _normal_blur_component = _normal_camera.AddComponent<normal_blur>();

            //set_background to null normal
            _normal_camera_camera_component.clearFlags = CameraClearFlags.SolidColor;
            _normal_camera_camera_component.backgroundColor = new Color(0.5f,0.5f,1.0f);
            _normal_camera_camera_component.camera.depthTextureMode = DepthTextureMode.DepthNormals;

            //sets replacementshader to render normals
            _normal_camera_camera_component.SetReplacementShader(_display_normal_shader,"");

            //parent and reset it to original camera;
            _normal_camera.transform.rotation = transform.rotation;
            _normal_camera.transform.position = transform.position;
            _normal_camera.transform.parent = transform;

            //create a new Render Texture for the normal pass and assign it to the Camera
            _normal_render_texture = new RenderTexture(Screen.width,Screen.height,32,RenderTextureFormat.ARGBHalf);
            _normal_render_texture.name = "normal_pass";
            _normal_camera_camera_component.targetTexture = _normal_render_texture;

            //set normal Texture global for all shaders
            Shader.SetGlobalTexture("_objectNormalTexture", _normal_render_texture);
        }
    }
    // Fetches an existing camera in the hierarchy, or creates a new one.
    private void GetOrCreateNormalCamera()
    {
        // if we've already got a distortion camera, then just return immediately.
        if (_normalCamera) return;

        // otherwise, search the hierarchy for an existing one. If it's there, we're
        // all set. Asign our camera reference, and return.
        Transform foundTranform = this.transform.Find( "ImageEffect_Gotow_HeatDistortion_Camera" );
        if (foundTranform) {
            _normalCamera = foundTranform.GetComponent<Camera>();
            return;
        }

        // if we're still here, then we've got to create a camera ourselves, and add it
        // to the scene. First, construct a GameObject with our known name.
        GameObject obj = new GameObject( "ImageEffect_Gotow_HeatDistortion_Camera" );
        // set it to be uneditable, and invisible in the scene hierarchy.
        // it can be recreated later if we need it, and it will confuse the user to have
        // another camera floating around.
        obj.hideFlags = HideFlags.NotEditable | HideFlags.HideAndDontSave;
        // Set its transform to this script's transform, so that it will always follow
        // the camera we're putting the image effect on.
        obj.transform.parent = this.transform;
        obj.transform.position = this.transform.position;
        obj.transform.rotation = this.transform.rotation;

        // Now, attach a camera component.
        _normalCamera = obj.AddComponent<Camera>();
        // set its projection matrix to match that of our main camera. This way, we
        // can always be sure that the cameras line up properly.
        _normalCamera.depth = _camera.depth;
        _normalCamera.renderingPath = _camera.renderingPath;
        _normalCamera.projectionMatrix = _camera.projectionMatrix;
        _normalCamera.fieldOfView = _camera.fieldOfView;
        _normalCamera.orthographic = _camera.orthographic;
        _normalCamera.orthographicSize = _camera.orthographicSize;

        // Set the camera to clear to a normal-neutral background.
        _normalCamera.clearFlags = CameraClearFlags.SolidColor;
        _normalCamera.backgroundColor = new Color( 0.5f, 0.5f, 1.0f );

        // Lastly, set up the replacement shader. We want only our defining particle
        // effects to render into the distortion normal buffer, everything else in the
        // scene will use a depth-only shader, so that the particles can be occluded.
        _normalCamera.SetReplacementShader( Shader.Find( "Hidden/ImageEffects/Gotow/DistortionMap" ), "RenderType" );
    }
Example #6
0
	void Awake() {
		if(!ms_shadowTextureFakePoint) {
			ms_shadowTextureFakePoint = new Texture2D(1, 1, TextureFormat.Alpha8, false, true);
			ms_shadowTextureFakePoint.filterMode = FilterMode.Point;
			ms_shadowTextureFakePoint.SetPixel(0, 0, new Color(0f, 0f, 0f, 0f));
			ms_shadowTextureFakePoint.Apply(false, true);

			ms_shadowMatrixID = Shader.PropertyToID("u_UniqueShadowMatrix");
			ms_shadowTextureID = Shader.PropertyToID("u_UniqueShadowTexture");
		}

		EnsureLightSource();

		m_shadowMatrix = Matrix4x4.identity;
		var shadowCameraGO = new GameObject("#> _Shadow Camera < " + this.name);
		shadowCameraGO.hideFlags = HideFlags.DontSave | HideFlags.NotEditable | HideFlags.HideInHierarchy;
		m_shadowCamera = shadowCameraGO.AddComponent<Camera>();
		m_shadowCamera.renderingPath = RenderingPath.Forward;
		m_shadowCamera.clearFlags = CameraClearFlags.Depth;
		m_shadowCamera.depthTextureMode = DepthTextureMode.None;
		m_shadowCamera.useOcclusionCulling = false;
		m_shadowCamera.cullingMask = useSceneCapture ? (LayerMask)~0 : inclusionMask;
		m_shadowCamera.orthographic = true;
		m_shadowCamera.depth = -100;
		m_shadowCamera.aspect = 1f;
		m_shadowCamera.SetReplacementShader(uniqueShadowDepthShader, "RenderType");
		m_shadowCamera.enabled = false;
		
		SetFocus(startFocus);

		m_materialInstances = new List<Material>();
		var materialMap = new Dictionary<Material, Material>();
		foreach(var r in GetComponentsInChildren<Renderer>()) {
			if(!r.receiveShadows)
				continue;

			bool hadMaterials = false;
			var sharedMaterials = r.sharedMaterials;
			for(int i  = 0, n = sharedMaterials.Length; i < n; ++i) {
				var m = sharedMaterials[i];

				Material mi = null;
				if(!materialMap.TryGetValue(m, out mi)) {
					materialMap[m] = mi = new Material(m);
					mi.name = m.name + " (uniq)";
					mi.shaderKeywords = m.shaderKeywords;
					mi.renderQueue = m.renderQueue;
					SetStaticShaderUniforms(mi);
					m_materialInstances.Add(mi);
				}
				sharedMaterials[i] = mi;
				hadMaterials = true;
			}

			if(hadMaterials)
				r.sharedMaterials = sharedMaterials;
		}

		if(m_materialInstances.Count > 0) {
			var mesh = new Mesh();
			mesh.bounds = new Bounds(Vector3.zero, Vector3.one * 1000f);
			mesh.hideFlags = HideFlags.HideAndDontSave;
			var mf = gameObject.AddComponent<MeshFilter>();
			mf.sharedMesh = mesh;
			var mr = gameObject.AddComponent<MeshRenderer>();
			mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
			mr.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
			mr.useLightProbes = false;
		}
	}
    void Awake()
    {
        _vertex_color_mask_shader = (Shader)Resources.Load("shader/hdr_vertex_color_mask");

        if (_mask_camera_camera == null){
            //create clipping mask for masks;
            _mask =
                    1 << 0 |
                    1 << 1 |
                    1 << 2 |
                    1 << 3 |
                    1 << 4 |
                    1 << 5 |
                    1 << 6 |
                    1 << 7 |
                    1 << 8 |
                    1 << 9 |
                    1 << 10 |
                    1 << 11 |
                    1 << 12 |
                    1 << 13 |
                    1 << 14 |
        //				1 << 15 |
        //				1 << 16 |
                    1 << 17 |
                    1 << 18;

            //create a new camera;
            _mask_camera_camera =  new GameObject("mask_camera");
            //add camera and copy attributes of original camera
            _mask_camera_camera_component = _mask_camera_camera.AddComponent<Camera>();
            _mask_camera_camera_component.CopyFrom(camera);
            _mask_camera_camera_component.depth = -2;

        //		//sets replacementshader to render normals
        //		_mask_camera_camera_component.SetReplacementShader(gray_unlit_shader ,"Opaque");

            //set_background to null mask
            _mask_camera_camera_component.clearFlags = CameraClearFlags.SolidColor;
            _mask_camera_camera_component.backgroundColor = new Color(0.5f,0.5f,0.5f);
            _mask_camera_camera_component.cullingMask = _mask;

            //set replacementshader
            _mask_camera_camera_component.SetReplacementShader(_vertex_color_mask_shader,"");

            //parent and reset it to original camera;
            _mask_camera_camera.transform.rotation = transform.rotation;
            _mask_camera_camera.transform.position = transform.position;
            _mask_camera_camera.transform.parent = transform;

            //set hdr rendering to on
            _mask_camera_camera_component.hdr = true;

            //create a new Render Texture for the mask pass and assign it to the Camera
            _mask_render_texture = new RenderTexture(Screen.width,Screen.height,8,RenderTextureFormat.ARGBHalf);
            _mask_render_texture.name = "mask_pass";
            _mask_camera_camera_component.targetTexture = _mask_render_texture;

            //set mask Texture global for all shaders
        Shader.SetGlobalTexture("_mask_Texture", _mask_render_texture);
        }
    }
Example #8
0
 /// <summary>
 /// Inicializacion
 /// </summary>
 private void Start()
 {
     CurrentCamera = GetComponent<Camera>();
     CurrentCamera.SetReplacementShader(RenderShader, null);
 }