Author Topic: Flat Shading + Culling = Black  (Read 1206 times)

Offline aZen

  • int
  • **
  • Posts: 94
    • View Profile
Flat Shading + Culling = Black
« on: May 16, 2013, 12:57:06 pm »
When I use

Code: [Select]
object3D.setAdditionalColor(SOME_COLOR);
object3D.setShadingMode(Object3D.SHADING_FAKED_FLAT);
object3D.setTransparency(0);
object3D.setCulling(false);

in software mode, everything is rendered transparent, but just black. Is this something that could be fixed without too much effort?

Thank you,
aZen

Edit: Edited the title to reflect the problem better.
« Last Edit: May 16, 2013, 02:07:40 pm by aZen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Flat Shading + Transparency = Black
« Reply #1 on: May 16, 2013, 01:10:53 pm »
And without transparency being used...?

Offline aZen

  • int
  • **
  • Posts: 94
    • View Profile
Re: Flat Shading + Transparency = Black
« Reply #2 on: May 16, 2013, 01:50:48 pm »
Oh... it's also black.

So the culling is the problem?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Flat Shading + Culling = Black
« Reply #3 on: May 16, 2013, 04:17:13 pm »
It might be, if you are looking into the model. But then you should get the same effect without flat shading. Do you?

Offline aZen

  • int
  • **
  • Posts: 94
    • View Profile
Re: Flat Shading + Culling = Black
« Reply #4 on: May 17, 2013, 11:54:51 am »
I've created a minimal test cast:

Code: [Select]
package vitco;

import com.threed.jpct.*;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * Testing problem where object is rendered black.
 */
public class BlackJPCT extends WindowAdapter implements MouseMotionListener {
    static FrameBuffer buffer;
    static World world;
    Object3D box;
    JFrame frame;

    public BlackJPCT() {
        // set up frame
        frame = new JFrame("Hello Black!");
        frame.setSize(800, 600);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

        // set up world
        world = new World();
        world.setAmbientLight(0, 0, 0);
        world.addLight( new SimpleVector(500,-500,500), new Color(20,20,20) );
        Config.fadeoutLight = false;

        // ==========================

        box = Primitives.getBox(10f, 1f);

        box.setAdditionalColor(Color.RED);

        // ###############################
        // ###############################
        // if I comment out either of these two lines
        // the object is no longer rendered as black
        box.setShadingMode(Object3D.SHADING_FAKED_FLAT);
        box.setCulling(false);
        // ###############################
        // ###############################
       
        box.build();

        world.addObject(box);

        // ==========================

        // set up camera
        world.getCamera().setPosition(50, -50, -5);
        world.getCamera().lookAt(SimpleVector.ORIGIN);

        // set up frame buffer
        buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);

        // set up event handler
        frame.addMouseMotionListener(this);
        frame.addWindowListener(this);
    }

    @Override
    public void windowClosing(WindowEvent e) {
        // clean up when closing
        buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
        buffer.dispose();
        frame.dispose();
        System.exit(0);
    }

    @Override
    public void mouseDragged(MouseEvent e) {}

    @Override
    public void mouseMoved(MouseEvent e) {
        box.rotateY(0.01f);
        // animate and redraw
        buffer.clear(Color.LIGHT_GRAY);
        world.renderScene(buffer);
        world.draw(buffer);
        buffer.update();
        buffer.display(frame.getGraphics());
    }

    // constructor
    public static void main (String[] args) {
        new BlackJPCT();
    }
}

The essence from that test case:
Code: [Select]
// if I comment out either of these two lines
// the object is no longer rendered as black
box.setShadingMode(Object3D.SHADING_FAKED_FLAT);
box.setCulling(false);

Thank you for your help!
« Last Edit: May 17, 2013, 11:57:04 am by aZen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Flat Shading + Culling = Black
« Reply #5 on: May 17, 2013, 04:52:25 pm »
It's a bug, thank you for the test case. This jar should fix it: http://jpct.de/download/beta/jpct.jar

Offline aZen

  • int
  • **
  • Posts: 94
    • View Profile
Re: Flat Shading + Culling = Black
« Reply #6 on: May 17, 2013, 07:54:42 pm »
It's fixed! Thank you!