Java-Gaming.org Hi !
 Featured games (83) games approved by the League of Dukes Games in Showcase (542) Games in Android Showcase (133) games submitted by our members Games in WIP (604) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 Normal map from height map  (Read 2699 times) 0 Members and 1 Guest are viewing this topic.
darkprophet

Senior Devvie

Go Go Gadget Arms

 « Posted 2006-11-26 13:43:44 »

Hey all,
Im trying to get a normal map from a heightmap through this calculation:

 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25 `public TextureImage filter( HeightMap map ) {      TextureImage image = new TextureImage( map.getDimension(), map.getDimension(), ImageFormat.RGB, new int[] { map.getDimension()            * map.getDimension() * 3 * 4 }, ByteBuffer.allocateDirect( map.getDimension() * map.getDimension() * 3 * 4 ).order( ByteOrder.nativeOrder() ));      FloatBuffer buffer = image.getData().asFloatBuffer();      for ( int i = 0; i < map.getDimension(); i++ ) {         for ( int j = 0; j < map.getDimension(); j++ ) {            Vec3f currentVertex = new Vec3f( i, map.getPixelWrap( i, j ), j );            Vec3f pU = new Vec3f( i + 1, map.getPixelWrap( i + 1, j ), j );            Vec3f pV = new Vec3f( i, map.getPixelWrap( i, j + 1 ), j + 1 );            Vec3f dpU = Vec3f.subtract( currentVertex, pU ).negate();            Vec3f dpV = Vec3f.subtract( currentVertex, pV );                        Vec3f normal = Vec3f.cross( dpU, dpV ).normalise();            normal.multiply( 0.5f ).add( 0.5f );                        buffer.put( normal.x ).put( normal.y ).put( normal.z );         }      }      buffer.rewind();      return image;   }`

If I was to loop through the created buffer in a J2D application, I would get a greenish rectangle (indicating normals pointing upwards) which is what I expected. But if I was to use OpenGL...I get an entirely different image:

Any ideas on whats going on?

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Riven
« League of Dukes »

« JGO Overlord »

Medals: 849
Projects: 4
Exp: 16 years

 « Reply #1 - Posted 2006-11-26 16:06:15 »

Here's my guess:

you're sending floats to an unsigned-byte texture!

(or not)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
darkprophet

Senior Devvie

Go Go Gadget Arms

 « Reply #2 - Posted 2006-11-26 16:09:19 »

LOL! Your right...how stupid of me.

Thanks riven.

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Add your game by posting it in the WIP section, or publish it in Showcase. The first screenshot will be displayed as a thumbnail.
 Elsealabs (14 views) 2014-12-28 10:39:27 CopyableCougar4 (18 views) 2014-12-28 02:10:29 BurntPizza (22 views) 2014-12-27 22:38:51 Mr.CodeIt (14 views) 2014-12-27 04:03:04 TheDudeFromCI (19 views) 2014-12-27 02:14:49 Mr.CodeIt (26 views) 2014-12-23 03:34:11 rwatson462 (58 views) 2014-12-15 09:26:44 Mr.CodeIt (47 views) 2014-12-14 19:50:38 BurntPizza (96 views) 2014-12-09 22:41:13 BurntPizza (115 views) 2014-12-08 04:46:31
 Rayvolution 50x BurntPizza 30x basil_ 29x HeroesGraveDev 25x LiquidNitrogen 22x appel 18x kpars 18x KevinWorkman 15x Riven 15x princec 14x NegativeZero 13x pitbuller 13x gouessej 13x SHC 12x KudoDEV 12x kevglass 11x
 How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27Resources for WIP games2014-08-01 16:20:17Resources for WIP games2014-08-01 16:19:50
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org