1 /**************************************************************************\ 2 * Copyright (c) Kongsberg Oil & Gas Technologies AS 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * Redistributions of source code must retain the above copyright notice, 10 * this list of conditions and the following disclaimer. 11 * 12 * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * Neither the name of the copyright holder nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 \**************************************************************************/ 32 33 #ifndef COIN_INTERNAL 34 #error this is a private header file 35 #endif /* !COIN_INTERNAL */ 36 37 #ifndef SO_POINTLIGHT_GLSL_H 38 #define SO_POINTLIGHT_GLSL_H 39 40 static const char POINTLIGHT_shadersource[] = 41 "\n" 42 "void PointLight(in vec3 light_position,\n" 43 " in vec3 light_attenuation,\n" 44 " in vec3 eye,\n" 45 " in vec3 ecPosition3,\n" 46 " in vec3 normal,\n" 47 " inout vec4 ambient,\n" 48 " inout vec4 diffuse,\n" 49 " inout vec4 specular)\n" 50 "{\n" 51 " float nDotVP;\n" 52 " float nDotHV;\n" 53 " float pf; \n" 54 " float att;\n" 55 " float d;\n" 56 " vec3 VP;\n" 57 " vec3 halfvec;\n" 58 "\n" 59 " VP = light_position - ecPosition3;\n" 60 " d = length(VP);\n" 61 "\n" 62 " VP = normalize(VP);\n" 63 "\n" 64 " att = 1.0 / (light_attenuation.x +\n" 65 " light_attenuation.y * d +\n" 66 " light_attenuation.z * d * d);\n" 67 "\n" 68 " halfvec = normalize(VP + eye);\n" 69 " nDotVP = max(0.0, dot(normal, VP));\n" 70 " nDotHV = max(0.0, dot(normal, halfvec));\n" 71 "\n" 72 " float shininess = gl_FrontMaterial.shininess;\n" 73 "\n" 74 " if (nDotVP == 0.0)\n" 75 " pf = 0.0;\n" 76 " else\n" 77 " pf = pow(nDotHV, shininess);\n" 78 "\n" 79 " ambient *= att;\n" 80 " diffuse *= nDotVP * att;\n" 81 " specular *= pf * att;\n" 82 "}\n" 83 "\n"; 84 85 #endif /* ! SO_POINTLIGHT_GLSL_H */ 86