Author Topic: Is flat shading works fine on my device?  (Read 862 times)

Offline ppparkje

  • byte
  • *
  • Posts: 9
    • View Profile
Is flat shading works fine on my device?
« on: June 27, 2012, 09:19:20 am »
Hi. I am newbie of 3D graphics programming and now working on some tutorials.

I have a lot to question, but I'll do a few of them.

The first one is, as mentioned above, the shading method.

I think the gouraud shading works fine, but when I switch it to flat shading, it renders like this:



and here is the code.

Code: [Select]

@Override
public void onDrawFrame(GL10 gl) {
cube.rotateY(m_cam.convertDEGAngleIntoFOV(0.5f));

buffer.clear(colBackground);
m_world.renderScene(buffer);
m_world.draw(buffer);
buffer.display();
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if(buffer == null) {

Util.LOGD("make framebuffer");
m_world = new World();
m_cam = m_world.getCamera();

m_light = new Light(m_world);
m_light.setIntensity(250, 250, 250);
m_light.setPosition(new SimpleVector(50, -50, 50));

m_world.setAmbientLight(0, 0, 0);

Texture t = new Texture(100, 100, new RGBColor(0, 0xff, 0, 0x7f));
TextureManager.getInstance().addTexture("test", t);
TextureManager.getInstance().addTexture("bottom", new Texture(100, 100, RGBColor.BLUE));
cube = Primitives.getBox(10, 1);
cube.setShadingMode(Object3D.SHADING_FAKED_FLAT);
cube.setEnvmapped(true);
cube.calcTextureWrap();
cube.translate(0, -10, 0);
cube.setTexture("test");
cube.strip();
cube.build();
m_world.addObject(cube);

m_bottomPlane = Primitives.getPlane(20, 300);
m_bottomPlane.translate(SimpleVector.ORIGIN);
m_bottomPlane.setSpecularLighting(true);
m_bottomPlane.calcTextureWrap();
m_bottomPlane.rotateX((float)Math.PI/2f);
m_bottomPlane.setTexture("bottom");
m_bottomPlane.build();
m_world.addObject(m_bottomPlane);

m_cam.setPosition(20, -20, 20);
m_cam.lookAt(cube.getTransformedCenter());

}

if(buffer != null)
buffer.dispose();
buffer = new FrameBuffer(gl, width, height);

MemoryHelper.compact();
}

Can anybody check the code it's right? I wonder it's on my device-specific issue. (I use HTC sensation with ICS)


And the second question is..

I'd like to accomplish a cartoonish rendering. For example, I think it can be simply done to a cube(in the code above) by boldening the edges. But I have no idea of implementing it. Moreover, I even do not know how to draw a line in 3D space. Can I get a hint of that?

Thanks for listening me and sorry for my poor english.
« Last Edit: June 27, 2012, 09:21:23 am by ppparkje »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Is flat shading works fine on my device?
« Reply #1 on: June 27, 2012, 10:07:43 am »
Try to remove this line:

cube.setEnvmapped(true);

The environment mapping is based on the vertex normals. In case of faked flat shading, these are tweaked in a way that might cause the environment mapping to go crazy.

However, flat shading won't give you cartoonish rendering (why does "everyone" wants this btw? All games that used it failed more or less...). You need a shader to do this (like here, but for desktop jPCT: http://www.jpct.net/forum2/index.php/topic,2821.0.html). If you want to create the outlines in the way that it's done in that thread, i'll finally have to add wireframe rendering to jPCT-AE...it missing ATM, because nobody really needed it so far. Another option is to create the outlines by rendering a slightly larger version of the object with an all-black-shader.

Offline ppparkje

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Is flat shading works fine on my device?
« Reply #2 on: June 27, 2012, 10:39:27 am »
Hmm.. I tried to remove and change argument, but both didn't work.

However flat shading renders fine only if when i don't use any light except ambient. But this time the cube has no shading.....;

First attached file is screenshot with code you mentioned, and second is coded with no light object.


By the way, Thanks for guiding to new shading. I must learn about composing and compiling shader in jPCT.

[attachment deleted by admin]