Material Environment Maps in Codea 3

One is a screenshot of the material in Shade and the other of Codea, my material isn’t showing an environment map, even when I set it in code. I also tried using Codea’s materials but it also didn’t work. Any idea on how this could be fixed?


That’s odd. Do you have an example project for me to look at?

1 Like

Hey John, glad you saw this, here’s a simple project, make sure you set cameras as a dependency.

function setup()
    scene = craft.scene()
    scene.sky.material = craft.material(asset.builtin.Materials.Atmosphere)
    
    scene.camera:add(OrbitViewer, vec3(0,0,0), 10, 0, 50)
    scene.camera:get(OrbitViewer).rx = 45
    scene.camera:get(OrbitViewer).ry = 220
    
    cube = scene:entity()
    cube.model = craft.model.cube(vec3(1,1,1))
    cube.material = craft.material(asset.builtin.Materials.Standard)
    cube.material.roughness = 0
    --cube.material.envMap = craft.cubeTexture(asset.documents.HDR_029_Sky_Cloudy_Bg)
end

function draw()
    scene:draw()
    scene:update(DeltaTime)
end

function touched(touch)
    scene.camera:get(OrbitViewer):touched(touch)
end

@John Have you had a chance to look at it yet?

Thanks for waiting patiently. I had to dig through some older code to figure out exactly how it all works in Shade and how that translates to codea. You just need to set scene.environment = hdrAssetKey and it should work. Shade actually has an environment probe so it can reflect the ground/grid plane. Here’s the project updated to use the probe code from Shade. The probe will let you reflect the atmosphere material (since it’s a dynamic shader it has to be baked into a irradiance cube map to work)

EnvMap Issue.zip (1.6 KB)

1 Like

Awesome, I downloaded your project and tested it but I get some weird borders around the cube map. I tried lowering and increasing the resolution of the probe but no difference; I don’t really mind it though as just having a reflection is exactly what I wanted, and you even coded a reflection probe. Thank you

and here’s an image for reference:


I might figure it out eventually and post a solution here, thanks for the help again.

1 Like

Hmm, that’s interesting. It’d be either a problem with the environment probe class or an issue with the irradiance generator. I’m assuming you don’t get that issue in Shade?

I just noticed, I also get in Shade;

1 Like

Ok I’ll need to have a look into it. By the way, what device and iOS version are you using?

iPhone 14 Pro iOS 16.5.1

One last thing, is it possible for different objects to have different reflection probes?

Not at the moment, the way the lighting works is pretty basic, what were you planning on doing with multiple probes?