x


Can i use of HLSL or GLSL shaders in unity?

Can i use of HLSL or GLSL shaders in unity?

If yes How?

thanks.

more ▼

asked Nov 18 '09 at 11:46 AM

Hamzeh Shabani gravatar image

Hamzeh Shabani
174 5 7 11

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

In addition to the above posts, Shader Lab handles a lot of the low level common functions of the graphics pipeline. If you want to create vertex or pixel shaders, they must be done in either Cg or GLSL.

Cg is probably the best way to go due to the fact it compiles for both OpenGL and DirectX, and it's language syntax is very similar to HLSL. To learn CG, I recommend "The Cg Tutorial", which is available for free online here : http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter01.html

Like mentioned above, the best way to learn how to use Cg and ShaderLab together is to go through the provided shader code for the builtin shaders. You will find all the Cg code between the "CGPROGRAM" and "ENDCG" lines. All code outside of those tags is ShaderLab code.

more ▼

answered Nov 22 '09 at 02:39 AM

Murcho gravatar image

Murcho
2.7k 12 23 53

(comments are locked)
10|3000 characters needed characters left

Unity provides a language called "ShaderLab" which is similar to Nvidia's CgFX. You can use this to write custom shaders including vertex & fragment programs.

Read more about it in the Unity reference manual here: http://unity3d.com/support/documentation/Components/SL-Reference.html

A good way to start off is to have a look at the source code for Unity's built-in shaders, which you can download here: http://unity3d.com/download_unity/builtin_shaders.zip

Or check out the custom shaders that people have put up on the Unity Wiki, here: http://www.unifycommunity.com/wiki/index.php?title=Shaders

more ▼

answered Nov 18 '09 at 11:57 AM

duck gravatar image

duck ♦♦
41k 92 148 415

oh thanks for your answers.

Nov 18 '09 at 02:25 PM Hamzeh Shabani

Please remember to use the "accept" button (the tick next to the answer)

Apr 16 '10 at 12:11 PM duck ♦♦
(comments are locked)
10|3000 characters needed characters left

You can use GLSL shaders in Unity (docs), but they are specific to OpenGL, so you cannot use them on DirectX targets. HLSL is not supported.

The recommended language to write shader programs in is Cg.

more ▼

answered Nov 18 '09 at 12:54 PM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.7k 7 23 102

Well, for all practical purposes Cg is the same as HLSL.

Nov 18 '09 at 03:01 PM Aras ♦♦
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1651

asked: Nov 18 '09 at 11:46 AM

Seen: 8667 times

Last Updated: Nov 18 '09 at 11:46 AM