Environment Mapping with Software

Started by AGP, February 06, 2018, 06:40:35 PM

Previous topic - Next topic

AGP

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?


     private void combineAmbientAndDiffuse() {
Texture tex = TextureManager.getInstance().getTexture("EnvironmentMap");
tex.add(TextureManager.getInstance().getTexture("Starfighter.png"), .5f);
     }

EgonOlsen

Just to clarify this: With "ambient map", you mean the environment map?

AGP


AGP

#3
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...


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);
     }
}

EgonOlsen

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.

EgonOlsen

About the PolyLine in software mode: I've no plans to add support for this, I'm afraid.

AGP

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.

AGP

#7
So I wrote prepareForSoftware() as follows. Trouble is I'm sensing that the order of the operations is wrong. It's currently going:


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:


     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:


     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).

EgonOlsen

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?

AGP

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)?

EgonOlsen

...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.