Skip to content

Instantly share code, notes, and snippets.

@makidoll
Last active November 5, 2024 01:19
Show Gist options
  • Save makidoll/7b048e3a3a052a94334d106d1dd2e54b to your computer and use it in GitHub Desktop.
Save makidoll/7b048e3a3a052a94334d106d1dd2e54b to your computer and use it in GitHub Desktop.
Convert GLSL to HLSL with 100% precision!

Convert GLSL to HLSL with 100% precision!

Have you tried translating GLSL code to HLSL and for some reason it never works, even through you've gone through it line by line? For example with noise functions.

Then do this!

  • Save your shader to a file and add to the top:
    #version 460
    precision mediump float;
    and make sure to add a main() function, calling your function such as:
    void main() {
      // code here so it doesn't get optimized away
    }
    
  • Download glslcc and run
    glslcc.exe --frag=shader.glsl --output=shader --lang=hlsl
  • Now you have cursed hlsl but working code! float param_1 = youreWelcome.z.xxxx
@0wwafa
Copy link

0wwafa commented Nov 5, 2024

D:\glsl-shaders\crt\shaders>I:\glslcc-1.7.6-win64\glslcc.exe --frag=crtgeom.glsl --output=CRTshader --lang=hlsl
Link failed:
ERROR: Linking fragment stage: Missing entry point: Each stage requires one entry point

@makidoll
Copy link
Author

makidoll commented Nov 5, 2024

@0wwafa did you add void main() {} with code calling to the functions you need translated? glslcc will optimize unused code away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment