two layers sahder?

Started by anne_domini, October 21, 2015, 01:55:19 AM

Previous topic - Next topic

anne_domini

I have several objects, obejcts overlay each other ( <eye>---> |  | ), each object has shader.
Is there a way to modify color of nearest object to eye like a function of color of second object?

EgonOlsen

You have to find the closest object yourself. You can base this on http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#getTransformedCenter() for example. If you are using the default shaders that jPCT-AE provides, you can use http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#setAdditionalColor(int, int, int) to assign an additional color. If you are using your own shaders, you can either provide your own uniform for setting a color or use setAdditionalColor as well and add


uniform vec4 additionalColor;


to your shader, which will be populated by jPCT-AE automatically. You still have to do something with that value in your shader, of course.

anne_domini

Thanks, and if i need to like this:
1. modify color with shader of most farest object.
2. have this color as input in 2nd object shader.
If there a way to do so?

EgonOlsen

You mean you want to access the first object's color in the shader of the second object? Like reading back the color from the frame buffer?

anne_domini


EgonOlsen

You can't do that. The shader can't access the frame buffer's pixels by definition. What's your actual goal? Maybe it can be achieved in some other way.

anne_domini

This is for our application, "Knowledge base for World of Tanks"(a bit of ads: https://play.google.com/store/apps/details?id=com.enigmapro.wot.knowlege&hl=en), we have activity "Armor piercer" which shows probability to penetrate armor of tank with selected shell.
Tank has different armor values in different places (these values are stored in the texture of object). Armor of tank can be of two types main and spaced.
For for user it is ok when he looks on main armor (if main penetrated - damage is dealt).
Several words on shader -  its work is pretty simple - it apply lightning based on angle and armor values.

Next goes the pain - spaced armor. Spaced armor covers main armor with thin armor (here i will not dive deep into game penetration mechanics).
In example: we have penetration value of 200mm. And we are looking on tank, it has main armor 250mm covered with 100mm spaced armor.
--->     |100mm     | 250mm

So totally we need to penetrate 100 + 250 = 350mm; our current penetration is 200mm
We are looking on tank and first we see spaced armor which is 100mm and shader shows that we can damage tank here. because shader doesnt know anything about armor layers which are deeper.
You can watch video https://youtu.be/ATzzXN0hTaU?t=461 (video in on russian lang, but dont worry it wont matter)

Maybe there is some way add renderhook, hide spaced armors, render probability values into texture. unhide spaced armor, render in second pass...

EgonOlsen

I'm not sure if I got the actual problem, but it somehow seems to be that another texture layer might be able to solve this!? Use one layer for main armor and the other one for spaced, mix them into the shader and...profit! Or not...?

anne_domini

Yep, texture layours will help, need to think about it...