www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Melssj5 on May 26, 2007, 04:54:14 pm

Title: Reflection efect
Post by: Melssj5 on May 26, 2007, 04:54:14 pm
Hi, how can I get a reflection efect over an object3d? like in the fps demo on the weapon. The object3d wont act like a mirror, only want to get that effect. Its for placing in over a car.

Can I have it together with another texture?
Title: Re: Reflection efect
Post by: EgonOlsen on May 26, 2007, 06:03:53 pm
The effect is simple environment mapping. You can enable it on any object. Combining it with another texture is possible by using multitexturing but to be honest, i've no idea how jPCT currently behaves when you enable environment mapping on an object with multiple textures. I think that the best idea would be to limit the environment mapping to layer 0 only, but i'm not sure that i did it that way. I suppose not...i'll have a look at this next week.
Title: Re: Reflection efect
Post by: Klaudiusz on May 27, 2007, 11:07:12 am
Egon,

You made great work with implement tex+env and tex+env+bump in software mode but personally i can't use it because it's not implement in OpenGL mode :( Is there any chanse toimplement it also on OpenGL?

Objects with texture and envmap are really beautyfull :)
Title: Re: Reflection efect
Post by: EgonOlsen on May 27, 2007, 11:54:53 am
As said: I'll have a look at it and i'll most likely limit env-mapping to the first texture layer. That way, you'll be able to create an effect similar to that of the software renderer. Just the setup will be a little different.
Title: Re: Reflection efect
Post by: EgonOlsen on May 29, 2007, 10:03:36 am
Ok, i had a look at it: It's already implemented in the way that i've decribed, i.e. the env-mapping is applied to layer 0 only. This means that you can set your environment map as the first texture and the normal texture as the second with an appropriate blending mode (modulate for example) and you should get the desired effect.
Title: Re: Reflection efect
Post by: Melssj5 on May 29, 2007, 04:05:45 pm
Ok, great the problem is that I dont know how to apply that. can you give a code example of that multitexturing stuff?
Title: Re: Reflection efect
Post by: EgonOlsen on May 29, 2007, 04:19:02 pm
Sure. Assuming that the model already has proper texture coordinates for its base texture, just do:

Code: [Select]
TextureInfo tis=new TextureInfo(tm.getTextureID("environment map"));
tis.add(tm.getTextureID("normal texture"), TextureInfo.MODE_ADD); // Or another mode...
yourObj.setTexture(tis);
Title: Re: Reflection efect
Post by: EgonOlsen on June 02, 2007, 05:07:49 pm
Bumpmapping in OpenGL mode is still not available, true?
No, it isn't.
Title: Re: Reflection efect
Post by: Melssj5 on June 16, 2007, 02:59:15 am
OK, finally I could test it and didnt worked as expected. I was thinking on something put over a texture, my actual app replace a texture on the texture manager allowing it to change the parts of the Object that has that Texture, but on that way the new Texture is applied to all the object.

Later I will post some shots about the result.
Title: Re: Reflection efect
Post by: Melssj5 on June 16, 2007, 05:58:42 am
Well, know I know how to use it. The problem is that is being applied to all the object and not only to the section I wanted but in anyway.

The problem now is the uvw coordinates. the car model I used was downloaded from 3dcafe when it had the free stuff online, and the textures are not being applied well. So when used the multitexture is becomes very.... mmmm...... shinny or something. Anyway the efect I got on the car wasnt the expected but was cool in anyway, I wanted it to be like is the car body reflects on somehow the enviroment but I got a efect like if the car were made of somehow of reflective crystal. I like it but is not what I am looking for. Is there anyway to remove the textures and coordinates from the msp using jpct?

Here I left a (slow) video taken with fraps and passed to movie maker to reduce its size. The video is not as good as the original becausse passed for 2 programs. I also tried getting the shots to make an animated gif but on the pic number 170 I realized that was too heavy for a gif so I made this wmv.

have a look is just 2.18 MB.

www.soft-ec.com/Video/carro.wmv (http://www.soft-ec.com/Video/carro.wmv)
Title: Re: Reflection efect
Post by: EgonOlsen on June 16, 2007, 11:17:40 am
This doesn't look like multi-texturing to me. Can you post the section that initializes the textures and the environment mapping?
Title: Re: Reflection efect
Post by: Melssj5 on June 16, 2007, 04:58:48 pm
The problem are the texture coordinates of the car, because when applied to the circular base i got the desired effect but on the car not.

the code is:

Code: [Select]
//after loading the 3d and before calling to addObject and before calling to buildAllObjects

carro.setEnvmapped(Object3D.ENVMAP_ENABLED);
carro.setEnvmapMode(Object3D.ENVMAP_WORLDSPACE);


Code: [Select]
//for changing the color.
manejadorTexturas.replaceTexture ("AZUL.JPG", texturaActual);
        TextureInfo tis=new TextureInfo(manejadorTexturas.getTextureID("MAPA.JPG"));
        tis.add(manejadorTexturas.getTextureID("AZUL.JPG"), TextureInfo.MODE_ADD); // Or another mode...
        carro.setTexture(tis);


as said before th problem is when apply that to the car becausse on the base it works well. How can I remove the coordinates info?
Title: Re: Reflection efect
Post by: Klaudiusz on June 16, 2007, 05:31:09 pm
The reflection efect looks great but sometime object 3d is too big to use UV.

Can i set one texture as ENVMAP_WORLDSPACE and secound as ENVMAP_CAMERASPACE?
Title: Re: Reflection efect
Post by: EgonOlsen on June 16, 2007, 08:06:11 pm
Can i set one texture as ENVMAP_WORLDSPACE and secound as ENVMAP_CAMERASPACE?
On the same object? No. Only the first texture stage will be environment mapped. All others are simply using the u/v-coordinates assigned to that stage.
Title: Re: Reflection efect
Post by: EgonOlsen on June 16, 2007, 08:10:14 pm
as said before th problem is when apply that to the car becausse on the base it works well. How can I remove the coordinates info?
The code looks fine to me so far...but i don't get the problem with the texture coordinates that you describe. I'm not sure how exactly you want it to look like. What i was thinking of when posting the code snipped was an object textured normally but with a kind of "reflective layer" on top of it. For that, you need to assign the enviroment map as the first layer and the normal texture as the second. I'm not sure why you want to remove the texture coordinates for the second one... ???
Title: Re: Reflection efect
Post by: EgonOlsen on June 16, 2007, 08:42:00 pm
Here'a an example of what i was talking about: http://www.jpct.net/download/tmp/viper.zip (http://www.jpct.net/download/tmp/viper.zip)
Title: Re: Reflection efect
Post by: Klaudiusz on June 16, 2007, 10:43:01 pm
Well i just found there is also:

Quote
CurrentObject.calcTextureWrapSpherical();

Very usefull in reflection effect,when You don't have UV. GJ Egon:)
Title: Re: Reflection efect
Post by: Melssj5 on June 17, 2007, 04:26:46 am
<What i was thinking of when posting the code snipped was an object textured normally but with a kind of "reflective layer" on top of it.>

Exactly. But you saw the result. The color is not the one I put, irs much more whity that the original and the enviroment map was almost black.

When I put any texture to the car it is always shown as a full unique color.
Title: Re: Reflection efect
Post by: EgonOlsen on June 17, 2007, 12:40:09 pm
Then have a look at the example that i've posted to see if that is, what you want and try to adept it to your case.
Title: Re: Reflection efect
Post by: Melssj5 on June 17, 2007, 06:47:16 pm
ok, I saw the exmple and that is what I want, I will check the code but I am 100% that my problem is my car model, anyway I will check it.
Title: Re: Reflection efect
Post by: Melssj5 on June 18, 2007, 05:34:53 pm
Well, the code on the example is exactly the same I was using first, well my enviroment map was like full stars and make that effect. Anyway, my problem is now the base color of the object. it change a lot when I apply the enviroment map. I mean, it becomes very shinny.

I modelled another car, took me about 9 hours to have an own model but anyway, the results were the same, except that this new model is too heavy (1.2 MB) and make everything go slow. At night I will post the app to see if anyone can help me.
Title: Re: Reflection efect
Post by: EgonOlsen on June 18, 2007, 06:01:35 pm
That would be very helpful. My guess is, that you are simply using a not so appropriate texture, but we'll see...
Title: Re: Reflection efect
Post by: Melssj5 on June 19, 2007, 07:48:52 am
ok, posted, the link is:

the problem is that it becomes very shinny, the original blue is at the beggining and the desired colors can be seen on the car demo on the download section, they are the same textures for the replacement. It also runs very slow on GLCanvas but fast on normal OGL.

please dont laugh at my model, I spent 9 hours doing it.

www.soft-ec.com/Demos/carro.zip (http://www.soft-ec.com/Demos/carro.zip)

BTW: The javadoc should be upgraded on the IRENDERER modes.

PD: Its so shinny that even without any light nor an ambient light I can see it.
Title: Re: Reflection efect
Post by: EgonOlsen on June 19, 2007, 06:17:56 pm
As far as i can see, everything is technically correct. The visual effect (or defect...) mainly comes from a sub optimal environment map. Try to darken the texture or use another one (the one used by me in that "viper example" is a bit too subtle for your car...something in between may work fine). Plus, the model has very flat sides, which leads to a kind of on/off-reflection when viewing it from the side, because all vertex normals of the whole side are pointing into the same direction. You may also try to play around with the blending mode used the apply the base map.
It's all a question of art in this case, i'm afraid.
Title: Re: Reflection efect
Post by: EgonOlsen on June 19, 2007, 06:30:07 pm
BTW: The javadoc should be upgraded on the IRENDERER modes.
They are bit sparse indeed. What information exactly are you missing?
Title: Re: Reflection efect
Post by: Melssj5 on June 19, 2007, 08:18:53 pm
so,its normal to get a so shinny result texture? Then I wont be able to exactly control the resultant color. Well, about the flat sides,I already noticed that but that was a modelling stuff that is easy to fix but I was worried about the shinnyness,  it seems to have self illumination becausse even without lights it appear and I guess it shouldnt becausse I wont even be able to control the visualization playing with the lights! Can this be "fixed" assuming its a problem!?!?!?

I thought that the IRENDERER fields had new names but I guess I was wrong. I was tired when wrote that.
Title: Re: Reflection efect
Post by: EgonOlsen on June 19, 2007, 08:59:57 pm
it seems to have self illumination becausse even without lights it appear and I guess it shouldnt becausse I wont even be able to control the visualization playing with the lights! Can this be "fixed" assuming its a problem!?!?!?
And finally, i understood your problem... :) Well, the behaviour itself can't be fixed. It's caused by the OpenGL pipeline which works like this when using multi-texturing:

(http://www.jpct.net/img/opengl_mt_pipeline.png)

As you can see, vertex colors are being applied first, then modulated (always, you can't change this) with the first texture stage's output. The result will be taken and blended with the second stage...etc. In your case, the second stage blends using ADD, which simply adds the color. Because this stage contains the base texture and the lights are off, you end up with 0+base_color=base_color which is why the model looks so bright even with no vertex lighting being used.
I'll have a look at this behaviour. Maybe it's possible to shift the enviroment mapping to the second layer somehow. In the meantime, you may play around with other blending modes like MODULATE, which doesn't suffer from this problem.
Title: Re: Reflection efect
Post by: EgonOlsen on June 20, 2007, 12:05:35 am
Ok, i've added support for shifting the environment map to the second texture stage if available. This is kinda hacky, so i'm not sure that it works 100%. Anyway, here's the jar: http://www.jpct.net/download/beta/jpct.jar (http://www.jpct.net/download/beta/jpct.jar)

and here are the docs for a new setting in Config:

Code: [Select]

        /**
* By default, an environment map will be applied to the first texture stage if
* environment mapping is used on an object. When combining it with multi texturung,
* this may not always be want one wants, because the lighting calculations of OpenGL
* may give you undesired results by applying the lighting to the environment map
* instead of the base map. To work around this problem, you can force jPCT to use the
* second texture stage for environment mapping, if (and only if) the object uses multiple
* stages. However, jPCT doesn't check if a particular polygon uses multiple stages. So
* if you are forcing environment mapping to stage 2, make sure that your multi textured
* object all have that stage for all polygons and that the correct textures are assigned.
* Default is false.
*/
public static boolean glForceEnvMapToSecondStage=false;

To use it in your app, set it to true and swap the texture assignments in the TextureInfo-creation. Please let me know if this fixes your problem somehow.
Title: Re: Reflection efect
Post by: Melssj5 on June 20, 2007, 04:40:49 am
ok I will test it now
Title: Re: Reflection efect
Post by: Melssj5 on June 20, 2007, 05:35:38 am
Yes it worked! Now I sill fix my model to avoid reflecting all the side. Thanks a lot.
Title: Re: Reflection efect
Post by: Melssj5 on June 21, 2007, 09:10:56 am
Hi, this is the link of the new version. Please can you post it con the download section, maybe removing the old version from there, or maybe keeping it as an old version. I dont know.

this version has the enviroment map applied, a better car model, and is better deployed. Maybe I will add an enviroment like a garage or something, but later.

www.soft-ec.com/Demos/CarView.zip (http://www.soft-ec.com/Demos/CarView.zip)
Title: Re: Reflection efect
Post by: EgonOlsen on June 21, 2007, 05:44:41 pm
Ok, i've updated the download with the new version.
Title: Re: Reflection efect
Post by: Melssj5 on June 21, 2007, 07:44:02 pm
Hey Egon, I tested it on a P4 2.67, 512 MB, GeForce4 64 MB and worked fine. Tested also on a P4 3.2 HT, 512MB, Via C3 32MB and worked but the reflection effect doesnt appear.


I could understand that is due to the bad quality of the video card via c3 but, it used to shown the enviroment map on the official version of jpct, but with the new beta you made it didnt. I mean that the video card showed the reflection that was undesired but not the desired one.
Title: Re: Reflection efect
Post by: Melssj5 on June 22, 2007, 06:31:19 am
Another issue with this. Can I have the original Texture and the reflection at the same time. When I set enable the enviroment map the texture does not apply correctly, when using full color textures its okay, but now I want to put some images on my textures, not only color. Can that be done?
Title: Re: Reflection efect
Post by: Melssj5 on June 22, 2007, 07:14:21 am
BUG1:When more than 2 textures are applied to the TextureInfo, the enviroment issue got disabled or something (dont reflect anything).

BUG2:When another texture is added the number of polygons increase! Each texture stage means painting all the polygons again? when added 3 stages some polygons were not visible, I needed to increase the amount in Config.maxPolysVisible! Is this normal?
Title: Re: Reflection efect
Post by: EgonOlsen on June 22, 2007, 08:50:22 am
The GeForce4MX is a Geforce2 derivative, which means that it has only 2 texture stages (the renderer should state something like this when initializing). That means that 2 textures can be processed in one pass, which is what jPCT does. When adding another texture, jPCT falls back to multiple passes, i.e. rendering each triangle multiple times, which is why the size increases and rendering slows down significantly. This is not a bug, it's a feature.
The first problem is related to this (or so i think), because when adding another texture, the preconditions mentioned in the Config-setting aren't met any longer, i.e. enviroment map isn't on stage 2 anymore, which basically means that in this case, you would have to revert the envmap to stage 1 again. But the application has to do this, i can't do it automatically.
Title: Re: Reflection efect
Post by: Melssj5 on June 22, 2007, 03:54:30 pm
Ok, I guess I should do some combination of the textures to have it as only one Texture and then apply it. Can you put on the class Texture an add method to do this, to put 2 textures and combine then into one single texture, maybe by adding the colors or something.
Title: Re: Reflection efect
Post by: EgonOlsen on June 22, 2007, 04:09:18 pm
Can you give an example of what you mean exactly (screenshot)?
Title: Re: Reflection efect
Post by: Melssj5 on June 22, 2007, 06:01:14 pm
mmmmm I am at the office but I mean for example:

Texture t1=new Texture ("Name1", "path1");
Texture t2=new Texture ("Name2", "path2");

Texture T=Texture.add ("Name3", t1, t2);

Like in the TextureInfo but joining it into a new one. On that way multi textures can be put using only 2 stages. one for the env and one for the base texture.

ok here are the shots.

T=t1+t2

(http://www.soft-ec.com/Demos/T.JPG)=(http://www.soft-ec.com/Demos/t1.jpg)+(http://www.soft-ec.com/Demos/t2.jpg)

http://www.soft-ec.com/Demos/T.JPG
=
http://www.soft-ec.com/Demos/t1.jpg
+
http://www.soft-ec.com/Demos/t2.jpg
Title: Re: Reflection efect
Post by: EgonOlsen on June 22, 2007, 09:19:32 pm
Ok, i see...well, actually i don't see, because i can't access the images (forbidden!) but anyway. If needed, i can add that albeit i'm not sure that it is. Java's capabilities should be more than sufficient to blend two images together. However, i don't really care...if you still want it, i'll add it for the next release.
Title: Re: Reflection efect
Post by: hytparadisee on June 23, 2007, 04:49:34 am
Just a bit worried -> ??? Would that affect any other aspects of jpct (especially performance-wise)?
Title: Re: Reflection efect
Post by: EgonOlsen on June 23, 2007, 10:46:50 am
Would that affect any other aspects of jpct (especially performance-wise)?
The change for environment mapping? No. Or were you talking about something else?
Title: Re: Reflection efect
Post by: Melssj5 on June 25, 2007, 05:22:01 pm
ok I better made this:

http://www.soft-ec.com/Demos/

http://www.soft-ec.com/Demos/ (http://www.soft-ec.com/Demos/)

This is the result I need, on that way the multiTexture efect doesnt need to be applied to a whole Object but can be aplied replacing a texture. Many objects loaded has more than one texture. And the env can be applied with just 2 stages.
Title: Re: Reflection efect
Post by: Peter Dym on July 10, 2012, 05:55:17 pm
Hi Egon,

I know, this is the old thread, but related to my actuqal problem. I was asked in my office to show a simple window with one rotated object. I piece of cake.
I am familiar with jpct so no problem. And I spent 2 days or more to do it in the reasonable quality and - no way. It should be very realistic and I'm missing the bacis reflection feature. And have no idea how to do it. I'm not total beginer (see my Airdroid project http://www.jpct.net/projects.html ) but to create an usable specular reflection is too much. I'm not restricted by Android OS or by performance because it should be an applet with one rotated object (which I have already done but - I have nothing to show actually). I need something like http://www.esko.com/en/Products/overview/studio/visualizer-gallery . Is there a way how to do that? I was so despaerate that I started with jMonekyEngine, which looks good but every step was and is accompanied with very exotic exceptions like "Your object does not contain faces" or "Expected version of something is lover that provided" :-) . So I would rather stay wit our cute jpct. Any suggestion?
Title: Re: Reflection efect
Post by: EgonOlsen on July 10, 2012, 09:23:50 pm
"Amazing" applet, that visualizer thing...it seems to use native code to create the slowest software renderer that i've even seen. Anyway, i'm not 100% sure what you want and what the problem is. Do you mean a basic (albeit faked) reflection effect like this one:

(http://jpct.de/pix/car_env.jpg)

?? That's actually pretty simple to do. You need the basic texture map and a spherical enviroment map (examples: http://www.codemonsters.de/home/content.php?show=spheremaps (http://www.codemonsters.de/home/content.php?show=spheremaps)). You create a TextureInfo with the enviroment map as first and the actual texture map as second texture (blending mode depends on the textures...i would start with MODE_ADD), assign that your object and enable environment mapping by doing

Code: [Select]
obj.setEnvmapped(Object3D.ENVMAP_ENABLED);
obj.setEnvmapMode(Object3D.ENVMAP_CAMERASPACE);

Title: Re: Reflection efect
Post by: Peter Dym on May 29, 2013, 08:43:47 pm
just fyi:

I had to work on something alse to make some money so no 3d games :-) and then I was asked to do a prototype of a 3d viewer. This is the result:

http://www.youtube.com/watch?v=V9gPfFFT4pM
http://www.youtube.com/watch?v=vlhMONC_AQY