combine 2 shaders

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Sakura37

I want to combine:
voronoi hosted at ImgBB — ImgBB and radial-gradient hosted at ImgBB — ImgBB to obtain: combined hosted at ImgBB — ImgBB

basically where the white in the radial gradient is, the voronoi shader’s form needs to be seen. Can I do that in Godot? I have the code for both shaders, I just don’t know how I can combine them .

You need to use the radial gradient as a mask for the voronoi. So by multiplying the result of the radial gradient to the voronoi, you should get only the voronoi where your gradient is.

MrEliptik | 2021-07-02 10:20

:bust_in_silhouette: Reply From: Wakatta

Shader Combinations

Create a function for both of your shaders and return the output then as MrEliptik stated multiply the results

Example

vec3 radial_gradient(){
    return output
}

vec3 voronoi(){
    #your code here
    return output
}

void fragment(){
    COLOR = voronoi() * radial_gradient()
}

Tips

  • The output var is what you would normally have in your fragment function as ABEDO = output or COLOR = output

  • If multiply gives you unusual results try also multiplying by a fraction or adding instead

  • If you’re familiar with Visual Shaders this actually gets done for you automatically and the added bonus of seeing it live to make tweaks