Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6713291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:21:44+00:00 2026-05-26T08:21:44+00:00

Seriouse graphics engine like CryEngine3, Unreal Engine 3 have their customized shader language and

  • 0

Seriouse graphics engine like CryEngine3, Unreal Engine 3 have their customized shader language and effect system. While trying to find some effect system for my small graphics framework, it looks like nvidia CgFx is the only choice (seems Khronos had a project called glFx, but the project page is 404 now).

I have several reasons to make a effect system of my own:

  1. I need more control about how and when to pass the shader parameters.
  2. In order to reuse shader snippets, I want to create some c++ macro like mechanism. It’s also useful to use macro to do some conditional compilation, and that the way CryEngine used to produces various effects.
  3. Looks like GLSL don’t have such effect system

so I am wondering how to create a effect system? Do I need to write grammar parser from scratch or there’s already some code/tools able to do this thing?

PS: I am using OpenGL with both GLSL and CG.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:21:44+00:00Added an answer on May 26, 2026 at 8:21 am

    Back in the day when I was using HLSL, I developped a little shader system which allowed me to specify all my parameters through data, so that I could just edit a sort of XML file containing the list of parameters and the shader codes, and after saving, the engine would automatically reload it, rebind all parameters, etc.

    It’s nothing compared to what’s found in the UDK, but pretty convenient, and I guess you’re trying to implement something like that ?

    I it is, then here are a few stuff to do. First, you need to create a class to abstract shader parameter handling (binding, setting, etc.) Something along these lines :

    class IShaderParameter
    {
    protected:
        IShaderParameter(const std::string & name)
            : m_Uniform(-1)
            , m_Name(name)
        {}
        GLuint m_Uniform;
        std::string m_Name;
    public:
        virtual void Set(GLuint program) = 0;
    };
    

    Then, for static parameters, you can simply create an overload like this :

    template < typename Type >
    class StaticParameter
        : public IShaderParameter
    {
    public:
        StaticParameter(const std::string & name, const Type & value)
            : IShaderParameter(name)
            , m_Value(value)
        {}
        virtual void Set(GLuint program)
        {
            if (m_Uniform == -1)
                m_Uniform = glGetUniformLocation(program, m_Name.c_str());
            this->SetUniform(m_Value);
        }
    protected:
        Type m_Value;
        void SetUniform(float value) { glUniform1f(m_Uniform, value); }
        // write all SetUniform specializations that you need here
        // ...
    };
    

    And along the same idea, you can create a “dynamic shader parameter” type. For example, if you want to be able to bind a light’s parameter to your shader, create a specialized parameter’s type. In its constructor, pass the light’s id so that it will know how to retrieve the light in the Set method. With a little work, you can have a whole bunch of parameters that you can then automatically bind to an entity of your engine (material parameters, light parameters, etc.)

    The last thing to do is create a little custom file format (I used xml) to define your various parameters, and a loader. For example, in my case, it looked like this :

    <shader>
        <param type="vec3" name="lightPos">light_0_position</param>
        <param type="vec4" name="diffuse">material_10_diffuse</param>
        <vertexShader>
          ... a CDATA containing your shader code
        </vertexShader>
    </shader>
    

    In my engine, “light_0_position” would mean a light parameter, 0 is the light’s ID, and position is the parameter to get. Binding between the parameter and the actual value was done during loading so there was not much overhead.

    Anyway, I don’t if that answer your question, and don’t take these sample codes too seriously (HLSL and OpenGL shaders work quite differently, and I’m no OpenGL expert ^^) but hopefully it’ll give you a few leads 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app which is based on the Qt Graphics View framework. It's
I have a serious problem in my app. I wrote a facebook like instant
I have this serious problem. I have an enumeration within 2 namespaces like this:
I have a NVida graphic card and I would like to use it for
I have a serious problem. Firstly, I am trying to retrieve values from my
I have a serious probleam with my Eclipse Plugin.. My plugin depends on another
I have a serious problem. One of our servers crashed. Now I reinstalled the
I am having some serious issues trying to tweak my layout in a table.
I have this serious: I have ASP.NET page, This page contents Update panel with
I'm using GLUT (freeglut3) (via the Haskell GLUT bindings). import Graphics.UI.GLUT handleKBMouse :: KeyboardMouseCallback

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.