JuliaGL / GLVisualize.jl

Visualization library written in Julia and OpenGL
Other
247 stars 34 forks source link

Add lights attributes #242

Open edljk opened 6 years ago

edljk commented 6 years ago
edljk commented 6 years ago

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

SimonDanisch commented 6 years ago

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

edljk commented 6 years ago

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

edljk commented 5 years ago

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.

SimonDanisch commented 5 years ago

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

edljk commented 5 years ago

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

edljk commented 5 years ago

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?

SimonDanisch commented 5 years ago

No, that's likely a bug ;)

edljk commented 5 years ago

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 commented 5 years ago

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

edljk commented 5 years ago

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 commented 5 years ago

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

Are you interested in a PR for this small extension?

SimonDanisch commented 5 years ago

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

edljk commented 5 years ago

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