Author Topic: Environment Mapping with Software  (Read 778 times)

Offline AGP

  • quad
  • ******
  • Posts: 1609
    • View Profile
Environment Mapping with Software
« on: February 06, 2018, 06:40:35 pm »
One of my ships is shiny. I have a vague memory of talking to you about environment mapping with the software renderer. I fully expected that the environment map would not work with the software renderer, but my expectation was that the diffuse map would be completely replaced by the environment map and that the environment map would be treated as diffuse. This is not so. Ambient map acts like the ambient map but the diffuse channel disappears. To that end, I tried writing the following method. But obviously, the result is that the ambient map is just colored by the diffuse. My question, then, is since the environment mapping is already performing as expected, would it be possible to just make the diffuse channel work with it?

Code: [Select]
     private void combineAmbientAndDiffuse() {
Texture tex = TextureManager.getInstance().getTexture("EnvironmentMap");
tex.add(TextureManager.getInstance().getTexture("Starfighter.png"), .5f);
     }
« Last Edit: February 08, 2018, 05:25:11 pm by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11895
    • View Profile
    • http://www.jpct.net
Re: Ambient Mapping with Software
« Reply #1 on: February 07, 2018, 10:45:44 am »
Just to clarify this: With "ambient map", you mean the environment map?

Offline AGP

  • quad
  • ******
  • Posts: 1609
    • View Profile
Re: Ambient Mapping with Software
« Reply #2 on: February 07, 2018, 12:16:18 pm »
Yes, sorry.

Offline AGP

  • quad
  • ******
  • Posts: 1609
    • View Profile
Re: Environment Mapping with Software
« Reply #3 on: February 09, 2018, 01:30:59 am »
Do you have a response?

Also, I know I keep hitting the same keystrokes but, Polyline for the software renderer? It's really very important. I wrote the following class. Even if it worked all of the time, it would still be a bit of a hack...

Code: [Select]
import java.awt.*;
import com.threed.jpct.*;

public class PolylineSoft extends Polyline {
     private SimpleVector[] points;
     public PolylineSoft(SimpleVector[] points, java.awt.Color color) {
super(points, color);
this.points = points;
     }
     public void update(SimpleVector[] newPoints) {
super.update(newPoints);
this.points = newPoints;
     }
     public void draw(Graphics g, Camera cam, FrameBuffer buffer) {
Color oldColor = g.getColor();
g.setColor(super.getColor());
for (int i = 0; i < points.length-1; i++) {
     SimpleVector p1 = Interact2D.project3D2D(cam, buffer, points[i]);
     SimpleVector p2 = Interact2D.project3D2D(cam, buffer, points[i+1]);
     if (p1 == null || p2 == null)
continue;
     g.drawLine((int)p1.x, (int)p1.y, (int)p2.x, (int)p2.y);
}
g.setColor(oldColor);
     }
}
« Last Edit: February 09, 2018, 04:46:44 am by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11895
    • View Profile
    • http://www.jpct.net
Re: Environment Mapping with Software
« Reply #4 on: February 09, 2018, 12:10:32 pm »
The software renderer doesn't support multiple texture layers. Or at least not in the way in which the hardware renderer does. You could use a different path for the software renderer and use setBlending(true). Then assign three textures to it (diffuse, envmap and envbump) but use a single colored texture with (128/128/128) as color value for the envbump texture. That should give you some kind of blending between diffuse and env.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11895
    • View Profile
    • http://www.jpct.net
Re: Environment Mapping with Software
« Reply #5 on: February 09, 2018, 12:15:32 pm »
About the PolyLine in software mode: I've no plans to add support for this, I'm afraid.

Offline AGP

  • quad
  • ******
  • Posts: 1609
    • View Profile
Re: Environment Mapping with Software
« Reply #6 on: February 09, 2018, 04:00:40 pm »
I'll try the setBlending thing and report back.

Why not? Academically, you have to agree that there should be no difference between what each renderer can render.

Offline AGP

  • quad
  • ******
  • Posts: 1609
    • View Profile
Re: Environment Mapping with Software
« Reply #7 on: February 09, 2018, 07:09:40 pm »
So I wrote prepareForSoftware() as follows. Trouble is I'm sensing that the order of the operations is wrong. It's currently going:

Code: [Select]
texInfo = new TextureInfo(tm.getTextureID("EnvironmentMap"));
texInfo.add(tm.getTextureID("Starfighter.png"), TextureInfo.MODE_ADD_SIGNED); //MODE_ADD, MODE_BLEND, MODE_MODULATE, MODE_ADD_SIGNED
in the constructor. Then, once it's been established that the renderer in use is software:

Code: [Select]
     public void prepareForSoftware() {
TextureManager.getInstance().addTexture("GreyBump", new  Texture(1024, 1024, new java.awt.Color(128, 128, 128)));
body.setBlending(true);
texInfo.add(TextureManager.getInstance().getTextureID("Starfighter.png"), TextureInfo.MODE_ADD_SIGNED);
texInfo.add(TextureManager.getInstance().getTextureID("GreyBump"), TextureInfo.MODE_ADD_SIGNED);
     }

No go. On the other hand:

Code: [Select]
     public void prepareForSoftware() {
TextureManager.getInstance().addTexture("GreyBump", new  Texture(1024, 1024, new java.awt.Color(128, 128, 128)));
body.setBlending(true);
texInfo = new TextureInfo(TextureManager.getInstance().getTextureID("Starfighter.png"));
texInfo.add(TextureManager.getInstance().getTextureID("EnvironmentMap"), TextureInfo.MODE_ADD_SIGNED);
texInfo.add(TextureManager.getInstance().getTextureID("GreyBump"), TextureInfo.MODE_ADD_SIGNED);
body.setTexture(texInfo);
     }
produces a very similar effect to my combineAmbientAndDiffuse() method (the diffuse information is not in the right place but the environment map, tinted by the diffuse color, behaves right).
« Last Edit: February 10, 2018, 04:57:58 am by AGP »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11895
    • View Profile
    • http://www.jpct.net
Re: Environment Mapping with Software
« Reply #8 on: February 12, 2018, 09:42:43 am »
I'm not sure what you mean. Do you have  a screen shot of how it looks like and how it's supposed to look like?

Offline AGP

  • quad
  • ******
  • Posts: 1609
    • View Profile
Re: Environment Mapping with Software
« Reply #9 on: February 13, 2018, 05:26:53 am »
I'll send it to you as soon as possible, via email.

Would you as least show me how I could do Polyline so that my lines would take the depth buffer in consideration (as it stands, my little hack gets drawn over everything)?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11895
    • View Profile
    • http://www.jpct.net
Re: Environment Mapping with Software
« Reply #10 on: February 13, 2018, 09:13:08 am »
...you would have to write yourself a line algorithm that not just interpolates x and y but also z (or the reciprocal of z) just like the polygon rendering routines do.