"Raytraced primitives in unity3d (part 5): distance fields"

Posted on 2016-11-08 in shaders • Tagged with unity3d, shaders, raytracing, distance-fields

After a long pause, I decided to give distance fields a try. Here's result: scene

This is a CSG-based shape. Sphere minus torus minus cube. Positions of the primitives are hardcoded.

Here's the code:

DistanceFields.shader:

Shader "Unlit/RaycastDistanceFields"{
    Properties  {
        _MainTex ("Texture", 2D) = "white" {}
        _Color ("Color", Color) = (1, 1, 1 …

Continue reading

"Raytraced primitives in unity3d (part 4.1): code cleanup"

Posted on 2016-04-13 in shaders • Tagged with unity3d, shaders, raytracing

This is a basic update of previous example.

It is largely the same thing as before:

scene

However, I cleaned up the code.

Basically, I'm thinking about moving from mathematically defined primitives (meaning every figure is defined by a formula) to distant fields which have somewhat simpler definition..

Distant field, basically …


Continue reading

"Raytraced primitives in unity3d (part 4): casting and receiving shadows"

Posted on 2016-04-12 in shaders • Tagged with unity3d, shaders, raytracing

Alright. I expected this to take less time, but things happened.

Here's what I have right now.

All lights on

Point liights, Point light

spot lights, Spot Light

and directional lights Directional Light

are supported and cast shadows.

Getting there, however, was unexpectedly difficult.

Here's the code. It is in need of some refactoring, but it works.

RaycastObject.shader …


Continue reading

"Raytraced primitives in unity3d (part 3): lights, shadows and attenuations"

Posted on 2016-04-01 in shaders • Tagged with unity3d, shaders, raytracing

I originally planned to finish and post this on monday. But stuff happened. So here we go.

Here's what I got at the moment: lit scene with point and spot lights

Good news: I got point and spot lights working. Raytraced sphere receives shadows from external sources. Oh, right, cookies and attenuation now works as well.
Bad …


Continue reading

"Raytraced primitives in unity3d (part 2): lit sphere"

Posted on 2016-03-25 in shaders • Tagged with unity3d, shaders, raytracing

So. Here's what I got at the moment:

lit sphere with several lights

It is the next iteration of shader from before. Here's the mesh geometry of this object:

lit sphere with several lights and wireframe

So, good news:

I got lighting. Attenuation isn't suported (yet), but it interacts with unity's point and directional lights, reads their colors, and also grabs ambient …


Continue reading

"Raytraced primitives in unity3d: sphere"

Posted on 2016-03-24 in shaders • Tagged with unity3d, shaders, raytracing

Alright, quick question. How many triangles are in this sphere?: Sphere

The answer is 12.

Sphere

The sphere is a raytraced primitive, which is actually a box (boundaries of the box are indicated by green wireframe). That's why it has 12 triangles.

Unity 3d shader system, despite having numerous flaws, allows easy …


Continue reading