void Start() { Camera.onPreRender += onPreRender; input = new Texture2D(width, height); Color[] colorArray = new Color[width * height]; for (int i = 0; i < colorArray.Length; ++i) { colorArray[i] = Random.Range(0f, 1f) > 0.5f ? Color.white : Color.black; } input.SetPixels(colorArray); input.Apply(); if (material) { material.mainTexture = input; } frameBuffer = new FrameBuffer(); frameBuffer.Create(width, height); output = frameBuffer.Get(); frameBuffer.Swap(); Graphics.Blit(input, frameBuffer.Get()); }
void Update() { if (timeElapsed >= (animDuration - 0.00001)) { record = false; } if (materialShader) { if (!record) { Shader.SetGlobalTexture(uniformName, frameBuffer.Apply(materialShader)); Shader.SetGlobalFloat("_TimeElapsed", Time.time); index = 0; wasRecording = false; } else { if (wasRecording == false) { wasRecording = true; timeStarted = Time.time; filePath = System.IO.Path.Combine(path, "Renders") + "/" + DateTime.Now.ToString("yyyyMMddHHmmssffff"); } Shader.SetGlobalFloat("_TimeElapsed", timeElapsed); Shader.SetGlobalTexture(uniformName, frameBuffer.Apply(materialShader)); if (File.Exists(filePath) == false) { Directory.CreateDirectory(filePath); } // UnityEngine.Debug.Log(timeElapsed); RenderTexture.active = frameBuffer.Get(); texture2D.ReadPixels(new Rect(0, 0, frameBuffer.Get().width, frameBuffer.Get().height), 0, 0); texture2D.Apply(); File.WriteAllBytes(filePath + "/" + index.ToString().PadLeft(3, '0') + ".jpg", texture2D.EncodeToJPG()); ++index; timeElapsed += 1f / frameRate; } } }
void Update() { Shader.SetGlobalMatrix("_RendererMatrix", render.localToWorldMatrix); Shader.SetGlobalMatrix("_InverseMatrix", render.localToWorldMatrix.inverse); Shader.SetGlobalVector("_TransformPosition", transform.position); Shader.SetGlobalMatrix("_TransformMatrix", transform.localToWorldMatrix); Graphics.Blit(frameBuffer.Get(), output, shader); output = frameBuffer.Get(); frameBuffer.Swap(); if (debug) { debug.mainTexture = output; } Shader.SetGlobalTexture("_VertexTexture", texture); Shader.SetGlobalTexture(uniformName, frameBuffer.Get()); }
void Start() { mesh = GetComponent <MeshFilter>().sharedMesh; resolution = (int)GetNearestPowerOfTwo(Mathf.Sqrt(mesh.vertices.Length)); texture = new Texture2D(resolution, resolution, TextureFormat.RGBAFloat, false); texture.filterMode = FilterMode.Point; colorArray = new Color[resolution * resolution]; Print(); frameBuffer = new FrameBuffer(); frameBuffer.Create(resolution, resolution); Graphics.Blit(texture, frameBuffer.Get()); frameBuffer.Swap(); Graphics.Blit(texture, frameBuffer.Get()); Shader.SetGlobalTexture(uniformName, frameBuffer.Get()); Shader.SetGlobalTexture("_VertexTexture", texture); Shader.SetGlobalFloat("_Resolution", resolution); render = GetComponent <Renderer>(); }
public void onPreRender(Camera camera) { if (shader == null) { shader = new Material(Shader.Find("Hidden/GameOfLife")); } shader.SetVector("_Resolution", new Vector2(width, height)); if (last + delay < Time.time) { last = Time.time; Graphics.Blit(frameBuffer.Get(), output, shader); output = frameBuffer.Get(); frameBuffer.Swap(); if (material) { material.mainTexture = output; } } }
void Update() { if (Input.GetKeyDown(KeyCode.LeftArrow)) { ChangeLOD(lod - 1); } else if (Input.GetKeyDown(KeyCode.RightArrow)) { ChangeLOD(lod + 1); } if (Input.GetKeyDown(KeyCode.UpArrow)) { ChangeCount(count + 50); } else if (Input.GetKeyDown(KeyCode.DownArrow)) { ChangeCount(count - 50); } if (isReady) { materialSlicing.SetFloat("_LineSize", lineSize); if (lastFire + 1f / frameRate < Time.time) { lastFire = Time.time; for (int i = count - 1; i > 0; --i) { Graphics.Blit(textures[(i - 1) % count], textures[i % count]); materialSlicing.SetFloat("_LinePosition", i / (float)count); materialSlicing.SetTexture("_NewFrame", textures[(i - 1) % count]); frameBuffer.Apply(materialSlicing); } Graphics.Blit(webcam.texture, textures[0]); } Shader.SetGlobalTexture("_TimeTexture", frameBuffer.Get()); } }