Author Topic: Does jPCT-AE support shadow?  (Read 6129 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Does jPCT-AE support shadow?
« on: August 01, 2012, 08:36:40 am »
There is a ShadowHelper  class in jPCT but not in jPCT-AE.

I want to use shadow in my world with jPCT-AE, is there any simple way to do this?

Thanks!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #1 on: August 01, 2012, 08:43:41 am »
The short answer would be: No, not yet. There's no official support for shadow mapping in jPCT-AE. The long answer would be: Yes, but...you would have to write the shaders for that by yourself (which might not be the "simple way" that you are looking for).
There is the option to render the depth map into a texture encoded in it's ARGB values, but there are no built-in shaders yet to take this texture and use it for shadow mapping. This is about to be added someday, but ATM, it'll be too slow on anything but the high end anyway.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #2 on: August 01, 2012, 09:02:47 pm »
Take in account Mali-400 does not support high precision floating point number in fragment shader. So if you have some device with Mali-400 or you want full compatibility with this GPUs, you can not use default depth shader. But its easy rewrite them (my rewritten shader is little bit faster). If you want, I can share them. And if you want some numbers, one per-pixel point light, one per-pixel spot light, post-processing image effects (distortion), one rendering of depth buffer, one rendering of motion vectors and motion blur effect (4 samples)... game is running 49fps on Samsung Galaxy S3, without motion blur (and everything needed for this effect) it is 60fps. So your app can running smooth with shadows too. But take in account, these numbers come from high-end phone.
« Last Edit: August 02, 2012, 09:32:16 am by Thomas. »

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #3 on: August 02, 2012, 04:53:20 am »
Thanks, Egon! But i really hope you can support this in jPCT-AE. ;D I think it may be helpful for someone.


Take in account Mali-400 does not support high precision floating point number in fragment shader. So if you have some device with Mali-400 or you want full compatibility with this GPUs, you can not use default depth shader. But its easy rewrite them (my rewritten shader is little bit faster). If you want, I can share them. And if you want some numbers, one per-pixel point light, one per-pixel spot light, post-processing image effects (distortion), one rendering of depth buffer, one rendering of motion vectors and motion blur effect (4 samples)... game is running 49fps on Samsung Galaxy S3, without motion blur (and everything needed for this effect) it is 60fps. So your app can running smooth with shadows too. But take in account, this numbers comes from high-end phone.

Thanks, Thomas! Please share them! You can update them to a public-web-store, or send to me by email: kiffa.gx@.gmail.com. Thanks again!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #4 on: August 02, 2012, 07:34:13 am »
I wasn't aware that the default depth shader doesn't work on Mali-crapsets. It would like to see the working version too!

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #5 on: August 02, 2012, 07:26:30 pm »
Here you are. Depth is packet into RGBA and have to be unpacked. I see I wanted to test performance of smoothstep(...)... Keep in mind, this is the simplest part of shadows. jPCT-AE not support projectors ATM, you will have to use Camera and write shaders for shadows.

vertex shader
Code: [Select]
uniform mat4 modelViewProjectionMatrix;

attribute vec4 position;

varying float depth;

uniform float nearPlane;
uniform float farPlane;

void main() {
vec4 pos = modelViewProjectionMatrix * position;
depth = (pos.z - nearPlane) / (farPlane - nearPlane); // TODO performance test of smoothstep(min, max, x)
gl_Position = pos;
}

fragment shader
Code: [Select]
precision highp float;

varying float depth;

const vec4 PACK_FACTORS = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);
const vec4 BIT_MASK = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);

void main() {
vec4 packedValue = fract(PACK_FACTORS * depth);
packedValue -= packedValue * BIT_MASK;
gl_FragColor = packedValue;
}

unpack
Code: [Select]
const vec4 UNPACK_FACTORS = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0);
... main
highp float depth = dot(texture2D(textureUnit0, texCoord), UNPACK_FACTORS);

I wasn't aware that the default depth shader doesn't work on Mali-crapsets. It would like to see the working version too!

Wokrs, but with a lot of artefacts.

Edit: I tested smoothstep(...) now. Ten times rendering of depth and fps is 22 with linear interpolation and also with smoothstep. And Egons shader is on 29 (with artefacts), but before it was slower ???

Eidt2: Oh before I used full resolution of depth texture (now I'm using half), so it was four times more fragment calculations, whereas vertex calculations are still same for any resolution...
« Last Edit: March 06, 2013, 04:44:15 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #6 on: August 02, 2012, 11:09:43 pm »
Thanks. I guess i'll have to update the depth shader code with these changes then.

Offline raft

  • quad
  • ******
  • Posts: 1972
    • View Profile
    • http://www.aptalkarga.com
Re: Does jPCT-AE support shadow?
« Reply #7 on: March 06, 2013, 10:35:00 am »
The short answer would be: No, not yet. There's no official support for shadow mapping in jPCT-AE.
any near plans to implement official shadow support? current hardware is quite fast and even getting faster.

I'm making a desktop version of sky maze and will soon add shadows. will be great if same code works for android too.

furthermore, android based game console* OUYA will be released on june which possibly will have more than enough power. specs are at the bottom of that page. (I'm still not a HW guy, so specs dont make much sense to me ;)) I'm also planning to publish sky maze on that platform.

*thanks to paul for tip :) 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #8 on: March 06, 2013, 11:03:35 am »
I'm still waiting to Thomas. to create a version that he considers to be fine... ;) IIRC, the last version still had some issues. I've roughly scheduled shadows for 1.26, which should be ready in may or june. Depending on how it goes, there might be some beta earlier. At least that's the current plan...

Regarding OUYA's hardware: It's a NVidia Tegra 3, which is the same thing that i have in my Nexus 7. To be honest, i'm not very impressed with what NVidia delivered with this chip. It's depth buffer accuracy is laughable by default, it's rendering accuracy is below everything else that i've seen on a mobile device and it's performance is fine but nothing to get crazy about. It should be fast enough to do basic shadow mapping though.

Offline raft

  • quad
  • ******
  • Posts: 1972
    • View Profile
    • http://www.aptalkarga.com
Re: Does jPCT-AE support shadow?
« Reply #9 on: March 06, 2013, 11:14:30 am »
cool, glad to hear that it's in the roadmap :)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #10 on: March 06, 2013, 04:42:06 pm »
I'm still waiting to Thomas. to create a version that he considers to be fine... ;)

Oh, shadows have currently the lowest priority for me, first I have to complete app to work and projects to school, then I wanted to look at the native Bullet and make support for jPCT... I can look at the shadows next week. There was a bug when everything outside of the shadow projector frustum are darker. This is visible in the screenshots and video of my game.

Offline raft

  • quad
  • ******
  • Posts: 1972
    • View Profile
    • http://www.aptalkarga.com
Re: Does jPCT-AE support shadow?
« Reply #11 on: June 20, 2013, 10:56:38 pm »
I guess shadows won't be ready at OUYA launch (which is 25th of June), right?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #12 on: June 21, 2013, 07:42:29 am »
I guess shadows won't be ready at OUYA launch (which is 25th of June), right?
No, they won't, i'm afraid. 1.26 got already bigger than it was supposed to be. I'll try to release it within the next 1 or 2 weeks and postpone the shadows to 1.27.

Offline drdla

  • byte
  • *
  • Posts: 16
    • View Profile
Re: Does jPCT-AE support shadow?
« Reply #13 on: April 27, 2016, 11:17:44 am »
It's few years from thic conversation.

Is there now any way to create shadows in jPCT-AE?

Thank you!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Does jPCT-AE support shadow?
« Reply #14 on: April 27, 2016, 12:11:40 pm »
Yes, but it's still in early beta and (maybe) not finished yet. It's also not documented ATM. However, in my tests, it does what it's supposed to do, so it might not change that much before the official release. If you want to play around with it, you can grab the beta here: http://jpct.de/download/beta/jpct_ae.jar
It includes a ShadowHelper-class in the util-package. If you want to combine shadows with your own shaders, you can do that as well, but it's not documented yet. You can look into the default shaders in the jar to get an idea of how to do it though.
But as said, things might change before the next official release.