PDA

View Full Version : State dependant rendering of objects



tsweet
08-01-2012, 07:25 AM
Hey guys,

I am currently working on my bachelor thesis which is about creating a 3D-Visualisation of a warehouse using the GWT plugin gwt-g3d.

I've come as far as being able to display the structual layout quite efficiently. Rendering 2 million+ vertextes at a decent framerate since i keep all the rendering within the shaders and minimize my gl.draw() calls. However I think i've come to a dead end using this technique since it is very static. What i need is a way to make my application more dynamic.
As I am used to object orientated programming in Java the shader language is quite hard to get my head around. Here's what I'm talking about...

I'm trying to render multiple areas (the number of these ares is UNKNOWN at initialisation) of my visualisation in a different manner (a different color to start with). So ive tried something like this within the fragment shader:

...
uniform vec3 alteredCoords[]; //a coordArray of positions that i want to render alternatively
...

// color each of these coords in grey
for (int i = 0; i < alteredCoords.length(); i++) {
if ( position.x == alteredCoords[i].x && position.y == alteredCoords[i].y && position.z == alteredCoords[i].z) {
gl_FragColor = vec4(100.0/255.0, 100.0/255.0, 100.0/255.0, 1.0);
return;
}
}

I know that this wont work as it is, because the array needs a constant size and there are casting issues.... try to ignore that for now since this wont work anyways because the shader language doesn't support dynamically sized arrays.

What i need is some sort of workaround for this issue...

any ideas?

Help please :D

EDIT:
to give you a better understanding of what i'm talking about here's a screenshot of what my layout looks like atm:

http://img4.imageshack.us/img4/6282/12802087.png

Notice that i've implemented my idea for a single area (grey square) already.... all i need is some way to dynamically render multiple areas that way

Ralph
08-01-2012, 10:49 AM
Ok since you also asked that on stackoverflow it seem you really want help, so I'll try to help you. However, either it's just me after 2 days of refactoring code or your explanation of your problem isn't really clear.

So basically you want to render an arbitrary amound of these shelves and depending on their location they should be colored somehow?

tsweet
08-01-2012, 11:02 AM
yes I am really desperate for help =P

Exactly, as soon as i've figured out a mechanism to address any number of locations dynamically i can realize what's missing in my application.

I am unsure of how clear my explanation is so far... so if there are questions regarding code or anything else just go for it, i'll try to answer as much as i can =D

On my way home from work i've thought about my post and maybe i should simply have asked: Is there any data type in the shading language that does not need a constant size and can be used for saving data (much like an ArrayList...)

Ralph
08-01-2012, 11:13 AM
yes I am really desperate for help =P


Sometimes just talking about the problem helps :)



On my way home from work i've thought about my post and maybe i should simply have asked: Is there any data type in the shading language that does not need a constant size and can be used for saving data (much like an ArrayList...)

No there isn't. If you need to give a shader a large amount of data you usually do it with a texture.

Now for the problem. Do you need to color them only according to their x,y location? If yes, I would simply create one buffer to draw a single shelf. Then draw them using two for loops, update the loction with an x,y offset uniform in the vertex shader and color with an uniform in the fragment shader.

tsweet
08-01-2012, 11:18 AM
thank you already!

i will try this out tmrw at work....
can you send me ur skype via pm?

greets!