Skip to main content
gamedev.net
🔒 Locked

Cross Platform Shaders

Started by Shael Sep 16, 2010 at 3:48 AM 5 replies 1.5k views
Original Post
Shael
Shael
I'm just wondering what everyone else is doing to make their shaders cross platform. Do a lot of people use Cg/CgFX? or do they make shaders for both GLSL and HLSL then ship whichever for whatever platform it will be run on.

I'm trying to make my engine cross platform and am tinkering on the idea of using Cg but I've never used it before (mostly just used HLSL/DX). Are they any big reasons why I shouldn't use Cg?

Cheers.
Shael
Shael
*bump*

I'm surprised no one has anything to say about this topic :/
swiftcoder
swiftcoder
Quote:
Original post by Shael
I'm surprised no one has anything to say about this topic :/
Perhaps only marginally on topic, but here goes:

If you only have familiarity with Direct X/HLSL/Windows, then why are you developing a cross-platform engine? In fact, why are you writing an engine at all, especially if you haven't finished writing the game?

Engines grow out of game requirements (not the other way round), and cross-platform engines generally grow out of a single-platform game/engine. It seems to me you may be putting the cart before the horse.

Or, in other words, if you had experience with OpenGL/GLSL, or cross-platform game engines in general, you would already know the answer [smile]
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
Asem
Asem
It's really up to you. Cg/CgFx are an option as well as GLSL. Cg/CgFx I think (I don't really use Cg) would work if your were to use them under D3D or Opengl. GLSL would only work with opengl but opengl is a graphics api that can do cross-platform anyway so I wouldn't see a problem using it. I currently program using opengl and glsl which is good and doesn't get in the way when I want to present it to peers who mostly use linux/mac since I develop in windows.
MJP
MJP
Writing shaders once and compiling as either HLSL or Cg works just fine, with a couple of #defines for a few cases. Or at least, as long as you don't need to use effects framework or CgFX.
Shael
Shael
Quote:
Original post by swiftcoder
Quote:
Original post by Shael
I'm surprised no one has anything to say about this topic :/
Perhaps only marginally on topic, but here goes:

If you only have familiarity with Direct X/HLSL/Windows, then why are you developing a cross-platform engine? In fact, why are you writing an engine at all, especially if you haven't finished writing the game?

Engines grow out of game requirements (not the other way round), and cross-platform engines generally grow out of a single-platform game/engine. It seems to me you may be putting the cart before the horse.

Or, in other words, if you had experience with OpenGL/GLSL, or cross-platform game engines in general, you would already know the answer [smile]


I am mostly familiar with DirectX and Windows but I have also worked with OpenGL and Linux in the past; MacOS is something I want to look into in the future. This engine is a learning project so making it cross platform allows me to delve into other platforms and learn about them, rather than being confined to one API and one OS. But anyway, I just wanted to know what peoples thoughts were on Cg.

I think I'm gonna go with Cg. After looking at the examples and documentation it looks pretty easy to use and will support multiple platforms. The bonus is that the Cg shader language is very similar to HLSL so I don't have to rewrite any of my current shaders - just some minor modifications.

swiftcoder
swiftcoder
Quote:
Original post by Shael
But anyway, I just wanted to know what peoples thoughts were on Cg.
My experience is that it tends to lag a little behind GLSL/HLSL in features, and it has tended to perform considerably worse on non-NVidia graphics cards - though I understand that it has improved on both counts lately. Whether either of those is problematic for you depends heavily on exactly what you are trying to do with it.
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.