| 1 |
{ -*- buffer-read-only: t -*- } |
| 2 |
{ DON'T EDIT -- this file was automatically generated from "source/main_shading_phong.fs" } |
| 3 |
'/* Phong shading GLSL fragment shader.' + LineEnding + |
| 4 |
' Used by ../castlerendererinternalshader.pas to construct the final shader.' + LineEnding + |
| 5 |
' When you change this file, rerun `make'' and then recompile Pascal sources.' + LineEnding + |
| 6 |
'*/' + LineEnding + |
| 7 |
'' + LineEnding + |
| 8 |
'/* PLUG-DECLARATIONS */' + LineEnding + |
| 9 |
'' + LineEnding + |
| 10 |
'#ifdef HAS_GEOMETRY_SHADER' + LineEnding + |
| 11 |
' #define castle_vertex_eye castle_vertex_eye_geoshader' + LineEnding + |
| 12 |
' #define castle_normal_eye castle_normal_eye_geoshader' + LineEnding + |
| 13 |
'#endif' + LineEnding + |
| 14 |
'' + LineEnding + |
| 15 |
'varying vec4 castle_vertex_eye;' + LineEnding + |
| 16 |
'varying vec3 castle_normal_eye;' + LineEnding + |
| 17 |
'' + LineEnding + |
| 18 |
'#if defined(COLOR_PER_VERTEX_RGB)' + LineEnding + |
| 19 |
'varying vec3 castle_ColorPerVertexFragment;' + LineEnding + |
| 20 |
'#elif defined(COLOR_PER_VERTEX_RGB_ALPHA)' + LineEnding + |
| 21 |
'varying vec4 castle_ColorPerVertexFragment;' + LineEnding + |
| 22 |
'#endif' + LineEnding + |
| 23 |
'' + LineEnding + |
| 24 |
'/* Apply per-vertex color, over the base/diffuse/emissive color + alpha. */' + LineEnding + |
| 25 |
'vec4 castle_apply_color_per_vertex(vec4 color)' + LineEnding + |
| 26 |
'{' + LineEnding + |
| 27 |
' return' + LineEnding + |
| 28 |
' #if defined(COLOR_PER_VERTEX_REPLACE)' + LineEnding + |
| 29 |
' #if defined(COLOR_PER_VERTEX_RGB)' + LineEnding + |
| 30 |
' vec4(castle_ColorPerVertexFragment, color.a);' + LineEnding + |
| 31 |
' #elif defined(COLOR_PER_VERTEX_RGB_ALPHA)' + LineEnding + |
| 32 |
' castle_ColorPerVertexFragment;' + LineEnding + |
| 33 |
' #endif' + LineEnding + |
| 34 |
' #elif defined(COLOR_PER_VERTEX_MODULATE)' + LineEnding + |
| 35 |
' #if defined(COLOR_PER_VERTEX_RGB)' + LineEnding + |
| 36 |
' vec4(castle_ColorPerVertexFragment * color.rgb, color.a);' + LineEnding + |
| 37 |
' #elif defined(COLOR_PER_VERTEX_RGB_ALPHA)' + LineEnding + |
| 38 |
' castle_ColorPerVertexFragment * color;' + LineEnding + |
| 39 |
' #endif' + LineEnding + |
| 40 |
' #else' + LineEnding + |
| 41 |
' color;' + LineEnding + |
| 42 |
' #endif' + LineEnding + |
| 43 |
'}' + LineEnding + |
| 44 |
'' + LineEnding + |
| 45 |
'/* Include fragment shader utilities used by both Gouraud and Phong shading. */' + LineEnding + |
| 46 |
'/* CASTLE-COMMON-CODE */' + LineEnding + |
| 47 |
'' + LineEnding + |
| 48 |
'void main_texture_apply(inout vec4 fragment_color,' + LineEnding + |
| 49 |
' const in vec3 normal_eye)' + LineEnding + |
| 50 |
'{' + LineEnding + |
| 51 |
' /* PLUG: main_texture_apply (fragment_color, normal_eye) */' + LineEnding + |
| 52 |
' /* PLUG: texture_apply (fragment_color, normal_eye) */ // deprecated' + LineEnding + |
| 53 |
'}' + LineEnding + |
| 54 |
'' + LineEnding + |
| 55 |
'/* CASTLE-LIGHTING-MODEL */' + LineEnding + |
| 56 |
'' + LineEnding + |
| 57 |
'void main(void)' + LineEnding + |
| 58 |
'{' + LineEnding + |
| 59 |
' vec3 normal_eye_fragment = normalize(castle_normal_eye);' + LineEnding + |
| 60 |
'' + LineEnding + |
| 61 |
'#ifndef CASTLE_BUGGY_FRONT_FACING' + LineEnding + |
| 62 |
' if (gl_FrontFacing)' + LineEnding + |
| 63 |
' /* Avoid AMD bug http://forums.amd.com/devforum/messageview.cfm?catid=392&threadid=148827&enterthread=y' + LineEnding + |
| 64 |
' Observed on fglrx (proprietary ATI Linux driver),' + LineEnding + |
| 65 |
' with ATI Mobility Radeon HD 4300 (castle computer "czarny"),' + LineEnding + |
| 66 |
' since Ubuntu 11.4 (fglrx OpenGL version 3.3.10665).' + LineEnding + |
| 67 |
'' + LineEnding + |
| 68 |
' It causes both (gl_FrontFacing) and (!gl_FrontFacing) to be true...' + LineEnding + |
| 69 |
' To minimize the number of problems, never use "if (!gl_FrontFacing)",' + LineEnding + |
| 70 |
' only "if (gl_FrontFacing)".' + LineEnding + |
| 71 |
'' + LineEnding + |
| 72 |
' See also https://makc3d.wordpress.com/2015/09/17/alternative-to-gl_frontfacing/ ,' + LineEnding + |
| 73 |
' gl_FrontFacing seems unreliable sometimes.' + LineEnding + |
| 74 |
' */ ; else' + LineEnding + |
| 75 |
' normal_eye_fragment = -normal_eye_fragment;' + LineEnding + |
| 76 |
'#endif' + LineEnding + |
| 77 |
'' + LineEnding + |
| 78 |
' /* PLUG: fragment_eye_space (castle_vertex_eye, normal_eye_fragment) */' + LineEnding + |
| 79 |
'' + LineEnding + |
| 80 |
' vec4 fragment_color;' + LineEnding + |
| 81 |
' calculate_lighting(fragment_color, castle_vertex_eye, normal_eye_fragment);' + LineEnding + |
| 82 |
'' + LineEnding + |
| 83 |
' /* PLUG: lighting_apply (fragment_color, castle_vertex_eye, normal_eye_fragment) */' + LineEnding + |
| 84 |
' /* PLUG: steep_parallax_shadow_apply (fragment_color) */' + LineEnding + |
| 85 |
' /* PLUG: fragment_modify (fragment_color) */' + LineEnding + |
| 86 |
'' + LineEnding + |
| 87 |
' #ifdef CASTLE_GAMMA_CORRECTION' + LineEnding + |
| 88 |
' fragment_color.rgb = castle_linear_to_screen(fragment_color.rgb);' + LineEnding + |
| 89 |
' #else' + LineEnding + |
| 90 |
' #ifdef CASTLE_TONE_MAPPING' + LineEnding + |
| 91 |
' fragment_color.rgb = castle_linear_to_screen(fragment_color.rgb);' + LineEnding + |
| 92 |
' #endif' + LineEnding + |
| 93 |
' /* Optimization to not call castle_linear_to_screen always:' + LineEnding + |
| 94 |
' it does nothing when neither CASTLE_GAMMA_CORRECTION nor CASTLE_TONE_MAPPING */' + LineEnding + |
| 95 |
' #endif' + LineEnding + |
| 96 |
'' + LineEnding + |
| 97 |
' /* PLUG: fog_apply (fragment_color, normal_eye_fragment) */' + LineEnding + |
| 98 |
'' + LineEnding + |
| 99 |
' /* NVidia GeForce 450 GTS (kocury) fails to compile a shader when' + LineEnding + |
| 100 |
' we pass gl_FragColor as inout parameter to functions' + LineEnding + |
| 101 |
' (testcase even fresnel_and_toon.x3dv).' + LineEnding + |
| 102 |
' Although on Radeon X1600 (fglrx, chantal) it works OK.' + LineEnding + |
| 103 |
' So we just use fragment_color everywhere above, and only assign it' + LineEnding + |
| 104 |
' to gl_FragColor at the end. */' + LineEnding + |
| 105 |
' gl_FragColor = fragment_color;' + LineEnding + |
| 106 |
'' + LineEnding + |
| 107 |
' /* PLUG: fragment_end (gl_FragColor) */' + LineEnding + |
| 108 |
'}' + LineEnding + |
| 109 |
'' |