GLVisualize.jl icon indicating copy to clipboard operation
GLVisualize.jl copied to clipboard

Add lights attributes

Open edljk opened this issue 8 years ago • 14 comments

  • hope it is non breaking with previous use of a single light field (with backlighting)
  • include above example
  • not completely sure if assemble_shader in utils.jl is the right place to add lighting options
  • add everywhere value calls to transform signals. I guess there is still some work to be done to preserve interactivity.. At least it should not affect Makie calls.

edljk avatar Dec 26 '17 09:12 edljk

Sorry for the multiplication of the updates. I hope, it should be stabilized now. Do not hesitate to modify. Any comments are welcome.

edljk avatar Dec 31 '17 10:12 edljk

Sorry, I will need to take a close look at this... I'd really just hope to address this with some nice looking julia code + transpiler at some point :P

SimonDanisch avatar Jan 12 '18 00:01 SimonDanisch

No problem at all: this is not an emergency and the proposed approach is for sure not completely satisfactory..

edljk avatar Jan 12 '18 07:01 edljk

Anything new regarding lighting? I noticed frag files changed in GLMakie since this tentative :-). Is it now possible to have a more uniform lighting in 3D? Add several lights? etc.

edljk avatar Jan 15 '19 11:01 edljk

Sorry, no ;) Would still be nice to have of course

SimonDanisch avatar Jan 15 '19 11:01 SimonDanisch

What do you think about extending your light_calc function to define other lighting styles?

edljk avatar Jan 15 '19 12:01 edljk

Actually, this simple hack makes it possible for me to obtain a uniform lighting just by extending light_calc. One issue (??) that I have is that the parameter shading does not seem to be taken into account for meshscatter! . Is it on purpose?

edljk avatar Jan 15 '19 19:01 edljk

No, that's likely a bug ;)

SimonDanisch avatar Jan 15 '19 20:01 SimonDanisch

I tried to fix it without success, sorry! Here is the code I used to have "uniform" lighting

mutable struct Lights 
    description::String 
    intensity::Array{Float64, 1} 
end

function GLMakie.GLVisualize.light_calc(x::Lights) 
    if x.description == "uniform"
         ST = [ 0.0  0.0  1.73205; 1.63299  0.0 -0.57735;
                   -0.816497  1.41421  -0.57735; -0.816497  -1.41421  -0.57735]
        lights = [Vec3f0(ST[k, :]...) for k = 1:size(ST, 1)]
        strl = """
        vec3 L      = normalize(o_lightdir);
        vec3 N      = normalize(o_normal);\n"""
        for k = 1:size(lights, 1)
            strl = strl * "vec3 light" * string(k) * " = blinnphong(N, o_vertex," * 
                  "vec3(" * string(lights[k][1]) * "," * 
                            string(lights[k][2]) * "," * 
                            string(lights[k][3]) * ")" *
                   ", color.rgb); \n"
        end
        strl = strl * "color       = vec4(light1 * " * string(x.intensity[1]) * " + " *
                                         "light2 * " * string(x.intensity[2]) * " + " * 
                                         "light3 * " * string(x.intensity[3]) * " + " * 
                                         "light4 * " * string(x.intensity[4]) * ", color.a);"                                         
        #println(strl)
        strl
    else
        ""
    end
end

edljk avatar Jan 15 '19 20:01 edljk

..with the option shading = Lights("uniform", [0.7, 0.3, 0.3, 0.7])

edljk avatar Jan 15 '19 20:01 edljk

Actually, the sprites function in particles.jl gets a data field without the key shading after a call

meshscatter!(..., shading = false)

but I am not able to identify the path from meshscatter to the sprites function..

edljk avatar Jan 15 '19 21:01 edljk

Finally, I managed to fix this (shading not taken into account in meshscatter) by some modification in

  • GLMakie by adding the shading field in the right places in the files particles.jl and drawing_primitves.jl and adding
 "light_calc" => light_calc(shading)

in particles.jl in the meshscatter function and

  • AbstractPlotting adding the shading fields in the right places in the file interfaces.jl

Are you interested in a PR for this small extension?

edljk avatar Jan 24 '19 09:01 edljk

That'd be awesome :) Thanks for your work on this, and sorry that I have this on low priority and therefore am not very responsive :D

SimonDanisch avatar Jan 24 '19 10:01 SimonDanisch

No problem at all: you are right, this is definitely low priority!

edljk avatar Jan 24 '19 13:01 edljk