} // end of Awake() // --------------------------------------------------------- private void Update() { controlPolyLine.positionCount = 4; Matrix4x4 splineMatrix = SplineParameters.GetMatrix(splineType); // pass all necessary variables to the Vertex Shader: // // spline matrix in Hermite form: material.SetMatrix("_SplineMatrix", splineMatrix); // control points for spline curve rendering: material.SetVector("_Control0", control0.position); material.SetVector("_Control1", control1.position); material.SetVector("_Control2", control2.position); material.SetVector("_Control3", control3.position); // step between subsequent t parameter values for curve: float step = (float)1.0 / (float)(verticesOnCurve - 1); material.SetFloat("_Step", step); material.SetColor("_Color", splineColor); // to draw the enclosing polyLine, set control line points: // controlPolyLine.SetPosition(0, control0.position); controlPolyLine.SetPosition(1, control1.position); controlPolyLine.SetPosition(2, control2.position); controlPolyLine.SetPosition(3, control3.position); } // end of Update()
} // end of Awake() // --------------------------------------------------------- private void Update() { controlPolyLine.positionCount = 4; Matrix4x4 splineMatrix = SplineParameters.GetMatrix(splineType); //rotate camera //center view and orbit camera.transform.LookAt(center); rotationCam += .5f * Time.deltaTime; camera.transform.position = cam + (new Vector3(Mathf.Sin(rotationCam), 0, Mathf.Cos(rotationCam)) * 6f); //animate //bounce between tow points control0.position = Vector3.MoveTowards(control0.position, cp0, Time.fixedDeltaTime * .1f); if(control0.position == cp0){ cp0 = new Vector3(cp0.x * -1, cp0.y, cp0.z); } //rotate around a centeral axis with a defined radius rotationCp1 += 1.5f * Time.deltaTime; control1.position = cp1 + (new Vector3(Mathf.Sin(rotationCp1), Mathf.Cos(rotationCp1), 0) * 1f); control2.position = Vector3.MoveTowards(control2.position, cp2, Time.fixedDeltaTime * .3f); if(control2.position == cp2){ cp2 = new Vector3(cp2.x, cp2.y * -1, cp2.z); } rotationCp3 += 1f * Time.deltaTime; control3.position = cp3 + (new Vector3(Mathf.Sin(rotationCp3), Mathf.Cos(rotationCp3), 0) * .5f); //bounce light source between two points light.transform.position = Vector3.MoveTowards(light.transform.position, lDest, Time.fixedDeltaTime * .1f); if(light.transform.position == le){ lDest = ls; } else if(light.transform.position == ls){ lDest = le; } // pass all necessary variables to the Vertex Shader: // // spline matrix in Hermite form: material.SetMatrix("_SplineMatrix", splineMatrix); // control points for spline curve rendering: material.SetVector("_Control0", control0.position); material.SetVector("_Control1", control1.position); material.SetVector("_Control2", control2.position); material.SetVector("_Control3", control3.position); // step between subsequent t parameter values for curve: float step = (float)1.0 / (float)(verticesOnCurve - 1); material.SetFloat("_Step", step); material.SetColor("_Color", splineColor); //pass light vars; camera pos, light color, light pos material.SetColor("_Light_Color", light.GetComponent<SpriteRenderer>().color); material.SetVector("_Light", light.transform.position); material.SetVector("_Cam", camera.transform.position); //determine if vertex or fragment shader is computing if(renderer == RendererType.vertex){ material.SetFloat("_VorF", 1); } else{ material.SetFloat("_VorF", 0); } // to draw the enclosing polyLine, set control line points: // controlPolyLine.SetPosition(0, control0.position); controlPolyLine.SetPosition(1, control1.position); controlPolyLine.SetPosition(2, control2.position); controlPolyLine.SetPosition(3, control3.position); } // end of Update()