Advertisement
suprecam

CHEAT SHEET - GLSL TO UNITY SHADERS

May 28th, 2020
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CONVERT FROM GLSL - TO - UNITY SHADERLAB HLSL (CG):
  2. ---------------------------------------------------
  3.  
  4. SYNTAX:
  5. -------
  6. vec<n>                  - float<n>
  7. mat<n>                  - float<n>x<n>
  8. fract                   - frac
  9. mix                     - lerp
  10. mod                     - x-y*floor(x/y)
  11. atan(x,y)               - atan2(y,x)
  12. texture                 - tex2D
  13.  
  14. TYPE CASTING:
  15. -------------
  16. vec3(1) ok              - float3(1) not ok, float3(1,1,1) or 1
  17. vec3 a = 1 not ok       - float3 a = 1 ok
  18.  
  19. INITIALIZED GLOBAL VARIABLES:
  20. -----------------------------
  21. vec3 up = vec3(0,1,0)   - static float3 up = float3(0,1,0)
  22.  
  23. MATRIX MULTIPLICATION:
  24. ----------------------
  25. use *                   - use mul()
  26.  
  27. SPECIFICS:
  28. ----------
  29. MAIN FUNCTION   - mainImage             - frag or surf
  30. UV COORDS       - fragCoord/iResolution - i.uv or IN.uv_MainTex
  31. TIME            - iTime                 - _Time.y
  32. MOUSE           - iMouse                -                           *Must manually add*
  33. FINAL COLOR     - fragColor = color     - return color
  34. TEXTURES        - iChannel<n>           -                           *Must manually add*
  35. BOILERPLATE     - None                  -                           *Many*
  36.  
  37. ***
  38. ***  Additional trick: instead of  replace "vec" with "float" ,  in HLSL we can define own data types,
  39. ***  so you can write following instruction: typedef vector ** <float, 2> vec2; typedef vector <float, 3> vec3;
  40. ***
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement