Author Topic: two layers sahder?  (Read 928 times)

Offline anne_domini

  • byte
  • *
  • Posts: 17
    • View Profile
two layers sahder?
« on: October 21, 2015, 01:55:19 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: two layers sahder?
« Reply #1 on: October 21, 2015, 08:29:28 am »
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

Code: [Select]
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.

Offline anne_domini

  • byte
  • *
  • Posts: 17
    • View Profile
Re: two layers sahder?
« Reply #2 on: October 21, 2015, 02:21:22 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: two layers sahder?
« Reply #3 on: October 21, 2015, 07:29:45 pm »
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?

Offline anne_domini

  • byte
  • *
  • Posts: 17
    • View Profile
Re: two layers sahder?
« Reply #4 on: October 21, 2015, 11:57:39 pm »
Em, seems so

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: two layers sahder?
« Reply #5 on: October 22, 2015, 08:41:27 am »
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.

Offline anne_domini

  • byte
  • *
  • Posts: 17
    • View Profile
Re: two layers sahder?
« Reply #6 on: October 22, 2015, 06:25:29 pm »
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: two layers sahder?
« Reply #7 on: October 22, 2015, 08:20:45 pm »
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...?

Offline anne_domini

  • byte
  • *
  • Posts: 17
    • View Profile
Re: two layers sahder?
« Reply #8 on: October 23, 2015, 06:54:38 pm »
Yep, texture layours will help, need to think about it...