How to apply a glowing texture?

Okay this is, I think, it. Or as close to it as I think I’ll get.

The glow happens, though with only a verrrrry slight corona, and you can also see pretty clearly what skin the model is wearing.

(I’d love to have a larger corona, but I couldn’t figure out a setting with a large corona that still left visible details on the model.)

@dave1707 I get that you want to make things as simple as possible but sometimes that gives me less information than I need. For example, an unintended effect here is that for some reason these settings make the model semi-transparent. I would not have noticed that without the ability to rotate the model.

I’ll write up what I learned here in a little bit…

Ohhhhhhhh waitwaitwaitwait.

For some reason, after a figure has a glow switched off, its chest becomes all caved-in.

Darn it, now I’m lost again.

@UberGoober I want things I don’t know as simple as possible, that makes it easier to understand and see what’s happening. Once I understand that, then I can start adding more code in steps to try different things. For me that’s a lot easier then being shown a full blown program that does a lot of things and then try to figure out what code does what. For example, your program above shows the bloom effect in simple code whereas the AR Face example that shows the bloom is harder to figure out. At least it does for me. By reducing your code even further I was able to see exactly what was needed for the bloom.

@UberGoober to avoid the cave-in chest look, do not modify the blendMode.

@piinthesky if I don’t change the blend mode it looks like I don’t really get any glow, it just changes the color.

I mean, gosh, I make the effect by applying a material, isn’t there just some easy way to remove a material?

@UberGoober Does this help. Tap screen to turn bloom on/off. The robot doesn’t have the sunken chest look.

viewer.mode=STANDARD

function setup()
    fill(255)
    parameter.integer("Rotate",-180,180,-180)
    scene = craft.scene()
    scene.camera.position=vec3(0,0,-40)
    
    cameraComponent = scene.camera:get(craft.camera)
    cameraComponent.hdr = true
    cameraComponent.colorTextureEnabled = true
    
    bloom = craft.bloomEffect()
    cameraComponent:addPostEffect(bloom)
    bloom.threshold = 4
    bloom.intensity = 1.2
    bloom.softThreshold = 0.4
    bloom.iterations = 8
    
    material = craft.material(asset.builtin.Materials.Specular)
    material.map = readImage(asset.builtin.Blocky_Characters.RobotSkin)
    
    bloomMaterial = craft.material(asset.builtin.Materials.Basic)
    bloomMaterial.diffuse = vec3(2.5,1.5,4)
    
    ground = scene:entity()
    ground.model = craft.model(asset.builtin.Blocky_Characters.Robot)
    ground.position = vec3(0,-5,0)
end

function update(dt)
    scene:update(dt)
end

function draw()
    update(DeltaTime)
    ground.eulerAngles = vec3(0,Rotate, 0)
    scene:draw()
    text("tap screen",WIDTH/2,HEIGHT-50)
end

function touched(t)
    if t.state==BEGAN then
        gl=not gl
        if gl then
            ground.material = bloomMaterial
        else
            ground.material = material
        end
    end
end

@UberGoober Here’s an example showing 50 robots at random positions. You can rotate or highlight individual robots using the pos, Rotate, int parameters. You can also rotate, zoom in/out the whole group.

viewer.mode=STANDARD

function setup()
    tab={}
    scene = craft.scene()
    scene.sun.rotation=quat.eulerAngles(30,45,30)
    v=scene.camera:add(OrbitViewer, vec3(0,0,0), 200, 0, 1000)
    v.ry=180
    
    cameraComponent = scene.camera:get(craft.camera)
    cameraComponent.hdr = true
    cameraComponent.colorTextureEnabled = true
    
    bloom = craft.bloomEffect()
    cameraComponent:addPostEffect(bloom)
    bloom.threshold = 4
    bloom.intensity = 1.2
    bloom.softThreshold = 0.4
    bloom.iterations = 8
    
    material = craft.material(asset.builtin.Materials.Specular)
    material.map = readImage(asset.builtin.Blocky_Characters.RobotSkin)
    
    bloomMaterial = craft.material(asset.builtin.Materials.Basic)
    bloomMaterial.diffuse = vec3(2.5,1.5,4)
    
    ground = scene:entity()
    ground.model = craft.model(asset.builtin.Blocky_Characters.Robot)
    ground.position = vec3(0,0,0)
    
    for z=1,50 do
        local ground = scene:entity()
        ground.model = craft.model(asset.builtin.Blocky_Characters.Robot)
        x=math.random(-50,50)
        y=math.random(-50,50)
        z=math.random(-50,50)
        ground.position = vec3(x,y,z)
        table.insert(tab,{gr=ground,x=x,y=y,z=z,r=0,a=false})
    end
    parameter.integer("pos",1,#tab,position)
    parameter.integer("Rotate",-180,180,0,rotate)
    parameter.boolean("int",false,intensity)
end

function update(dt)
    scene:update(dt)
end

function rotate()
    tab[pos].r=Rotate
end

function draw()
    update(DeltaTime)
    tab[pos].gr.eulerAngles = vec3(0,tab[pos].r, 0)
    scene:draw()
end

function position()
    Rotate=tab[pos].r
    int=tab[pos].a
end

function intensity()
    if int then
        tab[pos].gr.material = bloomMaterial
        tab[pos].a=true
    else   
        tab[pos].gr.material = material
        tab[pos].a=false
    end
end

@dave1707 this is fantastic. I think I got hung up on what @Simeon said about being able to do it by just changing settings on the existing material, and I was trying to do everything without using two materials. But using two materials clearly works better.

Also @dave1707 I’m sorry I took a dig at your stripped-down-to-the-essentials code. You’re entirely right in your approach, I think.

@dave1707 there is one thing, when a model is switched off after it’s been glowing, its skin is noticeably lighter than it started. This is fixed if I set blendMode to NORMAL but that gets into the hollow-chest problem again.

@UberGoober I’m not sure what’s happening, but even before model #1 is switched on, I can see which Robot it is compared to the other ones.

PS. The intensity function is being called when the program starts, that why the #1 Robot is lighter.

@UberGoober Try this update. I added ground.material=material to the for loop.

viewer.mode=STANDARD

function setup()
    tab={}
    scene = craft.scene()
    scene.sun.rotation=quat.eulerAngles(30,45,30)
    v=scene.camera:add(OrbitViewer, vec3(0,0,0), 200, 0, 1000)
    v.ry=180
    
    cameraComponent = scene.camera:get(craft.camera)
    cameraComponent.hdr = true
    cameraComponent.colorTextureEnabled = true
    
    bloom = craft.bloomEffect()
    cameraComponent:addPostEffect(bloom)
    bloom.threshold = 4
    bloom.intensity = 1.2
    bloom.softThreshold = 0.4
    bloom.iterations = 8
    
    material = craft.material(asset.builtin.Materials.Specular)
    material.map = readImage(asset.builtin.Blocky_Characters.RobotSkin)
    
    bloomMaterial = craft.material(asset.builtin.Materials.Basic)
    bloomMaterial.diffuse = vec3(2.5,1.5,4)
    
    ground = scene:entity()
    ground.model = craft.model(asset.builtin.Blocky_Characters.Robot)
    ground.position = vec3(0,0,0)
    
    for z=1,50 do
        local ground = scene:entity()
        ground.model= craft.model(asset.builtin.Blocky_Characters.Robot)
        ground.material=material
        x=math.random(-50,50)
        y=math.random(-50,50)
        z=math.random(-50,50)
        ground.position = vec3(x,y,z)
        table.insert(tab,{gr=ground,x=x,y=y,z=z,r=0,a=false})
    end
    parameter.integer("pos",1,#tab,position)
    parameter.integer("Rotate",-180,180,0,rotate)
    parameter.boolean("int",false,intensity)
end

function update(dt)
    scene:update(dt)
end

function rotate()
    tab[pos].r=Rotate
end

function draw()
    update(DeltaTime)
    tab[pos].gr.eulerAngles = vec3(0,tab[pos].r, 0)
    scene:draw()
end

function position()
    Rotate=tab[pos].r
    int=tab[pos].a
end

function intensity()
    if int then
        tab[pos].gr.material = bloomMaterial
        tab[pos].a=true
    else   
        tab[pos].gr.material = material
        tab[pos].a=false
    end
end

I appreciate all the help you guys have been giving me, thanks.

Still and all it’s weird that I can’t just do either thisEntity.material = nil or thisEntity.material:destroy() or thisEntity.remove(craft.material)

@RonJeffries you are asking good questions about documentation.

As much as I’d love more complete documentation, for the moment AFAIK we have only two options for finding better information of documented features, or for discovery of features not included at all in documentation:

  • Search the forums
  • Inspect the sample projects

You’ll find many posts (not just by me) asking for clarification on how various features work, so it actually works out that the odds are good you can find, if not the exact information you want, something close.

And if you can’t find what you need either of those ways, the only thing left to do is ask about it here.

yep

…you know those insta-wikis that seem to be automatically generated for every game that’s ever come out ever? Do you think we could get them to do one on Codea? :wink:

@UberGoober, an alternative approach for the bloom effect.

-- bloom effect
viewer.mode=STANDARD

function setup()
    tab={}
    scene = craft.scene()
    scene.sun.rotation=quat.eulerAngles(30,45,30)
    v=scene.camera:add(OrbitViewer, vec3(0,0,0), 200, 0, 1000)
    v.ry=180
    
    cameraComponent = scene.camera:get(craft.camera)
    cameraComponent.hdr = true
    cameraComponent.colorTextureEnabled = true
    
    bloom = craft.bloomEffect()
    cameraComponent:addPostEffect(bloom)
    bloom.threshold = 2
    bloom.intensity = 1
    bloom.softThreshold = 0.4
    bloom.iterations = 8
    
    for z=1,50 do
        local ground = scene:entity()
        ground.model= craft.model(asset.builtin.Blocky_Characters.Robot)
        ground.material=ground.model:getMaterial(0)

        x=math.random(-50,50)
        y=math.random(-50,50)
        z=math.random(-50,50)
        ground.position = vec3(x,y,z)
        table.insert(tab,{gr=ground,x=x,y=y,z=z,r=0,a=false})
    end
    parameter.integer("pos",1,#tab,position)
    parameter.integer("Rotate",-180,180,0,rotate)
    parameter.boolean("int",false,intensity)
end

function update(dt)
    scene:update(dt)
end

function rotate()
    tab[pos].r=Rotate
end

function draw()
    update(DeltaTime)
    tab[pos].gr.eulerAngles = vec3(0,tab[pos].r, 0)
    scene:draw()
end

function position()
    Rotate=tab[pos].r
    int=tab[pos].a
end

function intensity()
    if int then
        tab[pos].gr.material.diffuse = vec3(1.0,1.0,1.0)*3
        tab[pos].a=true
    else
        tab[pos].gr.material.diffuse =vec3(1.0,1.0,1.0)
        tab[pos].a=false
    end
end

@piinthesky holy clock in a bobble-head, that’s exactly what I need!

So the whole key to this is the line:

ground.material=ground.model:getMaterial(0)

…which relies on the model:getMaterial function, which isn’t in the documentation (AFAIK) and which I don’t think anyone else knew existed.

…so if you don’t mind my asking, how did you know it existed?

Since this is basically the answer to my question in another thread, I’m going to link to it there.

Just in case you’re curious these are the bloom and diffuse values I think I’m gonna go with:


    bloom.threshold = 2.9
    bloom.intensity = 0.58
    bloom.softThreshold = 0.16
    bloom.iterations = 8

    ...

    tab[pos].gr.material.diffuse = vec3(2.5,1.5,4)

@UberGoober, see this thread…
https://codea.io/talk/discussion/10831/add-transparency-to-a-3d-obj-mtl-model