{"id":15025988,"url":"https://github.com/hecomi/uraymarching","last_synced_at":"2025-05-15T12:06:59.933Z","repository":{"id":40605236,"uuid":"70344937","full_name":"hecomi/uRaymarching","owner":"hecomi","description":"Raymarching Shader Generator in Unity","archived":false,"fork":false,"pushed_at":"2022-07-30T14:05:35.000Z","size":36232,"stargazers_count":1376,"open_issues_count":10,"forks_count":132,"subscribers_count":67,"default_branch":"master","last_synced_at":"2025-05-15T12:06:53.410Z","etag":null,"topics":["raymarching","shader","unity"],"latest_commit_sha":null,"homepage":"http://tips.hecomi.com/entry/2019/01/27/233137","language":"HLSL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hecomi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-08T16:49:01.000Z","updated_at":"2025-05-12T08:29:07.000Z","dependencies_parsed_at":"2022-07-14T03:50:35.230Z","dependency_job_id":null,"html_url":"https://github.com/hecomi/uRaymarching","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hecomi%2FuRaymarching","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hecomi%2FuRaymarching/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hecomi%2FuRaymarching/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hecomi%2FuRaymarching/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hecomi","download_url":"https://codeload.github.com/hecomi/uRaymarching/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254337614,"owners_count":22054254,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["raymarching","shader","unity"],"created_at":"2024-09-24T20:03:27.321Z","updated_at":"2025-05-15T12:06:54.913Z","avatar_url":"https://github.com/hecomi.png","language":"HLSL","funding_links":[],"categories":[],"sub_categories":[],"readme":"uRaymarching\n============\n**uRaymarching** is a raymarching shader templates using [uShaderTemplate](https://github.com/hecomi/uShaderTemplate). The following functions are implemented:\n\n- Create a ray-marching object **by simply writing a distance function**\n- Legacy pipelines (**Forward** / **Deferred**) and **URP** (**Forward / Deferred**) are supported\n  - HDRP is not yet supported\n- Intersects polygonal objects because it writes depth\n- VR support\n- Lit / Unlit (+ Transparent)\n- Shadows for Directional / Spot / Point lights\n- Object-space and full-screen (Full screen only for legacy pipelines)\n\n\nScreenshots\n-----------\nThe following shapes are rendered inside a 12-polygon cube.\n\n\u003cimg src=\"https://raw.githubusercontent.com/wiki/hecomi/uRaymarching/hex_floor.gif\" width=\"720\" /\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/wiki/hecomi/uRaymarching/morph.gif\" width=\"720\" /\u003e\n\nCheck more examples here:\n\n- [https://github.com/hecomi/uRaymarchingExamples](https://github.com/hecomi/uRaymarchingExamples)\n\n\nInstall\n-------\n- Unity Package\n  - Download the following .unitypackage-s.\n    - [uShaderTemplate](https://github.com/hecomi/uShaderTemplate/releases).\n    - [uRaymarching](https://github.com/hecomi/uRaymarching/releases)\n- Git URL (UPM)\n  - Add the following git URLs to Package Manager.\n    - `https://github.com/hecomi/uShaderTemplate.git#upm`\n    - `https://github.com/hecomi/uRaymarching.git#upm`\n- Scoped Registry (UPM)\n  - Add a scoped registry to your project.\n    - URL: `https://registry.npmjs.com`\n    - Scope: `com.hecomi`\n  - Install uRaymarching in Package Manager.\n\nHow to use\n----------\n1. Select *Create \u003e Shader \u003e uShaderTemplate \u003e Generator* in the Project view.\n2. Input *Shader Name* and select *Shader Template* from Inspector.\n3. Edit items in *Conditions*, *Variables*, *Properties*, *Distance Function*, and *Post Effect*.\n4. Press *Export* button or *Ctrl + R* to create shader from the `Generator`.\n5. Create material in the Project view (or press *Create Material* button).\n6. Create *Cube* in the Hierarchy view.\n7. Apply the generated material to the cube.\n\nPlease also see [uShaderTemplate](https://github.com/hecomi/uShaderTemplate) to learn the detail of shader generation function.\n\n\nInspector\n---------\n\u003cimg src=\"https://raw.githubusercontent.com/wiki/hecomi/uRaymarching/inspector.png\" width=\"720\" /\u003e\n\nThe UI is generated by [uShaderTemplate](https://github.com/hecomi/uShaderTemplate) automatically from template files located in the *Assets/uRaymarching/Editor/Resources/ShaderTemplates*.\n\n\nShader Templates\n---------------\n- **Forward \u003e Standard**\n  - The lighting is done by the same method as a standard surface shader in *ForwardBase/Add* pass.\n- **Forward \u003e Unlit**\n  - No lighting by default so you have to write output colors manually.\n- **Deferred \u003e Standard**\n  - The lighting is done by the same method as a standard surface shader.\n- **Deferred \u003e Direct GBuffer**\n  - Write values directly into GBuffers without effects like GI and LightProbe.\n- **UniversalRP \u003e Lit**\n  - Same lighting as the built-in `Universal Render Pipelin/Lit` shader.\n- **UniversalRP \u003e Unlit**\n  - No lighting, and same as the built-in `Universal Render Pipelin/Unlit` shader.\n\nThe items in *Conditions* and *Variables* are different depending on the selected template. Please see each page for further details:\n\n- **[Legacy (Forward / Deferred)](https://github.com/hecomi/uRaymarching/blob/master/Documents/Legacy.md)**\n- **[UniversalRP](https://github.com/hecomi/uRaymarching/blob/master/Documents/UniversalRP.md)**\n\n\nProperties\n----------\nThis block is inserted into a `Property` section in a shader.\n\n```shaderlab\n[Header(Additional Parameters)]\n_Grid(\"Grid\", 2D) = \"\" {}\n```\n\n\u003cimg src=\"https://raw.githubusercontent.com/wiki/hecomi/uRaymarching/property.png\" width=\"720\" /\u003e\n\n\nDistance Function\n-----------------\nWrite a distance function here. The following code is the one generating the example of morphing sphere in *Screenshots* section in this document.\n\n```hlsl\ninline float DistanceFunction(float3 pos)\n{\n    float r = abs(sin(2 * PI * _Time.y / 2.0));\n    float d1 = RoundBox(Repeat(pos, float3(6, 6, 6)), 1 - r, r);\n    float d2 = Sphere(pos, 3.0);\n    float d3 = Plane(pos - float3(0, -3, 0), float3(0, 1, 0));\n    return SmoothMin(SmoothMin(d1, d2, 1.0), d3, 1.0);\n}\n```\n\n*\u003ca href=\"Assets/uRaymarching/Shaders/Include/Math.cginc\"\u003eMath.cginc\u003c/a\u003e* and *\u003ca href=\"Assets/uRaymarching/Shaders/Include/Primitives.cginc\"\u003ePrimitives.cginc\u003c/a\u003e* 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).\n\n\nPost Effect\n-----------\n*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.\n\n```hlsl\nfloat4 _TopColor;\n\ninline void PostEffect(RaymarchInfo ray, inout PostEffectOutput o)\n{\n    float3 localPos = ToLocal(ray.endPos);\n    o.Emission += smoothstep(0.48, 0.50, localPos.y) * _TopColor;\n    o.Occlusion *= 1.0 - 1.0 * ray.loop / ray.maxLoop;\n}\n```\n\n`RaymarchInfo` is the input and the output of a raymarching calculation and this is defined in *Struct.cginc*.\n\n```hlsl\nstruct RaymarchInfo\n{\n    // Input\n    float3 startPos;    // start position of ray\n    float3 rayDir;      // ray direction\n    float3 projPos;     // ComputeScreenPos-applied position\n    float3 polyNormal;  // normal on polygon surface\n    float minDistance;  // minimum ray distance (comes from material setting)\n    float maxDistance;  // maximum ray distance (changes by the raymarching setting)\n    int maxLoop;        // maximum number of loop (comes from material setting)\n\n    // Output\n    int loop;           // total number of loop of the calculation (\u003c= maxLoop)\n    float3 endPos;      // last position (= surface of the distance function)\n    float lastDistance; // the final distance of the raymarching\n    float totalLength;  // total ray length\n    float depth;        // depth (encoded)\n    float3 normal;      // normal (encoded)\n};\n```\n\nSo `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.\n\n`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.\n\n- [Legacy (Forward / Deferred)](https://github.com/hecomi/uRaymarching/blob/master/Documents/Legacy.md)\n- [UniversalRP](https://github.com/hecomi/uRaymarching/blob/master/Documents/UniversalRP.md)\n\nPlease see each template file by clicking *Edit* button on the right side of the *Shader Template* drop-down list for more details.\n\n\nExport\n------\n\u003cimg src=\"https://raw.githubusercontent.com/wiki/hecomi/uRaymarching/export.png\" width=\"720\" /\u003e\n\nPress *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).\n\n\nMaterial\n--------\n\u003cimg src=\"https://raw.githubusercontent.com/wiki/hecomi/uRaymarching/material-properties.png\" width=\"720\" /\u003e\n\n- Loop\n  - The maximum number of loops of raymarching in basic passes.\n- Minimum Distance\n  - If the distance returned by a distance function becomes lower than this value, the loop finishes.\n- Distance Multiplier\n  - This value is multiplied by the output of a distance function.\n- Shadow Loop\n  - The maximum number of loops of raymarching in shadow pass.\n- Shadow Minimum Distance\n  - *Minimum Distance* in shadow pass.\n- Shadow Extra Bias\n  - Additional shadow bias to avoid shadow acne.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhecomi%2Furaymarching","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhecomi%2Furaymarching","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhecomi%2Furaymarching/lists"}