Adding shaders to an existing program

Started by
2 comments, last by Kaptein 10 years, 4 months ago

Hello,

I have a very large OpenGL application that doesn't use shaders. We use almost all the non-shader gl functionality in this application. We recently found the need to add some functionality for which we will need to add shaders.

My question: if I add shaders do I have to recreate all the functionality I already have (it's a lot!) just to be able to add one more piece of functionality? It feels almost like rewriting the entire code again. For example, lighting and texturing.

Thanks.

Advertisement

With shaders, vertices are not transformed via the model-view-projection matrix, so you will have to manually create one and transform the vertices yourself.

Lighting is not done for you, so you will need to write your own lighting equations and send your own lighting data.

Textures are not applied for you. You need to sample them manually in the pixel shader.

Fog is not done for you. You need to write your own equation and send the parameters manually to the shaders.

The list continues.

Basically, unless you already keep copies of all of these parameters (light data, fog data, etc.) (and you should be), you will need to gut a large amount of your existing code to prepare the data for the shaders and then write all the shaders from scratch to replicate any existing functionality needed in addition to the new feature you want to add.

In addition to making a framework for working with shaders in general (compiling them, linking them, applying them, setting uniforms, etc.)

You may need to write your own matrix math routines or get them online.

It may make more sense to re-write an entirely shader-based solution despite the amount of work entailed, but at the end of the day the fixed-function pipeline is universally deprecated for a reason, and from a design/organisation/consistency standpoint the worst-possible case is to have a mix of fixed-function and programmable-pipeline—you may as well join us in the 21st century and go full-on shader-based.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Spiro,

Thanks for your comments. That's exactly what I was afraid of.

-amtri

Spiro,

Thanks for your comments. That's exactly what I was afraid of.

-amtri

On the bright side, once you get the hang of it - it's a fairly easy and standard process for most shaders

and, you'll never want to go back!

All those fancy things you see in all the other games out there are within your grasp smile.png

And there are many many tutorials for getting started with shaders.

Edit: If you get stuck on anything with either creating or loading shaders just write up a post with the specific issue

This topic is closed to new replies.

Advertisement