Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically generate GBuffer.glsllib #6

Open
kwando opened this issue Nov 12, 2012 · 10 comments
Open

Dynamically generate GBuffer.glsllib #6

kwando opened this issue Nov 12, 2012 · 10 comments
Assignees

Comments

@kwando
Copy link
Owner

kwando commented Nov 12, 2012

No description provided.

@ghost ghost assigned kwando Nov 12, 2012
@Setekh
Copy link
Contributor

Setekh commented Nov 12, 2012

Any ideas you'd like to share? About it's structure and assembly. Also would it be possible to make an array of objects assigned to a struct(i mean extending that type)? Like PointLight extends Light and that instance of point light to be added to an array and then iterated in the main?

@Setekh
Copy link
Contributor

Setekh commented Nov 12, 2012

hmm well apparently this works:

struct TestStruct {
float val;
};

struct TestStruct2 {
struct TestStruct st;
float val2;
};

Main()
TestStruct2 ts = TestStruct2(TestStruct(2.0f), 2.2f);

    blabablabla shader code here * (ts.val2 - ts.st.val);

Was thinking if teststruct can be used as Light and teststruct2 could be the type extending it.. but it looks inappropriate and cant really see it implemented somehow.. only if there was some way to bind the lights to the shader code... like the uniforms are..

@Setekh
Copy link
Contributor

Setekh commented Nov 12, 2012

hm, check this. http://pyopengl.sourceforge.net/context/tutorials/shader_7.xhtml

After going through it.. aparently we cna set a uniform with an array of structs:

struct TestStruct { float val; };

struct TestStruct2 {
struct TestStruct st;
float val2;
};

uniform TestStruct ts2[2] = { TestStruct(2), TestStruct(1.2) };

void main() {
// Compute GBuffer sample position
vec2 TexCoord = gl_FragCoord.xy / g_Resolution;
dm_decode(TexCoord);

TestStruct2 ts = TestStruct2(ts2[0], 2.2f);
TestStruct2 ts1 = TestStruct2(ts2[1], 1.2f);

}

So i got this idea where we can set that uniform with our lights array.

@kwando
Copy link
Owner Author

kwando commented Nov 12, 2012

This issue is about packing/unpacking the GBuffer, I think you are talking about lighting now?

But I imagine the same approach can be taken for the lights.

  1. Define a struct for a given light type
  2. Write one function to fill the struct with values
  3. Write one function to calculate lighting for a given struct

This way we breaks the dependency between how we pass the light data and how we use it.

struct DM_PointLight{
  vec3 vsPosition;
  vec4 color;
  float intensity;
  etc
} PointLight;

function fill_struct(){
  PointLight.vsPosition = m_LightPosition;
  PointLight.intensity = m_Color.a;
  ...
  ...
}

vec4 function perform_lighting(){
  // fancy lighting code only using GBuffer struct and PointLight struct and jME uniforms.
  return result;
}

function main(){
  fill_struct();
  gl_FragColor = perform_lighting();
}

I think something similar would work =)

@Setekh
Copy link
Contributor

Setekh commented Nov 12, 2012

Well thats what im talking about.. im talking about a light glsllib. Looks badass

@kwando
Copy link
Owner Author

kwando commented Nov 12, 2012

Submit a new issue on the light glsl-lib also. Implement this in a separate branch from my master so I can pull only those changes in =)

@Setekh
Copy link
Contributor

Setekh commented Nov 12, 2012

i kinda need more info on this, before submitting an issue. So let me get this straight, that layout u gave there for the point light, want me to do it in a LightPass.lib(gimmi a name to use), and it will be like struct DM_PointLight, struct DM_SpotLight, struct DM_DirectionalLight, and i'll do smth like fill_struct(vars) and it will fill that type(and which type it is will be a define), then when perform_lighting() is called it has everything it needs?

@Setekh
Copy link
Contributor

Setekh commented Nov 12, 2012

Or.. you would like me to make a template glsllib and for the specific light a shader will be dynamically created for that light material from the glsllib.

@kwando
Copy link
Owner Author

kwando commented Nov 12, 2012

To be honest I have not thought about all of this. Maybe do a quick spike (small test) on one light type and we will se if it will be a viable solution =)

@Setekh
Copy link
Contributor

Setekh commented Nov 12, 2012

Cool, tho im heading for work XD
It will be on my mind till morning, im testing so many things with this project and it's shader code recently that i find it hard to sleep at night lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants