Exemplo n.º 1
0
        void Update()
        {
            Light l = fromObject.GetComponent <Light> ();

            if (l != null)
            {
                this.color = l.color;
            }

            Matrix4x4 lineMat = directionObject.transform.worldToLocalMatrix;

            this.LightLine = GetShadingLine();

            Vector3 fromPoint = lineMat.MultiplyVector(LightLine.Points[0].Position);
            Vector3 toPoint   = lineMat.MultiplyVector(LightLine.Points[1].Position);

            if (this.directionObject != null)
            {
                ShadingLine line = new ShadingLine();
                line.Add(new ShadingLinePoint(fromPoint, color));
                line.Add(new ShadingLinePoint(toPoint, color));
                ShadingLineController shadingLineController = directionObject.GetComponent <ShadingLineController>();
                shadingLineController.Initialize(line);
            }
        }
        /// <summary>
        /// Simulate this instance.
        /// </summary>
        private void Simulate()
        {
            ShadingLine        lightLine      = lightDirectionController.LightLine;
            Vector3            lightDirection = (lightLine.Points [1].Position - lightLine.Points [0].Position).normalized;
            Vector3            normal         = shadingPointController.Normal;
            int                nDistro        = shadingUIController.Distro;
            List <ShadingLine> shadingLines   = GetSpecularShadingLine(lightDirection, normal, nDistro);

            shadingPointController.Initialize(shadingLines);
        }
Exemplo n.º 3
0
        private ShadingLine GetShadingLine()
        {
            Vector3     fromPoint = fromObject.transform.localToWorldMatrix.MultiplyPoint(new Vector3(0.0f, 0.0f, 0.0f));
            Vector3     toPoint   = toObject.transform.localToWorldMatrix.MultiplyPoint(new Vector3(0.0f, 0.0f, 0.0f));
            ShadingLine line      = new ShadingLine();

            line.Add(new ShadingLinePoint(fromPoint, this.color));
            line.Add(new ShadingLinePoint(toPoint, this.color));
            return(line);
        }
Exemplo n.º 4
0
        public void Initialize(ShadingLine line)
        {
            List <Vector3> positions = new List <Vector3>();

            foreach (ShadingLinePoint p in line.Points)
            {
                positions.Add(p.Position);
            }
            lineRenderer.SetPositions(positions.ToArray());
            if (line.Points.Count >= 2)
            {
                Color c0 = line.Points[0].Color;
                Color c1 = line.Points[line.Points.Count - 1].Color;
                lineRenderer.SetColors(c0, c1);
            }
        }
        private List <ShadingLine> GetSpecularShadingLine(Vector3 lightDirection, Vector3 normal, int nDistro)
        {
            Vector3 lightU  = Vector3.Dot(-lightDirection, normal) * normal;
            Vector3 lightH  = -lightDirection - lightU;
            Vector3 reflect = (-lightDirection - 2.0f * lightH).normalized;

            List <ShadingLine> shadingLines = new List <ShadingLine> ();

            {
                ShadingLine line = new ShadingLine();
                line.Add(new ShadingLinePoint(new Vector3(), Color.blue));
                line.Add(new ShadingLinePoint(reflect, Color.blue));
                shadingLines.Add(line);
            }

            if (Vector3.Dot(lightDirection, normal) > 0)
            {
                return(shadingLines);
            }

            float PhongPower     = shadingUIController.PhongPower;
            float PhongIntensity = 1.0f;

            while (shadingLines.Count < nDistro + 1)
            {
                Vector3 v = GetDistVector(); //-view direction
                if (Vector3.Dot(v, reflect) < 0.0f)
                {
                    v = -v;
                }
                if (Vector3.Dot(v, normal) > 0)
                {
                    float p = Mathf.Pow(Mathf.Abs(Vector3.Dot(reflect, v)), PhongPower) * PhongIntensity;
                    if (p > 0.001)
                    {
                        ShadingLine line = new ShadingLine();
                        line.Add(new ShadingLinePoint(new Vector3(), Color.red));
                        line.Add(new ShadingLinePoint(p * v, Color.red));
                        shadingLines.Add(line);
                    }
                }
            }
            return(shadingLines);
        }
Exemplo n.º 6
0
 void Start()
 {
     this.LightLine = GetShadingLine();
 }