Horde3D
http://horde3d.org/forums/

Coloring cones
http://horde3d.org/forums/viewtopic.php?f=2&t=1560
Page 1 of 1

Author:  kumopen [ 07.08.2011, 22:12 ]
Post subject:  Coloring cones

I have a scene with several identical cones that need to be colored when they enter certain areas of my map (E.g. they enter the red zone and should be colored red). The entities can not be batched into groups for this because there are a lot of colors. Because of the complexity of my scene, I can not simply use radial light sources.

Here is what I tried:

1. Create a uniform "color" that colors the cone differently. Clean and simple. Caveat: Because uniforms are per material, every entity needs its own copy of the material. This causes many rendercalls and slows the scene down when many cones are visible.
2. The cones are rotation-symmetric. Utilize the rotation around the Y-Axis to store that color information. Caveat: Objects that are attached to the cones get rotated as well. The calculation of the angle needs a dot&asin. Also it feels like hack.

Ideas that I couldn't go on with:

1. Is there maybe a way to pass along extra information to objects besides per-material uniforms? I noticed there is a uniform float nodeId; that changes with each entity of the same material during a drawcall - maybe I can do something similar?
2. I'm basically trying to apply a (colored) shadow to an object. Wouldn't something like this be used in games a lot?

Any help is appreciated. Thank you for reading.

Author:  marciano [ 09.08.2011, 15:23 ]
Post subject:  Re: Coloring cones

Custom per-instance uniforms that can be set for each model node would be the best solution. It could be something as simple as a generic vec4 uniform array for which arbitrary data could be stored for each model using the API. Unfortunately they are not yet implemented but they should definitely go into the next version.

Author:  kumopen [ 10.08.2011, 11:12 ]
Post subject:  Re: Coloring cones

Thank you for your time and the positive news.

I hate to be that guy, but is there a guesstimate when that feature will come?

Author:  marciano [ 12.08.2011, 18:02 ]
Post subject:  Re: Coloring cones

I'm currently still on a trip but maybe there is some time next week to quickly add this.

Author:  kumopen [ 12.08.2011, 20:14 ]
Post subject:  Re: Coloring cones

Thank you very much for considering this.

Have a safe trip.

Author:  marciano [ 21.08.2011, 18:20 ]
Post subject:  Re: Coloring cones

So here is a quick patch that adds support for custom per-model uniforms. The new API function is documented, so it should be quite obvious how it works ;)

Attachments:
model_inst_uniforms.zip [2.08 KiB]
Downloaded 921 times

Author:  kumopen [ 04.09.2011, 20:23 ]
Post subject:  Re: Coloring cones

Sorry for the late reply.

Just got it to work. It works perfectly and is pretty fast too! Great addition. Why did you opt to not add this to the main trunk? Are there any caveats?

Author:  marciano [ 18.09.2011, 22:23 ]
Post subject:  Re: Coloring cones

Sorry for the long delay, the feature is in the main trunk now!

Author:  olsenjens [ 10.01.2012, 01:22 ]
Post subject:  Re: Coloring cones

Hello, i am trying to use this new feature in a similar fashion compared to OP but
i am having some problems getting the shader uniform handle to work propperly, an example on how you colored the cones would be nice


Code:
[[FS_AMBIENT]]   

uniform vec4 customInstData;

gl_FragColor.rgb = customInstData;


works fine in rendermonkey but gRDI->getShaderConstLoc( shdObj, "customInstData" ); return -1.

I did also allot of printing of the 20 or so versions of the shader objects and do see
it in there + the unitialized effect in the renderer.


any advice apreciated

Author:  worstplayer [ 10.01.2012, 16:06 ]
Post subject:  Re: Coloring cones

customInstData is an array, try this, maybe it helps?

Code:
[[FS_AMBIENT]]

uniform vec4 customInstData[4];

gl_FragColor.rgb = customInstData[0];

Author:  olsenjens [ 10.01.2012, 19:14 ]
Post subject:  Re: Coloring cones

Thank you sir, that solved it!

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/