POV-Ray : Newsgroups : povray.text.scene-files : Source code for "With and without a light_source" Server Time
1 Nov 2024 01:24:49 EDT (-0400)
  Source code for "With and without a light_source" (Message 1 to 1 of 1)  
From: Tor Olav Kristensen
Subject: Source code for "With and without a light_source"
Date: 24 Jun 2003 18:20:41
Message: <Xns93A54E262AE2torolavkhotmailcom@204.213.191.226>
Here is the source code for the light-source-less image that I posted
to povray.binaries.images 23. June:

http://news.povray.org/povray.binaries.images/32195/

Ambient, Diffuse and Specular (Phong) reflections for an isosurface
are "simulated" with a function controlled pigment.


Tor Olav


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Copyright 2003 by Tor Olav Kristensen
// Email: t o r _ o l a v _ k [ a t ] h o t m a i l . c o m
// http://home.no/t-o-k
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.5;

global_settings { ambient_light color rgb <1, 1, 1> }

#include "functions.inc" // For f_r() and f_torus

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#macro PhongFunction(ShapeFn, pCamera, pLight, AttFn,
                     Iambient, Idiffuse, Ispecular, Shininess)

  #local pLx = pLight.x;
  #local pLy = pLight.y;
  #local pLz = pLight.z;
  #local pCx = pCamera.x;
  #local pCy = pCamera.y;
  #local pCz = pCamera.z;

  #local Nil = 1E-10;
  #local H = 1E-4;

  #local ClampFn = function(N) { max(0, min(N, 1)) }

  #local TempFn0 =
    function(lI, Theta, Phi) {
      ClampFn(
        AttFn(lI)*
        (
          Iambient +
          Idiffuse*select(Theta, 0, 1)*Theta +
          Ispecular*select(Phi, 0, 1)*pow(abs(Phi), Shininess)
        )
      )
    }

  #local TempFn1 =
    function(lI, vLxn, vLyn, vLzn, vNxn, vNyn, vNzn, vCxn, vCyn, vCzn, S) {
      TempFn0(
        lI,
        vLxn*vNxn + vLyn*vNyn + vLzn*vNzn,
        vCxn*(S*vNxn - vLxn) + vCyn*(S*vNyn - vLyn) + vCzn*(S*vNzn - vLzn)
      ) 
    }

  #local TempFn2 =
    function(lI, vLxn, vLyn, vLzn, vNxn, vNyn, vNzn, vCxn, vCyn, vCzn) {
      TempFn1(
        lI,
        vLxn, vLyn, vLzn,
        vNxn, vNyn, vNzn,
        vCxn, vCyn, vCzn,
        2*(vLxn*vNxn + vLyn*vNyn + vLzn*vNzn)
      )
    }

  #local TempFn3 =
    function(vLx, vLy, vLz, lI, vNx, vNy, vNz, lN, vCx, vCy, vCz, lV) {
      TempFn2(
        lI,
        vLx/lI, vLy/lI, vLz/lI,
        vNx/lN, vNy/lN, vNz/lN,
        vCx/lV, vCy/lV, vCz/lV
      ) 
    }

  #local TempFn4 =
    function(vLx, vLy, vLz, vNx, vNy, vNz, vCx, vCy, vCz) {
      TempFn3(
        vLx, vLy, vLz, Nil + f_r(vLx, vLy, vLz),
        vNx, vNy, vNz, Nil + f_r(vNx, vNy, vNz),
        vCx, vCy, vCz, Nil + f_r(vCx, vCy, vCz)
      ) 
    }

  function {
    TempFn4(
      pLx - x, // vLx
      pLy - y, // vLy
      pLz - z, // vLz
      ShapeFn(x + H, y, z) - ShapeFn(x - H, y, z), // vNx
      ShapeFn(x, y + H, z) - ShapeFn(x, y - H, z), // vNy
      ShapeFn(x, y, z + H) - ShapeFn(x, y, z - H), // vNz
      pCx - x, // vCx
      pCy - y, // vCy
      pCz - z  // vCz
    )
  }

#end // macro PhongFunction

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare pLightLocation = <3.0, 2.0, -4.0>;

#declare pCameraLocation = <0.0, 3.4, -5.1>;
#declare pCameraLookAt = <0.0, -2.6, 0.0>;

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

/*
#declare FadeDistance = 10;
#declare FadePower = 2;

#declare AttenuationFn =
  function(D) { 1/(1 + pow(D/FadeDistance, FadePower)) }
#declare ExpAttenuationFn = function(D) { exp(-D/FadeDistance) }
*/

#declare NoAttenuationFn = function(D) { 1 }

#declare Ambient = 0.1;
#declare Diffuse = 0.5;
#declare Phong = 0.4;
#declare PhongSize = 50;

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare Rmaj = 4;
#declare Rmin = 1;

#declare TorusFn = function { f_torus(x, y, z, Rmaj, Rmin) }

#declare PhongTexture =
  texture {
    pigment {
      PhongFunction(
        TorusFn,
        pCameraLocation,
        pLightLocation,
        NoAttenuationFn, 
        Ambient,
        Diffuse,
        Phong,
        PhongSize
      )
      color_map {
        [ 0.00 color rgb <0.0, 0.0, 0.0> ]
//        [ 0.10 color rgb <0.1, 0.1, 0.1> ]
//        [ 0.24 color rgb <0.8, 0.4, 0.0> ]
//        [ 0.30 color rgb <0.3, 0.3, 0.3> ]
//        [ 0.70 color rgb <0.0, 0.0, 1.0> ]
        [ 1.00 color rgb <1.0, 1.0, 1.0> ]
      }
    }
    finish {
      ambient color rgb <1, 1, 1>
      diffuse 0
    }
  }

#declare pMin = -<Rmaj + Rmin, Rmin, Rmaj + Rmin>;
#declare pMax =  <Rmaj + Rmin, Rmin, Rmaj + Rmin>;

isosurface {
  function { TorusFn(x, y, z) }
  contained_by { box { pMin, pMax } }
  texture { PhongTexture }
}

/*
// This gives the same result as the isosurface shape above

torus {
  Rmaj, Rmin
  texture {
    pigment { color rgb <1, 1, 1> }
    finish {
      ambient Ambient
      diffuse Diffuse
      phong Phong
      phong_size PhongSize
    }
  }
}

light_source { pLightLocation color rgb <1, 1, 1> }
*/

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

sky_sphere {
  pigment {
    gradient y
    turbulence 0.1
    color_map {
      [ 0.0 color rgb <0.75, 0.75, 0.75> ]
      [ 0.4 color rgb <0.00, 0.00, 0.25> ]
      [ 0.6 color rgb <0.00, 0.00, 0.25> ]
      [ 1.0 color rgb <0.75, 0.75, 0.75> ]
    }
  }
}

camera {
  location pCameraLocation
  look_at pCameraLookAt
  angle 100
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.