Jump to content

  • Log In with Google      Sign In   
  • Create Account

Adding shaders to an existing program


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 amtri   Members   -  Reputation: 175

Like
0Likes
Like

Posted 20 November 2013 - 10:35 AM

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.



Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 13577

Like
1Likes
Like

Posted 20 November 2013 - 03:27 PM

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 amtri   Members   -  Reputation: 175

Like
1Likes
Like

Posted 20 November 2013 - 04:11 PM

Spiro,

 

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

 

-amtri



#4 Kaptein   Prime Members   -  Reputation: 2148

Like
1Likes
Like

Posted 21 November 2013 - 08:10 AM

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


Edited by Kaptein, 21 November 2013 - 08:13 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS