Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Featured Threads
  inspiration alert!!!
(36 replies)
  Indespensible MaxScripts, Plugins and 3rd Party Tools
(37 replies)
  The allmighty FREE Resources Thread !
(17 replies)
  spam alert!!!
(4886 replies)
  Maxforums member photo gallery index
(114 replies)
  Maxforums Member Tutorials
(89 replies)
  three cheers to maxforums...
(240 replies)
  101 Things you didnt know in Max...
(198 replies)
  A Face tutorial from MDB101 :D
(95 replies) Members Gallery
(516 replies)
(637 replies)
  Dub's Maxscript Tutorial Index
(119 replies)

Maxunderground news unavailable

why glsl or hlsl over cpp?
show user profile  digs
I know a few ppl here are pretty savvy in this subject, and I'm having trouble finding answers on the inter-tubes (plz correct me if im wrong on anything)

i know that hlsl is a microsoft specific graphics programming language for directx

and glsl is a cross-platform language for opengl

and often, people will program in hlsl for directx, then cross compile into glsl for other platforms

but i wonder, why do we choose one of these languages over cpp?
read 802 times
1/25/2016 6:34:18 PM (last edit: 1/25/2016 6:37:14 PM)
show user profile  Garp
By cpp, do you mean C++?

read 792 times
1/25/2016 6:51:10 PM (last edit: 1/25/2016 6:51:10 PM)
show user profile  digs

from what i understand shaders can also be programmed in cpp (c++)... i was under the impression that most common programming languages were a derivative of c

a friend and I were talking about this and he suggested that perhaps hlsl and glsl are more "light weight" compared to c++?
read 753 times
1/25/2016 8:07:17 PM (last edit: 1/25/2016 10:43:28 PM)
show user profile  ScotlandDave
Shader programs are written in those specific languages because that's what the hardware drivers for your gpu can understand. But you can write software in any language (C++ for example) that will output stuff to the gpu, as long as it can create shaders in those formats (hlsl etc) and bind them to the gpu..

Beyond that, in terms of writing the actual shaders in other languages, you'd basically be looking at reinventing the wheel and creating alternative drivers etc..

Website | Blog | Contact | Vimeo

read 709 times
1/25/2016 11:43:40 PM (last edit: 1/25/2016 11:43:40 PM)
show user profile  digs
questions overload

that makes sense, so, they are languages that have been refined to preform specific tasks? ie, they essentially do the same thing c++ can do, but they do it faster maybe? for the gpu?

drivers in the gpu have been written to take in (hlsl or glsl) and process the code faster?

wait, so are drivers like little cross compilers?

could you theoretically create game logic or computer ai in hlsl and just never use c++? (theoretically)

I think i need to research how programming languages are created.

i hope you don't mind if i vomit questions in here

read 692 times
1/26/2016 12:47:13 AM (last edit: 1/26/2016 3:39:31 AM)
show user profile  ScotlandDave
Yeah the drivers have the compilers in them. So your C++ application for example feeds the gpu driver with GLSL ( or HLSL ) shaders by leveraging the OpenGL ( or DirectX ) API , and the drivers gobble them up and put some stuff on the screen.

Traditionally shaders perform really specific tasks, and do really specific maths operations and so are constructed that way. They are limited to specific operations and specific input/output variables also so they can run massively parallel on a gpu. So for example you have a Vertex shader that takes specific inputs ( like a vertex xyz position and transform matrix ), then does a specific calculation on those inputs and sends them to the outputs. So the Vertex shader spawns itself a bazillion times inside the gpu, across all of it's cores, and simultaneously does it's calculations on a bunch of verts at the same time, and the outputs from it then directly update the gpu vertex buffer and what you see on screen changes.

There are other types of shaders ( called stages i think ) besides Vertex shaders, such as Geometry shaders, Fragment shaders, etc, that do different things at different points in the rendering pipeline. The newer shader types are more open to manipulation and so can be used for other tasks besides just vertex/geometry operations. So you can have for example a TransformFeedback shader that is hijacked to perform GI calculations or a shader that does the donkey work in video encoding - which is the basis of how GPU's are used for other stuff besides just putting stuff on the screen.

I suppose in that sense shaders could be manipulated into doing the kind of stuff you said, but because they have to run massively parallel they are also limited in the type of operations they can do. So generally, you need a host/control application written in C++ or whatever which oversees everything, and farms out the donkey-work/number-crunching to the gpu whenever possible.

I'm by no means an expert in the subject btw, but i'll answer any questions i can.

Website | Blog | Contact | Vimeo

read 685 times
1/26/2016 1:38:27 AM (last edit: 1/26/2016 1:38:27 AM)
show user profile  digs
that brings up another question i was going to ask earlier, (sidetrack) regarding api's, ide's, and sdk's...... ive been heavy on the googles so plllleease correct me if i don't have this, but can all of these things be thought of like:

an ide is something like visual studio, or perhaps 3ds max, or windows... and it can contain many different api's... and an sdk is something that allows you to modify an ide?

could a plugin for 3ds max be considered an api? like fume fx, or something random off sciptspot?



So, the opengl api (for example) takes our high level code such as glsl or c++ and converts it to machine code, then passes that machine code to the gpu... and we do these calculations in the gpu instead of on the cpu because the gpu has thousands of cores to do the callculations on? is that correct? ((i realize now that i really have no idea what a core is or how it works. I know instructions (the machine code?) are sent to it, and then calculations happen, and then machine code leaves the core and gooeessss... : / someplace ))

thanks again, and if you haven't answered a question directly than you are certainly giving more questions to think about which is really helpful

some of these things are just questions i've had for a very long time, or am vaguely familiar with and I'd like a deeper understanding of

and what's the saying: if you're thinking about asking it, someone else probably is too. I think it would be cool to have more open forums like this, for people to dump questions into

*edit* found this helpful

read 672 times
1/26/2016 4:48:56 AM (last edit: 1/26/2016 8:22:56 AM)
show user profile  ScotlandDave
Morning - to answer some of your questions:

An IDE ( IntegratedDevelopmentEnvironment ) is the application itself that is used to develop and compile/run code projects. Like VisualStudio for example.. Max isn't really an ide, although it does has the Script Editor etc for developing maxscripts..

An API ( Application Programming Interface ) is basically a coding framework that allows a programmer to have access to the functionality of other software or code. So for example, the Maxscript API provides a bunch of code functions and properties that expose the inner working of Max, and allows user to write that code to produce functionality. The Max C++ API is another similar example. Often an API is found in an SDK ( Software Development Kit ). An SDK generally includes the API libraries, header files, code examples and documentation for the API. For example when coding stuff for GPU leveraging Nvidia Cuda, you download the Cuda SDK and use the Cuda API from within Visual Studio - so you build an application for example in C++ and use the functions etc in the Cuda API to get access to Cuda functionality, and compile and run the app from VisualStudio when testing.. The Cuda lib/api basically exposes some of the stuff that's in the gpu drivers. OpenGL does a similar thing. I've used the Cinema4D C++ and Python SDK/API's to create plugins for C4D is another example..

There are libraries ( api's ) for libraries also. For example to make writing code for a specific platform easier or to streamline development. An example of this is GLEW and GLFW for creating OpenGL applications - OpenGL is quite low level and can involve a lot of setup and a ton of code just to do basic stuff, so what GLFW does is makes something like creating an OpenGL context and opening a window and putting 3D stuff in it possible in just a few lines of code. So basically it wraps a whole lot of OpenGL api stuff in some easily accessible function calls. GLEW does a similar task, it helps to write software that runs across various platforms and OpenGl versions, it does a lot of the donkey work detecting versions and switching on/off functionality so you app runs well on different systems. Another example is Xamarin which is a paid-for IDE and API that makes it much simpler to write and deploy games and apps across different mobile devices ( Apple, iOS, Android, etc ) - so it does all the donkey work behind the scenes and you have much less code to write..

So, the opengl api (for example) takes our high level code such as glsl or c++ and converts it to machine code, then passes that machine code to the gpu... and we do these calculations in the gpu instead of on the cpu because the gpu has thousands of cores to do the callculations on? is that correct?

Yeah pretty much. CPU's cores are much more complex as they have to do more stuff and hold larger more complex datasets etc, but GPU cores are much more streamlined and many more of them can be crammed onto a chip, hence why there's so many of them compared to cpu's.. The opengl API doesn't 'convert' the high-level code as such btw, it just allows access to the functionality within the gpu drivers so that the high-level code can talk to the GPU.

Hope that's useful..

Website | Blog | Contact | Vimeo

read 639 times
1/26/2016 10:51:35 AM (last edit: 1/26/2016 10:51:35 AM)
show user profile  LionDebt
If you're interested in dipping your toes into writing your own shaders... Unity has it's own 'language' called ShaderLab which gives you a pretty neat insight into developing surface / vertex shaderz.
read 631 times
1/26/2016 12:15:21 PM (last edit: 1/26/2016 12:15:21 PM)
show user profile  digs
@dave, yea man, super helpful.. ive been digesting this all day, luckily im rendering today so there's lots of time for research, i have more questions but i want to do some research first

@ld, Yea! I've recently gotten back into shader code, hlsl now. My last "day job" was as a unity game developer, and about 2 months before i left for my current job, i began shader programming in unity using cg
read 606 times
1/26/2016 8:12:58 PM (last edit: 1/26/2016 8:21:25 PM)
show user profile  digs
thanks again dave, your detailed explanation was a HUGE help for me

most of the references and examples of api's i was finding out there were all about, amazon api, facebook api, twitter api... this only really confused me because i was trying to make a link between the facebook api and the directx api, like, they're both api's, so they must have something in common

I tend to over complicate things when im trying to understand something better

there is still one thing im not 100% clear on

another friend of mine described an api as being "compiled code that you can't edit, but you can use"

this is like, mul(x, y)

someone else has taken the time to create a mul function that I can now use to simplify the process.

so, could i then create a simple api that generates coordinates for a cube, then randomly places that cube in 3d space? could that be considered an api? for example, all you would need to do is use the function CreateDaCube(), and my api would create the cube for you

if so, do you add my api to your project, and access it through a preprocessor directive or namespace? im not clear on how someone would "load" an api into their project and use it
read 581 times
1/27/2016 4:37:50 PM (last edit: 1/28/2016 6:01:15 AM)
show user profile  ScotlandDave
That's an interesting question, what's the difference between an API and a Library, and what classifies as an API..

Regards your example, i'd say yeah if you created some functionality, created some 'public' headers for it so it can be accessed, and wrapped it up as a .lib or .dll file then yeah i'd say it was both an API ( because it was accessible ) and a library ( because it's a compiled library ).

Regards your friend saying that an api is compiled code that you can't edit. That's true in some cases and not true in others. Some API's also provide the source code so that you can edit it and recompile the lib yourself if need be. Some only provide the lib files themselves and the header files so it's accessible/usable but you can't edit it..

So regards how do you add an api to another project. It depends on the IDE but there are a lot of similarities i think. I use visual studio and generally, you provide paths in your Project Properties to external libraries ( ie the .lib files themselves ) and also paths to the include files for the libs ( the .h header files - the compiler needs these up from so that it knows what stuff to refer to when it's reading through the actual code ). Some API's use CMake, which is a piece of software that generates project files for the API for various platforms, ie it can be set up to create a project setup for VisualStudio with all the dependencies etc already setup and ready to go, just crack open the solution file and edit/compile the project or whatever..

You mentioned namespace and preprocessor directives. Namespaces are just a way to more quickly refer to external code within your code. Preprocessor directives are just switches that are sent to the compiler to tell it stuff, some api's require these to be defined but normally they'll be specific to your project and already handled before the api's lib was compiled..

Website | Blog | Contact | Vimeo

read 552 times
1/28/2016 11:26:36 AM (last edit: 1/28/2016 11:26:36 AM)
#Maxforums IRC
Open chat window