All Projects → hecomi → Uraymarching

hecomi / Uraymarching

Raymarching Shader Generator in Unity

Projects that are alternatives of or similar to Uraymarching

3d Game Shaders For Beginners
🎮 A step-by-step guide to implementing SSAO, depth of field, lighting, normal mapping, and more for your 3D game.
Stars: ✭ 11,698 (+1375.16%)
Mutual labels:  unity, shader, hlsl
Unity Raymarching Framework
A framework to easy implement raymarching in unity. Include lots of hash,noise,fbm,SDF,rotate functions
Stars: ✭ 129 (-83.73%)
Mutual labels:  unity, shader, hlsl
Pbr proj
Shader of PBR for Unity
Stars: ✭ 68 (-91.42%)
Mutual labels:  unity, shader, hlsl
Skeletalgeometriceffects
Experiments on geometry shader instancing with skeletal animations
Stars: ✭ 436 (-45.02%)
Mutual labels:  unity, shader, hlsl
Unity Shaders
✨ Shader demo - More than 300 examples
Stars: ✭ 198 (-75.03%)
Mutual labels:  unity, shader, hlsl
Nnao
Neural Network Ambien Occlusion based on http://theorangeduck.com/page/neural-network-ambient-occlusion
Stars: ✭ 57 (-92.81%)
Mutual labels:  unity, shader, hlsl
Proccharvfx
Procedural character generation with Unity Shader Graph and VFX Graph
Stars: ✭ 114 (-85.62%)
Mutual labels:  unity, shader, hlsl
Unity3d Cg Programming
Various shaders.
Stars: ✭ 800 (+0.88%)
Mutual labels:  unity, shader, hlsl
Bloodfx
Procedural blood stain shader
Stars: ✭ 170 (-78.56%)
Mutual labels:  unity, shader, hlsl
Computestochasticreflections
Compute Stochastic Screen Space Reflections for unity post processing
Stars: ✭ 163 (-79.45%)
Mutual labels:  unity, shader, hlsl
Gpu Planetary Rendering
GPU atmosphertic scattering and planet generation in Unity 3D
Stars: ✭ 92 (-88.4%)
Mutual labels:  unity, shader, hlsl
Noiseshader
Noise shader library for Unity
Stars: ✭ 616 (-22.32%)
Mutual labels:  unity, shader, hlsl
Unityurptoonlitshaderexample
A very simple toon lit shader example, for you to learn writing custom lit shader in Unity URP
Stars: ✭ 2,988 (+276.8%)
Mutual labels:  unity, shader, hlsl
Standardgeometryshader
An example of a geometry shader with Unity's standard lighting model support.
Stars: ✭ 303 (-61.79%)
Mutual labels:  unity, shader, hlsl
Unity Ui Rounded Corners
This components and shaders allows you to add rounded corners to UI elements!
Stars: ✭ 307 (-61.29%)
Mutual labels:  unity, shader, hlsl
Kinobloom
Bloom effect for Unity
Stars: ✭ 704 (-11.22%)
Mutual labels:  unity, shader
Miniengineao
SSAO image effect from Microsoft MiniEngine, ported to Unity.
Stars: ✭ 448 (-43.51%)
Mutual labels:  unity, shader
Kvantwig
Non-realistic hair simulation in Unity
Stars: ✭ 467 (-41.11%)
Mutual labels:  unity, shader
Stablefluids
A straightforward GPU implementation of Jos Stam's "Stable Fluids" on Unity.
Stars: ✭ 430 (-45.78%)
Mutual labels:  unity, shader
Unityurpunlitscreenspacedecalshader
Unity unlit screen space decal shader for URP. Just create a new material using this shader, then assign it to a new unity cube GameObject = DONE, now you have unlit decal working in URP
Stars: ✭ 455 (-42.62%)
Mutual labels:  unity, shader

uRaymarching

uRaymarching is a raymarching shader templates using uShaderTemplate (the latest version of uShaderTemplate is included in this asset). The following functions are implemented:

  • Create a raymarching object only by writing a distance function
  • Legacy (Forward / Deferred) and UniversalRP are supported
    • HDRP will be supported in the future
  • Mixed with polygon objects
  • VR ready
  • Standard / Unlit / Transparent
  • Shadows for Directional / Spot / Point lights
  • Object-space and full-screen (full-screen is only in Legacy pipelines)

Screenshots

The following shapes are rendered in a 12-polygon cube.

Check more examples here:

Install

Please download the latest version of .unitypackage from the Releases page and extract it in your project.

How to use

  1. Select Create > Shader > uShaderTemplate > Generator in the Project view.
  2. Input Shader Name and select Shader Template from Inspector.
  3. Edit items in Conditions, Variables, Properties, Distance Function, and Post Effect.
  4. Press Export button or Ctrl + R to create shader from the Generator.
  5. Create material in the Project view (or press Create Material button).
  6. Create Cube in the Hierarchy view.
  7. Apply the generated material to the cube.

Please also see uShaderTemplate to learn the detail of shader generation function.

Inspector

The UI is generated by uShaderTemplate automatically from template files located in the Assets/uRaymarching/Editor/Resources/ShaderTemplates.

Shader Templates

  • Forward > Standard
    • The lighting is done by the same method as a standard surface shader in ForwardBase/Add pass.
  • Forward > Unlit
    • No lighting by default so you have to write output colors manually.
  • Deferred > Standard
    • The lighting is done by the same method as a standard surface shader.
  • Deferred > Direct GBuffer
    • Write values directly into GBuffers without effects like GI and LightProbe.
  • UniversalRP > Lit
    • Same lighting as the built-in Universal Render Pipelin/Lit shader.
  • UniversalRP > Unlit
    • No lighting, and same as the built-in Universal Render Pipelin/Unlit shader.

The items in Conditions and Variables are different depending on the selected template. Please see each page for further details:

Properties

This block is inserted into a Property section in a shader.

[Header(Additional Parameters)]
_Grid("Grid", 2D) = "" {}

Distance Function

Write a distance function here. The following code is the one generating the example of morphing sphere in Screenshots section in this document.

inline float DistanceFunction(float3 pos)
{
    float r = abs(sin(2 * PI * _Time.y / 2.0));
    float d1 = RoundBox(Repeat(pos, float3(6, 6, 6)), 1 - r, r);
    float d2 = Sphere(pos, 3.0);
    float d3 = Plane(pos - float3(0, -3, 0), float3(0, 1, 0));
    return SmoothMin(SmoothMin(d1, d2, 1.0), d3, 1.0);
}

Math.cginc and Primitives.cginc are included in the generated shader, so in this example some functions like RoundBox() and Repeat() come from these include files (of cource you can write them by yourself).

Post Effect

Post Effect is similar to a surface function in a surface shader. The following code is used in the hexagon-tile example in Screenshots section.

float4 _TopColor;

inline void PostEffect(RaymarchInfo ray, inout PostEffectOutput o)
{
    float3 localPos = ToLocal(ray.endPos);
    o.Emission += smoothstep(0.48, 0.50, localPos.y) * _TopColor;
    o.Occlusion *= 1.0 - 1.0 * ray.loop / ray.maxLoop;
}

RaymarchInfo is the input and the output of a raymarching calculation and this is defined in Struct.cginc.

struct RaymarchInfo
{
    // Input
    float3 startPos;    // start position of ray
    float3 rayDir;      // ray direction
    float3 projPos;     // ComputeScreenPos-applied position
    float3 polyNormal;  // normal on polygon surface
    float minDistance;  // minimum ray distance (comes from material setting)
    float maxDistance;  // maximum ray distance (changes by the raymarching setting)
    int maxLoop;        // maximum number of loop (comes from material setting)

    // Output
    int loop;           // total number of loop of the calculation (<= maxLoop)
    float3 endPos;      // last position (= surface of the distance function)
    float lastDistance; // the final distance of the raymarching
    float totalLength;  // total ray length
    float depth;        // depth (encoded)
    float3 normal;      // normal (encoded)
};

So ray.loop / ray.maxLoop is a normalized value and becomes close to 0.0 on the position where a ray reaches easily and becomes close to 1.0 when hard. So you can use it as a factor of a rechability or 1.0 - ray.loop / ray.maxLoop as an simple and a light-weight occlusion factor.

PostEffectOutput is defferent depending on the selected shader template. For example, it is an alias of SurfaceOutputStandard in Standard template. Please see the following pages for more details.

Please see each template file by clicking Edit button on the right side of the Shader Template drop-down list for more details.

Export

Press Export button or Ctrl + R to export shader. Then, press Create Material button to generate a material which uses the shader (or create a material manually from the Project pane).

Material

  • Loop
    • The maximum number of loops of raymarching in basic passes.
  • Minimum Distance
    • If the distance returned by a distance function becomes lower than this value, the loop finishes.
  • Distance Multiplier
    • This value is multiplied by the output of a distance function.
  • Shadow Loop
    • The maximum number of loops of raymarching in shadow pass.
  • Shadow Minimum Distance
    • Minimum Distance in shadow pass.
  • Shadow Extra Bias
    • Additional shadow bias to avoid shadow acne.

License

The MIT License (MIT)

Copyright (c) 2016 hecomi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].