Need help regarding setup of Thomas' shadow implementation in my example.

Started by Wolf17, February 27, 2015, 06:33:45 AM

Previous topic - Next topic

Wolf17

   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 .

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

shadowHelper = new cz.chladek.jpct.extension.ShadowProjector();
world.getLightController().setShadowHelper(shadowHelper);


3.Ondrawfrme::..

shadowHelper.update(world, fb);



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

fb.display();

This from my ondrawframe.


Also THis is what in the update method..............

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

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

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

EgonOlsen

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

Wolf17

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 . 

EgonOlsen

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.

Wolf17

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

EgonOlsen

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?

EgonOlsen

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

Wolf17


EgonOlsen


Wolf17

No , It only renders a black strip over white fb when I only use projector camera and without depthshader. I am doing this...

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


EgonOlsen

Please try the same thing without any custom shaders set. And can you post your shader sources as well?

Wolf17

These are same which are used in thomas' game .
Vertex shader shadow map

uniform mat4 modelViewProjectionMatrix;

attribute vec4 position;

varying vec4 vPosition;

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



fragment shader shadowmap

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



EgonOlsen

Yes, these are the ones that fill the depthmap. I'm more interested in the ones that are used to render the actual scene.

Wolf17


EgonOlsen

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.