Results 1 to 3 of 3

Thread: multiple light sources each with their own shader

  1. #1
    Member Newbie
    Join Date
    Sep 2014
    Posts
    33

    Question multiple light sources each with their own shader

    hi, ive created quite a few library functions for creating linked lists with models loaded by assimp and i understand the basic lighting models. i want to, for convenience, be able to create one shader for each light and pass all the models through these seperate shaders. it would make my life alot easier, i believe. if their is a way to do this, or if their is a better way to acheive the same result please let me know. thanks

  2. #2
    Member Contributor
    Join Date
    Apr 2015
    Posts
    75
    Basically you want to reuse shader code. Make 1-2-n shaders for diff lights and then use them in other model shaders ? If yes , then just create simple "include" directive algorithm when loading the shader, for example how i do it.
    Code :
    string LoadShaderSource(filename)
     
         string shadersource;
         OpenFile(filename)
         while(getline(file,line)
         {
            if(line.startswith(#include)
               extract filename from the line
               LoadShaderSource(filename)
           else
              shadersource.append(line)
           }
          return shadersource;

    then in the shader you can use something like
    #version 330 core

    #include "Light.vsh"

    // The rest of the shader
    // That will be doing the model stuff
    .... use Light functions here .....

  3. #3
    Member Newbie
    Join Date
    Sep 2014
    Posts
    33
    k, im having a little trouble understanding what you are saying, but i believe im looking for a more dynamic solution. i would like to be able to add a lightsource at any time and also delete one at anytime. id like to create a file that gives the intenstiy, falloff, etc. and then a type of light. i would then run a copy of the necessary light type (which would be a shader program), with the proper variables once for every seperate light in the scene. thanks

Similar Threads

  1. Replies: 4
    Last Post: 05-28-2014, 09:36 AM
  2. Multiple light sources interacting
    By leftblank in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-26-2012, 06:35 PM
  3. Multiple Dynamic Light Sources in GL3
    By thokra in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 06-07-2011, 06:42 AM
  4. 8 Light Sources
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-21-2002, 01:37 AM
  5. multiple light sources
    By tanvi in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 12-17-2000, 08:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean