How can I make Environment Map (reflection) visible in Lighting.j3md?

Hi All!

After looking around on the forums, I came across this post, which shows how you can use Lighting.j3md to render an Environment Map on your material. This is exactly what I want, so I tried it myself:

[java]

    reflectionTexture = assetManager.loadTexture("Textures/EnvMaps/OutputCube.dds");
    reflectionMap = new TextureCubeMap( reflectionTexture.getImage());

    vehicleMaterial = new Material(aM, "Common/MatDefs/Light/Lighting.j3md");
    vehicleMaterial.setFloat("Shininess", 50);
    vehicleMaterial.setParam("DiffuseMap", VarType.Texture2D, aM.loadTexture("Models/Vehicles/Tuktuk/baked_tuktuk.png"));
    vehicleMaterial.setBoolean("UseMaterialColors",true);    
    vehicleMaterial.setBoolean("UseAlpha",true);    
    vehicleMaterial.setColor("Diffuse",ColorRGBA.White);
    vehicleMaterial.setColor("Specular",ColorRGBA.White);
    vehicleMaterial.setParam("EnvMap", VarType.TextureCubeMap, reflectionMap);   // <-- Set the environment map here

    vehicleModel.setMaterial(vehicleMaterial);

[/java]

The problem is that the environment map is not visible on the material at all. The diffuse is, and changing other values such as the Specular colour etc. does have an effect, so I’m sure I’m not mixing up materials!

Would you mind telling me what I’m doing wrong?

  • Thank you!

I know it says on that post: “set use UseReflection to true” and you should also set “ReflectionPower”, and “ReflectionIntensity”, but how do I access these parameters? Looking through Lighting.j3md, I couldn’t see these parameters.

Try this ones

    // Env Map for reflection
    TextureCubeMap EnvMap

    // the env map is a spheremap and not a cube map
    Boolean EnvMapAsSphereMap

And maybe the fresnel parameters.

    // Parameters for fresnel
    // X = bias
    // Y = scale
    // Z = power
    Vector3 FresnelParams

These are probably bad if all left at 0.

Or you could just look at the environment map test and see what’s different.

Wow - quick responses! Thank you very much!

Empire Phoenix, as far as I am aware, I was already setting the EnvMap with the line:

[java]
vehicleMaterial.setParam(“EnvMap”, VarType.TextureCubeMap, reflectionMap); // <– Set the environment map here
[/java]

pspeed, Those parameters helped a lot, and I wasn’t aware of the Environment Map test. I had a look at this and it’s helped a lot! I have the environment map working properly now, thanks very much! I would guess they defaulted to 0.

What do I use to mask out the areas which I don’t want it to ‘reflect’ (areas where the environment map doesn’t appear)? Is it the specular map?

It should be based on it i presume, would at least make sense to me.