Car Reflections

Started by Locust, June 01, 2017, 09:40:40 AM

Previous topic - Next topic

Locust

Hey

I have a 3d model of a car with a single texture and to make it look good I need to have some kind of reflections on the metal.

Whats the best way to achieve a more realistic look?

EgonOlsen

The easiest way would be to use a custom shader and second texture for a spherical environment map. That wouldn't give you proper reflections, but it might look good enough. I can provide you with a basic shader example for that it that helps.

Locust

Quote from: EgonOlsen on June 01, 2017, 01:51:23 PM
The easiest way would be to use a custom shader and second texture for a spherical environment map. That wouldn't give you proper reflections, but it might look good enough. I can provide you with a basic shader example for that it that helps.

That would be great, since I havent touched shaders yet.

EgonOlsen

Here are some example shaders. I'm not entirely sure if they compile, because I merged them together from two other ones without testing them, but anyway...

http://www.jpct.net/download/tmp/shaders.zip

Usage would be to create an instance of GLSLShader with them and assign that to the car object. The car object itself needs two texture layers (look at TextureInfo for this), one is the car's normal texture and the other would be something like this: http://graphics.stanford.edu/papers/envmap/Figs/rnl_probe.gif

Locust

This is the code I use for creating the shader and loading the textures.

I dont seem to get the desired result with this. I also tried different Modes when adding the second texture to the TextureInfo, aswell as changing the order in which the textures are assigned to the TextureInfo.
The transparency on the result is also messed up.

Am I doing something wrong?


            String vertex = Loader.loadTextFile(mContext.getResources().openRawResource(R.raw.reflection_vert));
            String fragment = Loader.loadTextFile(mContext.getResources().openRawResource(R.raw.reflection_frag));
            GLSLShader shader = new GLSLShader(vertex,fragment);

            Texture texture = new Texture(mContext.getResources().openRawResource(R.raw.hatchback_diffuse));
            texture.keepPixelData(true);
            if(!TextureManager.getInstance().containsTexture("car_diffuse"))
                TextureManager.getInstance().addTexture("car_diffuse", texture);

            Texture environment = new Texture(mContext.getResources().openRawResource(R.raw.environment));
            if(!TextureManager.getInstance().containsTexture("environment"))
                TextureManager.getInstance().addTexture("environment",environment);

            TextureInfo textureInfo = new TextureInfo(TextureManager.getInstance().getTextureID("car_diffuse"));
            textureInfo.add(TextureManager.getInstance().getTextureID("environment"),TextureInfo.MODE_ADD);

            o3d.setTexture(textureInfo);
            o3d.setShader(shader);

EgonOlsen

It might be that the shaders don't support transparency as they are, but that can be added easily. However, before dealing with that, I would like to know what exactly are your desired results and what you get instead. A screen shot might help...

Locust

I actually fixed the transparency issues, that was an error on my end. So the car model is part of an augmented reality app and I want it to better blend in to the real world.

The first picture shows the car with the simple texture and no shader.

The 2nd picture shows the car with the shader and MODE_BLEND and you can see that it is just darkening the mode in some areas. I tried different modes which looked even worse.


Also to get it more realistic is there an option to make it use specular lightning? I know there is setSpecularLightning but does it do anything if I have a shader applied?

EgonOlsen

Actually, the blending mode has no impact if you are using a shader, because the shader does the blending. That happens here, in the fragment shader:

texture2D(textureUnit0, texCoord1)+texture2D(textureUnit1, texCoord)


Replacing the + by * gives you modulate blending. You are free to play around with some combination of vertex colors and both textures' colors to get something pleasing.

For specular, you would have to modify the lighting calculation in the shader. A simple hack might be to use the square root of the lighting's intensity instead of the intensity itself. If that's not good enough, you have to switch to per pixel lighting somehow.

Locust

#8
Quote from: EgonOlsen on June 22, 2017, 10:52:02 AM
Actually, the blending mode has no impact if you are using a shader, because the shader does the blending.
Hmm thats super weird then, because it definitely changes the outcome for me.
e.g. heres the same  scene just with add instead of  blend.

Quote from: EgonOlsen on June 22, 2017, 10:52:02 AM
For specular, you would have to modify the lighting calculation in the shader. A simple hack might be to use the square root of the lighting's intensity instead of the intensity itself. If that's not good enough, you have to switch to per pixel lighting somehow.

Gonna look into that

EgonOlsen

Then your shader isn't active...

Locust

hmm youre right, I still had to change the Open GL ES version, I did change the lines mentioned here:
http://www.jpct.net/wiki/index.php?title=OpenGL_ES_2.0_support

But now I get a complete black screen instead, are there any major incompatibilities between the standard OpenGL version and 2.0?


EgonOlsen

No, actually there aren't. You aren't even supposed to notice the switch to 2.0 except for the added features.
How does your init code looks (GLSurfaceView and FrameBuffer creation) like? Are you getting any log output.

Locust

I did the changes to the init according to this link:
http://www.jpct.net/wiki/index.php?title=OpenGL_ES_2.0_support


mGLView = new GLSurfaceView(getApplication());
mGLView.setEGLContextClientVersion(2);

mGLView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);

fb = new FrameBuffer(w, h);

I couldnt find any relevent log output either. The 3D models are just not showing.

EgonOlsen

That setEGLConfigChooser(...) call isn't part of the Wiki page, or is it?

Try to use an instance of jPCT-AE's NVDepthConfigChooser instead.

Locust

mGLView.setEGLConfigChooser(new NVDepthConfigChooser(mGLView));

Using this line instead just results in a black screen, while the other config atleast showed the camera image. Both dont show any 3d Models though.