Friday, 17 October 2014

Moving To VRay!!!

I seem to be doing lots of visualization work these days so decided to move to VRay. I think its much easier than Mental Ray to get the final result you want. But this in my opinion is because of how easy to use the VRay materials and lights are. I personally think Mental Ray is still a good renderer but I now prefer VRay mainly because of its materials.

I may also start using Houdini with Mantra for visualization work as I haven't tried any interior lighting and rendering with Mantra before. Also Mantra is one of my favourite renders.

Test scene I made as a way to learn and understand VRay.


Sunday, 5 October 2014

Unity Bezier Curve Script

Following from my previous post I have been working on this bezier curve script in my spare time. The script was done with C# in Unity and takes an array of objects as the input. The script then creates a curve by using these objects as control points.

The script works in the viewport by utilising the gizmo object and at render time I used the Line Renderer. I found this website which goes really in depth with creating bezier curves in unity.


Unity Bezier Curve Viewport Update

Below is the entire script which I have kept in one file just for simplicity.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BezierCurveScript : MonoBehaviour {
public class BezierPath
{
public List<Vector3> pathPoints;
private int segments;
public int pointCount;
public BezierPath()
{
pathPoints = new List<Vector3>();
pointCount = 100;
}
public void DeletePath()
{
pathPoints.Clear ();
}
Vector3 BezierPathCalculation(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
{
float tt = t * t;
float ttt = t * tt;
float u = 1.0f - t;
float uu = u * u;
float uuu = u * uu;
Vector3 B = new Vector3();
B = uuu * p0;
B += 3.0f * uu * t * p1;
B += 3.0f * u * tt * p2;
B += ttt * p3;
return B;
}
public void CreateCurve(List<Vector3> controlPoints)
{
segments = controlPoints.Count / 3;
for (int s = 0; s < controlPoints.Count -3; s+=3)
{
Vector3 p0 = controlPoints[s];
Vector3 p1 = controlPoints[s+1];
Vector3 p2 = controlPoints[s+2];
Vector3 p3 = controlPoints[s+3];
if(s == 0)
{
pathPoints.Add(BezierPathCalculation(p0, p1, p2, p3, 0.0f));
}
for (int p = 0; p < (pointCount/segments); p++)
{
float t = (1.0f / (pointCount/segments)) * p;
Vector3 point = new Vector3 ();
point = BezierPathCalculation (p0, p1, p2, p3, t);
pathPoints.Add (point);
}
}
}
}
private void createLine(Vector3 start, Vector3 end, float lineSize, Color c)
{
GameObject canvas = new GameObject("canvas" + canvasIndex);
canvas.transform.parent = transform;
canvas.transform.rotation = transform.rotation;
LineRenderer lines = (LineRenderer) canvas.AddComponent<LineRenderer>();
lines.material = new Material(shader);
lines.material.color = c;
lines.useWorldSpace = false;
lines.SetWidth(lineSize, lineSize);
lines.SetVertexCount(2);
lines.SetPosition(0, start);
lines.SetPosition(1, end);
canvasIndex++;
}
private void UpdatePath()
{
List<Vector3> c = new List<Vector3>();
for(int o = 0; o < objects.Length; o++)
{
if(objects[o] != null)
{
Vector3 p = objects[o].transform.position;
c.Add (p);
}
}
path.DeletePath ();
path.CreateCurve(c);
}
private int canvasIndex = 0;
public Shader shader;
BezierPath path = new BezierPath();
public GameObject[] objects;
// Use this for initialization
void Start () {
UpdatePath ();
}
// Update is called once per frame
void Update ()
{
UpdatePath ();
for (int i = 1; i < (path.pointCount); i++)
{
Vector3 startv = path.pathPoints[i-1];
Vector3 endv = path.pathPoints[i];
createLine (startv, endv, 0.25f, Color.blue);
}
}
void OnDrawGizmos()
{
UpdatePath ();
for (int i = 1; i < (path.pointCount); i++)
{
Vector3 startv = path.pathPoints[i-1];
Vector3 endv = path.pathPoints[i];
Gizmos.color = Color.blue;
Gizmos.DrawLine(startv, endv);
}
}
}