GithubHelp home page GithubHelp logo

chenf33 / unity-raymarching-framework Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jiepengtan/unity-raymarching-framework

0.0 2.0 0.0 1.67 MB

A framework to easy implement raymarching in unity. Include lots of hash,noise,fbm,rotate functions

License: MIT License

C# 10.11% GLSL 25.18% ShaderLab 26.87% HLSL 37.84%

unity-raymarching-framework's Introduction

Unity-Raymarching-Framework

A framework to easy implement raymarching in unity. Include lots of hash,noise,fbm,SDF,rotate functions,most of them come from shadertoy,with this library,you can easy write raymarching shader in unity without rewrite the noise function again.

also,this framework provide a easy way to merge your raymarching scene with unity scene.

Include Noise:

1.PNoise :Perlin Noise
2.VNoise :Value Noise
3.SNoise :Simplex Noise
4.WNoise :Worley Noise (Voronoi)
4.TNoise :TriNoise

Hash

// x out, x in...
HashXX
eg: float2 Hash22(float2 p)
means 2 in 2 out

FBM

float FBM( float2 p )
float FBM( float2 p,float iterNum)

Rot:

Rot2D
Rot3D

With this framework,you can easy merge raymarching scene with Unity ,and easy to walk around in it ,without rewrite a "SetCamera" function to init ro,rd variable.

Here is a example:

Shader "FishManShaderTutorial/RaymarchMergeExample" {
    Properties{
        _MainTex("Base (RGB)", 2D) = "white" {}
    }
    SubShader{
        Pass {
            ZTest Always Cull Off ZWrite Off
            CGPROGRAM
#pragma vertex vert   
#pragma fragment frag  
#include "ShaderLibs/Framework3D.cginc"
            float4 ProcessRayMarch(float2 uv,float3 ro,float3 rd,inout float sceneDep,float4 sceneCol)  {
                float3 col = float3(0.,0.,0.);
                float3 n = float3(0.,1.0,0.);
                float t = sceneDep + 10;
                float occ = 0.;
                float3 sc =  float3(0.,0.5,0.);
                float3 sr = 0.5;
                float3 ce = sc - ro;
                float b = dot( rd, ce );
                float tt = sr*sr - (dot( ce, ce )- b*b );
                if( tt > 0.0 ){
                    t = b - sqrt(tt);
                    float3 p = ro+t*rd;
                    col = 0.5+0.5*cos(2.*PI*(float3(1.,1.,1.)*p.y*0.2+float3(0.,0.33,0.67)));
                }
                MergeRayMarchingIntoUnity(t,col, sceneDep,sceneCol);
                return float4(col,1.0);
            } 
            ENDCG
        }//end pass
    }//end SubShader
    FallBack Off
}

More examples:

unity-raymarching-framework's People

Contributors

jiepengtan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.