unibas-gravis / scalismo-faces

Scalable Image Analysis and Shape Modelling: Module to work with 2d images, with a focus on face images
Apache License 2.0
118 stars 27 forks source link

Pixel Shader for Point Light Source #96

Closed andreas-schneider closed 6 years ago

andreas-schneider commented 6 years ago

Currently we do not have a PixelShader to render images with a point light source. This implements a pixel shader with lambertian shading and a point light source.

Example code to see the influence of a point light source with respect to the distance to the mesh:

    val mesh: VertexColorMesh3D = ???
    val param = RenderParameter.defaultSquare
    for(z <- -850 to -200 by 100) {
        val buffer = ZBuffer[RGBA](param.imageSize.width, param.imageSize.height, RGBA.BlackTransparent)
        val renderingPointLight = TriangleRenderer.renderMesh(mesh.shape, param.pointShader,
        LambertPointLightShader.pixelShader(ColorNormalMesh3D(mesh), param, RGB(0.5), RGB(0.5), Point(0,0,z)), buffer)
        PixelImageIO.write(renderingPointLight.toImage, new File(s"/tmp/pointLight_${z}.png")).get
    }