I wrote a little program to test how projected shadows work.
I wanted to check in particular the case where the point to project (it could be the vertex of a triangle) is not situated between the light source and the plane but behind the light itself, that is the light is between the point and the plane. The problem is that my little program is not even working in the case where the point is between the light and plane. I checked the calculations tens of times, so I guess the error should be logic, but I cant find it.. Here the code public class test { int x = 0; int y = 1; int z = 2; int w = 3; float floor[][] = { {-100.0f, -100.0f, 0.0f}, {100.0f, -100.0f, 0.0f}, {100.0f, 100.0f, 0.0f}, {-100.0f, 100.0f, 0.0f}}; private float shadow_floor[] = new float[16]; float light_position[] = {0.0f, 0.0f, 10.0f, 1.0f}; public test() { //Find floorplane based on thre known points float plane_floor[] = calculatePlane(floor[1], floor[2], floor[3]); //store shadowMatrix for floor shadow_floor = shadowMatrix(plane_floor, light_position); float[] point = new float[]{1.0f, 0.0f, 5.0f, 1.0f}; float[] projectedPoint = pointFmatrixF(point, shadow_floor); System.out.println("point: (" + point[x] + ", " + point[y] + ", " + point[z] + ", " + point[w] + ")"); System.out.println("projectedPoint: (" + projectedPoint[x] + ", " + projectedPoint[y] + ", " + projectedPoint[z] + ", " + projectedPoint[w] + ")"); } public static void main(String args[]) { test test = new test(); } // make shadow matrix public float[] shadowMatrix(float plane[], float light_pos[]) { float shadow_mat[] = new float[16]; float dot; dot = plane[x] * light_pos[x] + plane[y] * light_pos[y] + plane[z] * light_pos[z] + plane[w] * light_pos[w]; shadow_mat[0] = dot - light_pos[x] * plane[x]; shadow_mat[4] = -light_pos[x] * plane[y]; shadow_mat[8] = -light_pos[x] * plane[z]; shadow_mat[12] = -light_pos[x] * plane[3]; shadow_mat[1] = -light_pos[y] * plane[x]; shadow_mat[5] = dot - light_pos[y] * plane[y]; shadow_mat[9] = -light_pos[y] * plane[z]; shadow_mat[13] = -light_pos[y] * plane[w]; shadow_mat[2] = -light_pos[z] * plane[x]; shadow_mat[6] = -light_pos[z] * plane[y]; shadow_mat[10] = dot - light_pos[z] * plane[z]; shadow_mat[14] = -light_pos[z] * plane[w]; shadow_mat[3] = -light_pos[w] * plane[x]; shadow_mat[7] = -light_pos[w] * plane[y]; shadow_mat[11] = -light_pos[w] * plane[z]; shadow_mat[15] = dot - light_pos[w] * plane[w]; return shadow_mat; } public float[] calculatePlane(float p1[], float p2[], float p3[]) { //Array for planlikningen float plane[] = new float[4]; //Gitt to vektorer (tre punkter) i planet kan normalen regnes ut //Vi vil ha aboluttverdier plane[x] = Math.abs(((p2[y] - p1[y]) * (p3[z] - p1[z])) - ((p2[z] - p1[z]) * (p3[y] - p1[y]))); plane[y] = Math.abs(((p2[z] - p1[z]) * (p3[x] - p1[x])) - ((p2[x] - p1[x]) * (p3[z] - p1[z]))); plane[z] = Math.abs(((p2[x] - p1[x]) * (p3[y] - p1[y])) - ((p2[y] - p1[y]) * (p3[x] - p1[x]))); plane[w] = -(plane[x] * p1[x] + plane[y] * p1[y] + plane[z] * p1[z]); return plane; } public float[] pointFmatrixF(float[] point, float[] matrix) { int x = 0; int y = 1; int z = 2; float[] transformedPoint = new float[4]; transformedPoint[x] = matrix[0] * point[x] + matrix[4] * point[y] + matrix[8] * point[z] + matrix[12]; transformedPoint[y] = matrix[1] * point[x] + matrix[5] * point[y] + matrix[9] * point[z] + matrix[13]; transformedPoint[z] = matrix[2] * point[x] + matrix[6] * point[y] + matrix[10] * point[z] + matrix[14]; transformedPoint[w] = 1; return transformedPoint; } } If the plane is an xy plane, the light is on (0, 0, 10) and the point on (1, 0, 5) then the projected point on the plane should be (2, 0, 0), but the program is returning (400000.0, 0.0, 0.0, 1.0).. Where am I wrong? |
Administrator
|
Hi gouessej,
thanks for the interesting links, I am trying the HWShadowmapsSimple.java I have just some missing jar, all the gleem and demos. I found the gleem here http://www.gnu.org/software/gleem/ (and I changed all the gleem.* into gnu.gleem.*) what about instead the demos? This one is fine http://www.java2s.com/Code/Jar/j/Downloadjogldemosjar.htm? |
the gnu.gleem is giving me a lot of errors, I substituted it with jogl-demos-utils.jar
However I still have two errors viewer = new ExaminerViewer(); viewer.setUpVector(Vec3f.Y_AXIS); constructor ExaminerViewer in class ExaminerViewer cannot be applied to given types; required: int found: no arguments reason: actual and formal argument lists differ in length cannot find symbol symbol: method setUpVector(Vec3f) location: variable viewer of type ExaminerViewer |
Administrator
|
Use Gleem from here. Build the project jogl-demos. Why are some developers obsessed by obtaining obsolete JARs instead of building libraries from sources?
Julien Gouesse | Personal blog | Website
|
Thanks gouessej, that worked ^^
They looks awesome, however can you sum me up quickly pro and vs of each technique? If I need to create a shadow of a single object (based on million of triangles) on a plane, shouldnt be the projected shadow the best way for me? I could do it once rendering the shadow offscreen on a texture, no? Here http://www.opengl.org/archives/resources/faq/technical/lights.htm at the end they mention using the glFrustum(), I know it may be outdated, but can it be fine for my case? |
Administrator
|
To be honest, my main machine is under Mageia Linux 2, my graphics card is so old that I can only use it with an "old" version of Mesa in which lighting is broken only for my hardware. My skills in lighting are very weak, maybe Sven or Demoscene Passivist can answer your question better than me.
What is mentioned in the archived version of the OpenGL FAQ can be used only on the fixed pipeline. If you want something more "future proof", use shaders. I would use these examples: http://fabiensanglard.net/shadowmapping/index.php http://fabiensanglard.net/shadowmappingPCF/index.php http://fabiensanglard.net/shadowmappingVSM/index.php
Julien Gouesse | Personal blog | Website
|
Ok, hovewer thanks for the links :)
Ps: never heard of Mageia, I googled and it seems to be a mandriva-based, nice |
Free forum by Nabble | Edit this page |