Using high-version GLSL in Unity

Viewed 51

I have a lot of GLSL shaders which I am trying to get working in Unity. So I made a simple test-shader (copied from an example) that works fine in Unity:

GLSLPROGRAM 

#ifdef VERTEX 
   void main()
   {
      gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
   }
#endif 

#ifdef FRAGMENT             
   void main() 
   {
      gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); 
   }
#endif 

ENDGLSL  

The problem is now that I need to use a higher GLSL version. For that I include the version directive #version 450, which results in error C7616: global variable gl_Vertex is removed after version 140. So I tried to adapt the code to modern GLSL standards:

GLSLPROGRAM 

#version 450 

#ifdef VERTEX 
   layout(location = 0) in vec4 pos;

   void main()
   {
      gl_Position = gl_ModelViewProjectionMatrix * pos;
   }
#endif 

#ifdef FRAGMENT         
   out vec4 FragColor;

   void main() 
   {
      FragColor = vec4(1.0, 0.0, 0.0, 1.0); 
   }
#endif 

ENDGLSL 

There is no error, but it produces wrong coordinates for gl_Position that are all over the place. I assume that the layout(location = 0) in vec4 pos doesn't work like that with Unity, but I don't know how to fix it.

I know that I could translate to HLSL, but it would be nice if I could use my all of my GLSL shaders directly without a translation step.

0 Answers
Related