Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - take2316

Pages: [1]
Support / Shadow mapping approach
« on: March 20, 2013, 01:53:49 am »
I'm trying to implement simple shadow mapping for jPCT-AE. I saw some of the recent forum posts about how shadows will soon be implemented?... but I just wanted to know if my approach is correct. (I'm trying to implement this for a school project that's due in a little over 48 hours!)

Code: [Select]
// Framebuffer fb
// Camera lightCam represents the light's view
// Texture shadowMap
// GLSLShader depthShader

// render shadow map
world.setGlobalShader(depthShader); // doesn't override the shader for objects that called setShader!
world.setGlobalShader(null); // is this how you remove the global shader?
world.setCameraTo(cam); // set back to regular camera
// regular render pass

Then I'll have to pass in the light's model view projection matrix to the regular shadow mapping shader. Since GLSLShader does not support passing in your own uniforms, I'll have to create an implementation of IRenderHook... right? Or is there a way to pass in the model-view-projection matrix for the light source(s) via GLSLShader without implementing IRenderHook?

Support / Fragment shader not loading on different Android device
« on: March 15, 2013, 12:39:16 am »
I can successfully run my shader code on my Android 4.1.1 Samsung Galaxy S3 device, but when I try it on an Android 2.3.4 LG Revolution, I get this error: "ERROR: Failed to load and compile fragment shaders!"

Here are my vertex and fragment shaders:

Vertex shader:
Code: [Select]
uniform mat4 modelViewMatrix;
uniform mat4 modelViewProjectionMatrix;

attribute vec4 position;
attribute vec3 normal;

varying vec2 texCoords;

void main() {
// apparently, jPCT doesn't support gl_NormalMatrix, but it's okay:
// see:,2723.msg20171.html#msg20171
// and:
vec3 n = normalize(modelViewMatrix * vec4(normal,0.0)).xyz;

vec3 u = (modelViewMatrix * position).xyz;

vec3 r = u - 2.0 * dot(u,n) * n;
float m = 2.0 * sqrt(r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0));
texCoords.x = r.x/m + 0.5;
texCoords.y = r.y/m + 0.5;

gl_Position = modelViewProjectionMatrix * position;

Fragment shader:
Code: [Select]
uniform sampler2D textureUnit0;

varying vec2 texCoords;

void main() {
gl_FragColor = texture2D(textureUnit0, texCoords);

Do you have any idea why this might be happening?

Support / setRenderHook(shader) not compiling
« on: March 10, 2013, 01:43:48 am »
Eclipse is giving me this error for the following code:
The method setRenderHook(IRenderHook) in the type Object3D is not applicable for the arguments (GLSLShader)

Code: [Select]
GLSLShader shader = new GLSLShader(vertex, fragment);

I tried casting shader to an IRenderHook, but when the code runs, I get this fatal exception error: E/AndroidRuntime(30731): java.lang.ClassCastException: com.threed.jpct.GLSLShader cannot be cast to com.threed.jpct.IRenderHook

Any ideas on how to fix this?

Bugs / BitmapHelper rescale not working correctly?
« on: March 09, 2013, 09:15:10 pm »
I'm creating a texture from a 640x480 image and want to rescale it to 256x256 for the texture. So I tried doing:
Code: [Select]
Texture texture = new Texture(BitmapHelper.rescale(b, 256, 256);where b is the 640x480 Bitmap image. However, when I load it into a plane, only the middle of the image is shown in the texture:
Code: [Select]
Object3d plane = Primitives.getPlane(1, 100);
I verified this by saving the bitmap to my sdcard on the Android phone and indeed the saved bitmap shows the full picture. However, the texture looks like it's only the very middle portion of the bitmap. Is this how BitmapHelper.rescale works, i.e. saving the center portion first?

Support / SetEnvmapped gives a flickering texture
« on: March 06, 2013, 05:44:28 am »
I'm following the Integrating jPCT-AE with Vuforia code (, and want to use environment mapping for the textures. So I added
Code: [Select]
cube.setEnvmapped(Object3D.ENVMAP_ENABLED);but what I get is a flashing (flickering) texture. Could someone point me in the right direction to use environment mapping?

Pages: [1]