public override void MakePhoton(ref GIRend.Photon p) { p.position = transform.TransformPoint(new Vector3(Random.value - 0.5f, Random.value - 0.5f, 0f)); // construct a random direction within cone angle float azimuth = Random.value * Mathf.PI * 2f; float altitude = Random.value * _coneAngleDeg * Mathf.Deg2Rad; Vector3 local; local.x = Mathf.Cos(azimuth) * Mathf.Sin(altitude); local.y = Mathf.Sin(azimuth) * Mathf.Sin(altitude); local.z = Mathf.Sqrt(1f - local.x * local.x - local.y * local.y); p.next_dir = local.x * transform.right + local.y * transform.up - local.z * transform.forward; Color col; if (_texture != null) { Vector3 localPos = transform.InverseTransformPoint(p.position); Vector3 uv = localPos + 0.5f * Vector3.one; uv.z = 0f; col = intensity * _texture.GetPixelBilinear(uv.x, uv.y); } else { col = intensity * _light.color; } p.intensity = new Vector3(col.r, col.g, col.b); }
public override void MakePhoton(ref GIRend.Photon p) { p.position = transform.position; // construct a random direction within cone angle float azimuth = Random.value * Mathf.PI * 2f; float altitude = Random.value * _coneAngleDeg * Mathf.Deg2Rad; Vector3 local; local.x = Mathf.Cos(azimuth) * Mathf.Sin(altitude); local.y = Mathf.Sin(azimuth) * Mathf.Sin(altitude); local.z = Mathf.Sqrt(1f - local.x * local.x - local.y * local.y); p.next_dir = local.x * transform.right + local.y * transform.up + local.z * transform.forward; float dotmin = Mathf.Cos(0.5f * _light.spotAngle * Mathf.Deg2Rad); do { p.next_dir = Random.onUnitSphere; }while(Vector3.Dot(transform.forward, p.next_dir) <= dotmin); Color col = intensity * _light.color; p.intensity = new Vector3(col.r, col.g, col.b); }
public override void MakePhoton(ref GIRend.Photon p) { Vector3 off = Random.onUnitSphere; p.position = transform.position + _radius * off; p.next_dir = Random.onUnitSphere; if (Vector3.Dot(p.next_dir, off) < 0f) { p.next_dir = -p.next_dir; } Color col = intensity * _light.color; p.intensity = new Vector3(col.r, col.g, col.b); }
public void Hit(ref GIRend.Photon p, ref RaycastHit hit, out Color existingRadiance) { Vector3 local = transform.InverseTransformPoint(hit.point); Vector3 uv = local + 0.5f * Vector3.one; uv.z = 0f; int x = Mathf.FloorToInt(uv.x * _texture.width); int y = Mathf.FloorToInt(uv.y * _texture.height); int index = y * _texture.height + x; index = Mathf.Clamp(index, 0, pixels.Length - 1); existingRadiance = pixels[index]; pixels[index].r += p.intensity.x; pixels[index].g += p.intensity.y; pixels[index].b += p.intensity.z; pixels[index].a = 255; }
public abstract void MakePhoton(ref GIRend.Photon p);