Author Topic: Need help regarding setup of Thomas' shadow implementation in my example.  (Read 3563 times)

Offline Wolf17

  • int
  • **
  • Posts: 77
    • View Profile
   I am using Thomas' Game sample and his JPCT extentions (Both are Great Help ! Thanks for open sourcing them !!! ) for creating a world with a cuboid and a plane surface which is having a spotlight.
I really know nothing about shaders, but at the same time trying/eager to have some basic shadowsmapping in my work . 
What I did -
1. On My Oncreate Method I loaded custom shaders .
Code: [Select]
ZipInputStream zis = new ZipInputStream(res.openRawResource(R.raw.data));
ZipEntry ze;
try {
while ((ze = zis.getNextEntry()) != null) {
BLABLA....

ShaderProvider.setShader(ze.getName(), sb.toString());
}

zis.closeEntry();
zis.close();
          BLABLAh....
2. On my OnSrfacechanged...
Code: [Select]
shadowHelper = new cz.chladek.jpct.extension.ShadowProjector();
world.getLightController().setShadowHelper(shadowHelper);

3.Ondrawfrme::..
Code: [Select]
shadowHelper.update(world, fb);


4.  Removed
Code: [Select]
              world.renderScene(fb);
world.draw(fb);

fb.display();
This from my ondrawframe.


Also THis is what in the update method..............
Code: [Select]
public void update(World world, FrameBuffer fb) {
if (light != null) {
if (!setted) {
Enumeration<Object3D> objects = world.getObjects();
while (objects.hasMoreElements()) {
Object3D object = objects.nextElement();
if (!object.getName().startsWith("particle")) {
PolygonManager pm = object.getPolygonManager();
int maxID = pm.getMaxPolygonID();
for (int i = 0; i < maxID; i++)
pm.addTexture(i, textureID, TextureInfo.MODE_MODULATE);
}
}
projectionMatrix = projector.getProjectionMatrix(fb, nearPlane, farPlane);
setted = true;
}
updateProjector();
Camera originalCam = world.getCamera();

world.setCameraTo(projector);
fb.setRenderTarget(shadowTexture, 1, 1, 1, 1, true);
fb.clear(RGBColor.WHITE);
Tools.renderWithShader(world, fb, depthShader);
fb.display();
fb.removeRenderTarget();
world.setCameraTo(originalCam);
}
}

And Tools.renderwithshader......................
Code: [Select]
public static void renderWithShader(World world, FrameBuffer fb, GLSLShader shader) {
Enumeration<Object3D> objects = world.getObjects();
while (objects.hasMoreElements()) {
Object3D obj = (Object3D) objects.nextElement();
if (obj.getVisibility()) {
GLSLShader objShader = obj.getShader();
shaders.add(objShader);
obj.setShader(shader);
}
}

world.renderScene(fb);
world.draw(fb);

objects = world.getObjects();
int i = 0;
while (objects.hasMoreElements()) {
Object3D obj = (Object3D) objects.nextElement();
if (obj.getVisibility()) {
GLSLShader objShader = shaders.get(i);
obj.setShader(objShader);
i++;
}
}
shaders.clear();
}


**********************************************************************
  ___ Result was a blank black screen .___...I also used this
Code: [Select]
shadowHelper.blitShadowMap(fb, halfW - 64, fb.getHeight() - size - 10, size);
to blit the shadowTexture ... but it is also blank white blit .

Then I did many funny experiments with different laughable  results but none produced the desired results.

also my log o/p is full of this-
02-27 10:59:17.330: I/jPCT-AE(7147): Additional visibility list (106) created with size: 512
02-27 10:59:17.350: I/jPCT-AE(7147): Additional visibility list (107) created with size: 512
..........

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #1 on: February 27, 2015, 10:25:27 am »
Looks like as if you have some exception in your code that you just shallow instead of handling it correctly...hence the massive creation of visibility lists. This indicates an unfinished rendering process. Check your code for empty catch-blocks...

Offline Wolf17

  • int
  • **
  • Posts: 77
    • View Profile
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #2 on: February 27, 2015, 10:51:23 am »
If I comment out
 "fb.setRenderTarget(shadowTexture, 1, 1, 1, 1, true);"
and"   fb.removeRenderTarget();"
then I stop getting the log o/p additionallist
and the result is a white framebuffer (due to fb.clear(white).)with black blit shadowtexture.
exact oppsite of first result!..
I Could not find any relation.
Also I wanna know ...That is my code from the first post is O.K for shadows ? Is it complete?
I am actually simply copying/hacking /retrofitting Thomas' example for shadows to work . 
« Last Edit: February 27, 2015, 11:17:32 am by Wolf17 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #3 on: February 27, 2015, 12:20:48 pm »
As said: If your code creates dozens of visibility lists, you either don't call display in all render paths or you do but your code doesn't reach it, because it bombs out earlier and you are swallowing the exception. It has to be one of those.

Offline Wolf17

  • int
  • **
  • Posts: 77
    • View Profile
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #4 on: February 27, 2015, 03:25:06 pm »
    The  visibility lists is no more there when I put fb.display() on Ondrawframe().
But I still see a blank screen ....and a white blit overlay. When I put logger.log something in my update   
method and in tools.renderwithshader() method...it does show up in my log o/p. Which ,I think suggests that my code does reach till there.
Don't  know whats happening. :(
« Last Edit: February 27, 2015, 03:36:44 pm by Wolf17 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #5 on: February 27, 2015, 05:51:42 pm »
Have you tried to render the scene when viewed from the projector without the depthmap shader,  so that you can see the scene that it actually renders?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #6 on: February 27, 2015, 05:53:17 pm »
...and the normal scene without any special shaders? Just to make sure that everything else like ambient lighting is fine and the scene isn't all dark anyway?
« Last Edit: February 27, 2015, 05:56:17 pm by EgonOlsen »

Offline Wolf17

  • int
  • **
  • Posts: 77
    • View Profile
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #7 on: February 27, 2015, 05:56:06 pm »
Yes . Everything Works fine when rendering normally.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #8 on: February 27, 2015, 05:57:38 pm »
...even the scene when viewed from the projector?

Offline Wolf17

  • int
  • **
  • Posts: 77
    • View Profile
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #9 on: February 27, 2015, 06:10:05 pm »
No , It only renders a black strip over white fb when I only use projector camera and without depthshader. I am doing this...
Code: [Select]
public void update(World world, FrameBuffer fb) {
if (light != null) {
if (!setted) {
Enumeration<Object3D> objects = world.getObjects();
while (objects.hasMoreElements()) {
Object3D object = objects.nextElement();
if (!object.getName().startsWith("particle")) {
PolygonManager pm = object.getPolygonManager();
int maxID = pm.getMaxPolygonID();
for (int i = 0; i < maxID; i++)
pm.addTexture(i, textureID, TextureInfo.MODE_MODULATE);
}
}
projectionMatrix = projector.getProjectionMatrix(fb, nearPlane, farPlane);
setted = true;
}
updateProjector();
Camera originalCam = world.getCamera();
Logger.log("blbllbbalablllllllllllllllllllllll");
world.setCameraTo(projector);
fb.clear(RGBColor.WHITE);
world.renderScene(fb);
world.draw(fb);
fb.display();
}
}

« Last Edit: February 27, 2015, 06:12:48 pm by Wolf17 »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #10 on: February 27, 2015, 06:13:17 pm »
Please try the same thing without any custom shaders set. And can you post your shader sources as well?

Offline Wolf17

  • int
  • **
  • Posts: 77
    • View Profile
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #11 on: February 27, 2015, 06:19:24 pm »
These are same which are used in thomas' game .
Vertex shader shadow map
Code: [Select]
uniform mat4 modelViewProjectionMatrix;

attribute vec4 position;

varying vec4 vPosition;

void main(){
vPosition = modelViewProjectionMatrix * position;
gl_Position = vPosition;
}


fragment shader shadowmap
Code: [Select]
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif

uniform float nearPlane;
uniform float farPlane;
uniform float bias;

varying vec4 vPosition;

vec4 packFloat(float value){
#ifdef GL_FRAGMENT_PRECISION_HIGH
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);
vec4 packetValue = fract(PACK_FACTORS * value);
return packetValue - packetValue * BIT_MASK;
#else
const vec3 PACK_FACTORS = vec3(128.0, 128.0 * 256.0, 128.0 * 256.0 * 256.0);
vec3 packetValue = floor(PACK_FACTORS * value);
packetValue -= vec3(0.0, packetValue.r * 256.0, packetValue.g * 256.0);
return vec4(packetValue / 255.0, 1.0);
#endif
}

void main() {
gl_FragColor = packFloat((vPosition.z - nearPlane) / (farPlane - nearPlane) + bias);
}


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #12 on: February 27, 2015, 06:25:01 pm »
Yes, these are the ones that fill the depthmap. I'm more interested in the ones that are used to render the actual scene.

Offline Wolf17

  • int
  • **
  • Posts: 77
    • View Profile
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #13 on: February 27, 2015, 06:30:52 pm »
I think this package contains those shaders (attachment)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Need help regarding setup of Thomas' shadow implementation in my example.
« Reply #14 on: February 27, 2015, 06:39:51 pm »
Are you actually ever assigning these shaders that you add to this ShaderProvider class  to some object? I don't see anything like that in your code.