Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I define function through my SFN_Nodes? #2

Open
smkplus opened this issue May 11, 2018 · 3 comments
Open

How can I define function through my SFN_Nodes? #2

smkplus opened this issue May 11, 2018 · 3 comments
Labels

Comments

@smkplus
Copy link

smkplus commented May 11, 2018

Hi Holmer
I love shaderforge and I like to Improve your repository :)

Shader Forge has a problem... It generate All shader Inside fragment shader
without declaring functions
It makes hard to reading shader
It create repetitive definitions in the shader

for example when I use Rotator Instead of declaring function It will generate Inside of fragment shader

float2 node_5074 = (mul(i.uv0-node_5074_piv,float2x2( node_5074_cos, -node_5074_sin, node_5074_sin, node_5074_cos))+node_5074_piv);

You could define it as Rotation function:

float2x2 rotate2d(float _angle){
    return float2x2(cos(_angle),-sin(_angle),
                sin(_angle),cos(_angle));
}

I'm working on procedural generation

procedural

Shader "Hidden/Shader Forge/SFN_FBMNoise" {
    Properties {
        _OutputMask ("Output Mask", Vector) = (1,1,1,1)
        _XY ("XY", 2D) = "black" {}
    }
    SubShader {
        Tags {
            "RenderType"="Opaque"
        }
        Pass {
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #define UNITY_PASS_FORWARDBASE
            #include "UnityCG.cginc"
            #pragma target 3.0
            uniform float4 _OutputMask;
            uniform sampler2D _XY;

            struct VertexInput {
                float4 vertex : POSITION;
                float2 texcoord0 : TEXCOORD0;
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
                float2 uv : TEXCOORD0;
            };
            VertexOutput vert (VertexInput v) {
                VertexOutput o = (VertexOutput)0;
                o.uv = v.texcoord0;
                o.pos = UnityObjectToClipPos(v.vertex );
                return o;
            }


            // Author @patriciogv - 2015
            // http://patriciogonzalezvivo.com

            float random (in float2 st) {
            return frac(sin(dot(st.xy,
                                float2(12.9898,78.233)))*
                43758.5453123);
            }

            // Based on Morgan McGuire @morgan3d
            // https://www.shadertoy.com/view/4dS3Wd
            float noise (in float2 st) {
            float2 i = floor(st);
            float2 f = frac(st);

            // Four corners in 2D of a tile
            float a = random(i);
            float b = random(i + float2(1.0, 0.0));
            float c = random(i + float2(0.0, 1.0));
            float d = random(i + float2(1.0, 1.0));

            float2 u = f * f * (3.0 - 2.0 * f);

            return lerp(a, b, u.x) +
                    (c - a)* u.y * (1.0 - u.x) +
                    (d - b) * u.x * u.y;
            }

            #define OCTAVES 6
            float fbm (in float2 st) {
            // Initial values
            float value = 0.0;
            float amplitude = .5;
            float frequency = 0.;
            //
            // Loop of octaves
            for (int i = 0; i < OCTAVES; i++) {
                value += amplitude * noise(st);
                st *= 2.;
                amplitude *= .5;
            }
            return value;
            }

            float4 frag(VertexOutput i) : COLOR {


                // Read inputs
                float4 _xy = tex2D( _XY, i.uv );

                // Operator

                float2 st =_xy;

                float3 color = float3(0,0,0);
                color += fbm(st*3.0);

                float4 outputColor = float4(color,1.0);
                // Return
                return outputColor * _OutputMask;
            }
            ENDCG
        }
    }
}

But What Is my problem?

My Problem Is that I can't add functions through mySFN_FBMNoise.cs and I have to convert them to variables!!

@smkplus smkplus changed the title How can I define function In shaderforge? How can I define function through my SFN_Nodes? May 11, 2018
@bajacondor
Copy link

Hello @smkplus, I'm working on a similar issue. I would like to create various noise nodes for ShaderForge. Did you ever solve this? I would love to hear of your progress on this issue.
Thank you for any response!!

@smkplus
Copy link
Author

smkplus commented Feb 5, 2023

@bajacondor you can create the custom nodes, bro
I shared the shader

@bajacondor
Copy link

@smkplus,

Yes, thank you. But how do you get the node to use it with ShaderForge? In your picture, you are still using the Rnd output which seems to be a single component, like Holmer's noise node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants