Ludvig Lindqvist: Sketch #20 WIP

Sure!

The basic approach is to replace GLSL keywords to HLSL in the functions.

A few examples taken from ShaderMan (which is a Unity script that converts whole shaders):

Replace mix() with lerp()
Replace vec2 with float2
Replace mat2 with float2x2
Replace mod with fmod
etc..

To see more keywords that needs to be replaced, you can refer to the ShaderMan script on Line 110 onwards. Basic description of the ShaderMan tool:

The shaders exhibited on ShaderToy are exclusively written in GLSL, and run in your browser using WebGL.I write an automatic conversion tool to turn a GLSL shader into an HLSL shader that help you fast convert ShaderToy to ShaderLab unity.

Simple example on this circle shader
Untitled4
Replace all vec2 to float2

Then put that new (translated) code function in a .cginc file in your project and include that in either ShaderForge or your shader. Then you should be able to use the function circle(uv, pos, rad) to make a circle. Amplify can also include .cginc files.
If you are writing your own shader and want to use any functions from a custom cginc file, you add this to it:

#include "file.cginc"

I made a basic network where I use the circle function in my .cginc file


and this is the result:
10_circle

Hope that helps.

Please keep in mind the copyright terms of content on ShaderToy.

3 Likes