Jump to content
  • Advertisement
Sign in to follow this  
faculaganymede

OpenGL Shader: Possible to mix HLSL with GLSL?

This topic is 4880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Shader Experts, Is it possible to do the following: 1. Use a shader coded in Microsoft's DirectX9 High Level Shading Language (HLSL) in an OpenGL application 2. Use a shader coded in OpenGL Shading Language (GLSL) in an DirectX application 3. Implement an OpenGL application to use a shader coded in either/both GLSL and HLSL [Edited by - faculaganymede on March 10, 2005 1:08:04 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by faculaganymede
Shader Experts,

Is it possible to do the following:

1. Use a shader coded in Microsoft's DirectX9 High Level Shading Language (HLSL) in an OpenGL application

2. Use a shader coded in OpenGL Shading Language (GLSL) in an DirectX application

3. Implement an OpenGL application to use a shader from either/both GLSL and HLSL


1. Not directly using HLSL, however you can use CG which is essentially the same language, but supports both APIs.

2. Nope, GLSL is similar to HLSL, but they are different languages. Again CG is the best option if you need cross API shaders.

3. You may be able to mix CG and GLSL in an app, but I don't think you can use them both at the same time (say a CG vs with a GLSL ps). In any case it's probably a better idea to pick one language to use for all your shaders.

Quote:

Could someone also clarify the following for me:

1. DirectX9 = DX9 ?

2. DirectX9 vs Direct3D vs OpenGL (all three are graphics APIs?)

3. ATI X800 vs ATI Radeon X800 vs ATI Radeon 9800

Many thanks in advance.


1. Yes

2. DX9 is a suite of APIs that includes D3D for graphics as well as APIs for sound, input, video, and networking. D3D and OpenGL are graphics libraries. D3D has gone through many version, of which 9 is the latest version.

3. Not sure what the question is here.

Share this post


Link to post
Share on other sites
Thanks for your reply, Solias.

The reason for questions about mixing the shader API's is because I am thinking of writing my shaders in HLSL, these shaders'll be plug-in's to someone else's application, but I am not sure what API (OpenGL or DX) their application is implemented in.

Thanks for the clarification on the graphics terms. I am pretty new to graphics and get confused by the terminologies (not clear on their differences).

Share this post


Link to post
Share on other sites
Solias:
Couldn't you just compile your shader (HLSL or GLSL) into asm and thereby creating "support" for both shader-languages? :P

Best regards,
Roquqkie

Share this post


Link to post
Share on other sites
Roquqkie:
GLSL is compiled into native GPU code, and not intermediate dx-asembler - like HLSL.

Share this post


Link to post
Share on other sites
Quote:
Original post by faculaganymede
Thanks for your reply, Solias.

The reason for questions about mixing the shader API's is because I am thinking of writing my shaders in HLSL, these shaders'll be plug-in's to someone else's application, but I am not sure what API (OpenGL or DX) their application is implemented in.


That sounds like it could be tricky. Do you have the source to this app or are you going through a plugin api? Does the app use shaders already? If so you'll probably want to use the same kind.

Quote:

Thanks for the clarification on the graphics terms. I am pretty new to graphics and get confused by the terminologies (not clear on their differences).


No problem, we've all been there at one point. Feel free to ask if you have more questions.

Quote:
Original post by Roquqkie
Solias:
Couldn't you just compile your shader (HLSL or GLSL) into asm and thereby creating "support" for both shader-languages? :P


That's more or less how CG works on opengl. It provides a compiler to convert cg code into low level opengl shader code which is accepted by the vertex and fragment program extensions. However as Stein said, GLSL works differently, it's passed directly to the driver as GLSL source. What happens after that in the driver is entirely machine dependant. You can get assembler out of HLSL using the dx runtime, but it's not the same language used by the opengl shader extensions.

Share this post


Link to post
Share on other sites
Thanks for your detailed explanations, Solias.

Quote:
Original post by Solias
That sounds like it could be tricky. Do you have the source to this app or are you going through a plugin api? Does the app use shaders already? If so you'll probably want to use the same kind.

I don't have the source to the application, it'll probably be going through a plugin api. I don't know much about it yet, other than that it already uses shaders. I also know that it runs on a PC and it "requires DX9 graphics on an ATI". Now, this is a little confusing to me. If an application requires DX9, doesn't that mean it uses DX9 API libraries rather than OpenGL? You can't mix OpenGL APIs with DX9 APIs, right?

Quote:
Original post by Solias
That's more or less how CG works on opengl. It provides a compiler to convert cg code into low level opengl shader code which is accepted by the vertex and fragment program extensions. However as Stein said, GLSL works differently, it's passed directly to the driver as GLSL source. What happens after that in the driver is entirely machine dependant. You can get assembler out of HLSL using the dx runtime, but it's not the same language used by the opengl shader extensions.

So I guess the best way to go is make my shaders in Cg since it works in both DX9 and OpenGL applications.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!