• Stars
    star
    1,263
  • Rank 37,244 (Top 0.8 %)
  • Language GLSL
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Convert ShaderToy to Unity HLSL/CG

ShaderMan

ShaderToy to ShaderLab Converter

If you’ve tried dabbling with shaders at all, you’ve probably come across ShaderToy – an online shader showcase with some pretty amazing examples of what’s possible in a few lines of shader code, inspired greatly by classic demoscene coding. Here’s just two examples: https://www.shadertoy.com/view/4dl3zn

It’s an amazing resource, not only for inspiration but for learning how to create shaders, since every example comes with full source code which you can edit and immediately test online in your browser, alter parameters, supply different inputs etc.

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.

Microsoft have published a very useful reference guide here which details many of the general differences between GLSL and HLSL. Unity also have a useful page here.

    Replace iGlobalTime shader input (“shader playback time in seconds”) with _Time.y
    Replace iResolution.xy (“viewport resolution in pixels”) with _ScreenParams.xy
    Replace vec2 types with float2, mat2 with float2x2 etc.
    Replace vec3(1) shortcut constructors in which all elements have same value with explicit float3(1,1,1)
    Replace Texture2D with Tex2D
    Replace atan(x,y) with atan2(y,x) <- Note parameter ordering!
    Replace mix() with lerp()
    Replace *= with mul()
    Remove third (bias) parameter from Texture2D lookups
    mainImage(out vec4 fragColor, in vec2 fragCoord) is the fragment shader function, equivalent to float4 mainImage(float2 fragCoord : SV_POSITION) : SV_Target
    UV coordinates in GLSL have 0 at the top and increase downwards, in HLSL 0 is at the bottom and increases upwards, so you may need to use uv.y = 1 – uv.y at some point.

Note that ShaderToys don’t have a vertex shader function – they are effectively full-screen pixel shaders which calculate the value at each UV coordinate in screenspace. As such, they are most suitable for use in a full-screen image effect (or, you can just apply them to a plane/quad if you want) in which the UVs range from 0-1.

But calculating pixel shaders for each pixel in a 1024×768 resolution (or higher) is expensive. One solution if you want to achieve anything like a game-playable framerate is to render the effect to a fixed-size rendertexture, and then scale that up to fill the screen. Here’s a simple generic script to do that:

Demo

https://www.youtube.com/watch?v=ZncPTfT8wLg


How to use:

1.copy your lovely shader from www.shadertoy.com

ShaderToy

2.Open ShaderMan from Tools\ShaderMan

before opening shaderman be sure that there is codegenerator.cs in scene otherwise ShaderMan throws NullReferenceException.

3.Choose Name for you shader:

Step

4.Import your shader from shaderToy.com

Step

5.Click On Convert And Enjoy :D

Final Step


Video Tutorial is Available

capturedwadad

https://www.youtube.com/watch?v=MCER5P8Xz3w&lc=z22ysdkqln2texqj004t1aokgkzlpvkn3rdybfw1wtugrk0h00410


Musual

Music Visualization Shader

Musual

https://github.com/smkplus/Musual

https://youtu.be/ppSjyvxR8uI

More Repositories

1

CustomToolbar

CustomToolbar
C#
436
star
2

Iridescence

Iridescence shader
ShaderLab
150
star
3

UnityRayMarching

Unity Raymarching Examples
GLSL
75
star
4

Musual

Music Visualization Shader
C#
71
star
5

KamaliDebug

Easy way to Debug Colorful texts in Unity Console
C#
68
star
6

ShaderBooks

ShaderBooks
59
star
7

Divinity-Origin-Sin-2

Implement the famous game shaders
ShaderLab
48
star
8

CyberPunkEffect

ShaderLab
44
star
9

KamaliTransition

Unity Shader transition between panels
C#
43
star
10

UIBlur

UI Blur Shader
ShaderLab
42
star
11

RainFX

Natural Rain
C#
34
star
12

SimpleLiquid

ShaderLab
29
star
13

WetShader

Wet Shader
ShaderLab
25
star
14

ShaderInDepth

Shader Examples
C#
24
star
15

Quantum-break

Quantum-break Shaders Tutorial
ShaderLab
23
star
16

RainDrop

ShaderLab
22
star
17

KamaliSplashScreen

KamaliSplashScreen
ShaderLab
16
star
18

CurveAnimationStoreInRuntime

C#
15
star
19

KamaliDissolve

HLSL
13
star
20

FurShader

Fur Shader
ShaderLab
13
star
21

Welding

C#
9
star
22

Reaction-Diffusion

Reaction Diffusion
C#
7
star
23

Unity-Design-Pattern

Unity Design Pattern
C#
6
star
24

KnifeHit

Simple Multiplayer game with WebsocketSharp(working progress...)
C#
6
star
25

KamaliTutorials

5
star
26

DifferenceShader

DifferenceShader
C#
4
star
27

VFX

C#
4
star
28

PhotonExamples

photon examples for beginners
C#
4
star
29

TheBookofShadersForUnity

Shader Examples Using Visual Shader Editor(ShaderGraph & ShaderForge)
ShaderLab
3
star
30

3DMorpher

Morph 3D model to another models
ShaderLab
3
star
31

LSystem-Unity

An L-system or Lindenmayer system is a parallel rewriting system and a type of formal grammar.
C#
3
star
32

MyResume

https://smkplus.github.io/MyResume/
HTML
2
star
33

Snooker.io

Snooker.io
JavaScript
2
star
34

ZLab

ZTEST & ZWrite Laboratory
ShaderLab
2
star
35

FartMan

FartMan is a real hero because he saves a lot of people with his special powers. He is the strongest man in the world. He also has to fight with criminals who are after his powers. That's why he is a big hero for a lot of people.
C#
2
star
36

BilliardNetwork

Forge Network
C#
1
star
37

FlamingCore

C#
1
star
38

smkplus

1
star
39

UvPainter

Painting on uv by Raycasting
C#
1
star
40

Persian-Text-to-Speech-Unity

Persian Text to Speech Unity
C#
1
star
41

Car-warriors

Indie GameDev
C#
1
star
42

MyUniversityProjects

My Universiy Projects
Java
1
star
43

HoudiniPractice

HoudiniPractice
1
star