Does jPCT-AE support shadow?

Started by kiffa, August 01, 2012, 08:36:40 AM

Previous topic - Next topic

kiffa

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!

EgonOlsen

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.

Thomas.

#2
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.

kiffa

Thanks, Egon! But i really hope you can support this in jPCT-AE. ;D I think it may be helpful for someone.


Quote from: Thomas. 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, 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!

EgonOlsen

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

Thomas.

#5
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
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
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

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);


Quote from: EgonOlsen 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!

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...

EgonOlsen

Thanks. I guess i'll have to update the depth shader code with these changes then.

raft

Quote from: EgonOlsen 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.
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 :) 

EgonOlsen

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.

raft

cool, glad to hear that it's in the roadmap :)

Thomas.

Quote from: EgonOlsen on March 06, 2013, 11:03:35 AM
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.

raft

I guess shadows won't be ready at OUYA launch (which is 25th of June), right?

EgonOlsen

Quote from: raft on June 20, 2013, 10:56:38 PM
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.

drdla

It's few years from thic conversation.

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

Thank you!

EgonOlsen

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.