Debian Codegraph @

src/scene/glsl/generated-pascal/lighting_model_phong_shading_gouraud.vs.inc

raw
1 { -*- buffer-read-only: t -*- }
2 { DON'T EDIT -- this file was automatically generated from "source/lighting_model_phong/shading_gouraud.vs" }
3 '/*' + LineEnding +
4 ' Copyright 2010-2020 Michalis Kamburelis.' + LineEnding +
5 '' + LineEnding +
6 ' This file is part of "Castle Game Engine".' + LineEnding +
7 '' + LineEnding +
8 ' "Castle Game Engine" is free software; see the file COPYING.txt,' + LineEnding +
9 ' included in this distribution, for details about the copyright.' + LineEnding +
10 '' + LineEnding +
11 ' "Castle Game Engine" is distributed in the hope that it will be useful,' + LineEnding +
12 ' but WITHOUT ANY WARRANTY; without even the implied warranty of' + LineEnding +
13 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.' + LineEnding +
14 '' + LineEnding +
15 ' ----------------------------------------------------------------------------' + LineEnding +
16 '' + LineEnding +
17 ' Calculate Phong lighting model, in Gouraud shading. */' + LineEnding +
18 '' + LineEnding +
19 'uniform vec4 castle_MaterialDiffuseAlpha;' + LineEnding +
20 'uniform vec3 castle_MaterialAmbient;' + LineEnding +
21 'uniform vec3 castle_MaterialSpecular;' + LineEnding +
22 'uniform float castle_MaterialShininess;' + LineEnding +
23 'uniform vec3 castle_MaterialEmissive;' + LineEnding +
24 'uniform vec3 castle_GlobalAmbient;' + LineEnding +
25 '' + LineEnding +
26 'uniform vec4 castle_UnlitColor;' + LineEnding +
27 '' + LineEnding +
28 '/* Material ambient color * global (light model) ambient. */' + LineEnding +
29 'vec3 get_ambient_color()' + LineEnding +
30 '{' + LineEnding +
31 ' vec3 ambient = castle_MaterialAmbient;' + LineEnding +
32 ' return ambient * castle_GlobalAmbient;' + LineEnding +
33 '}' + LineEnding +
34 '' + LineEnding +
35 'void calculate_lighting(out vec4 result, const in vec4 vertex_eye, const in vec3 normal_eye)' + LineEnding +
36 '{' + LineEnding +
37 '#ifdef LIT' + LineEnding +
38 ' /* Two-sided lighting in Gouraud shading:' + LineEnding +
39 ' flip the normal vector to correspond to the face side that we actually see.' + LineEnding +
40 '' + LineEnding +
41 ' Note that we don''t flip the normal_eye (we only flip the' + LineEnding +
42 ' normal_for_lighting), as normal_eye may be useful also for other' + LineEnding +
43 ' calculations, e.g. cubemap reflections, that don''t want this flippping' + LineEnding +
44 ' (testcase: demo-models/cube_environment_mapping/cubemap_generated_in_dynamic_world.x3dv )' + LineEnding +
45 '' + LineEnding +
46 ' This is commented out, because it''s not perfect, and I''m not sure can' + LineEnding +
47 ' we efficiently do artifact-free version of two-sided lighting.' + LineEnding +
48 ' Reproduction of the problem:' + LineEnding +
49 ' - demo-models/cube_environment_mapping/cubemap_generated_in_dynamic_world.x3dv,' + LineEnding +
50 ' look at the back side of the box.' + LineEnding +
51 ' - demo-models/fog/fog_linear, rotate in Examine and look at the thin water' + LineEnding +
52 ' edges.' + LineEnding +
53 '' + LineEnding +
54 ' The problem: We base our flipping on normal_eye,' + LineEnding +
55 ' which may be a smoothed (per-vertex) normal vector.' + LineEnding +
56 '' + LineEnding +
57 ' - We cannot calculate here reliably per-face vector (fragment shaders' + LineEnding +
58 ' can do a trick with dFdx, see' + LineEnding +
59 ' https://makc3d.wordpress.com/2015/09/17/alternative-to-gl_frontfacing/ ,' + LineEnding +
60 ' but dFdx is only available in fragment shader).' + LineEnding +
61 '' + LineEnding +
62 ' - Fully-correct solutions are inefficient:' + LineEnding +
63 ' - To pass to vertex shader a face_normal in a special uniform' + LineEnding +
64 ' means that we have to pass extra data, and also that we have to' + LineEnding +
65 ' split vertexes to not share vertexes across faces.' + LineEnding +
66 ' - Calculating light 2x times and then letting fragment shader to choose' + LineEnding +
67 ' which side to show (this is what fixed-function does, I think).' + LineEnding +
68 '' + LineEnding +
69 ' - If you''re OK with being correct (not fast), you can use Phong shading' + LineEnding +
70 ' where two-sided lighting works easily.' + LineEnding +
71 ' */' + LineEnding +
72 ' /* vec3 normal_for_lighting = (normal_eye.z > 0.0 ? normal_eye : -normal_eye); */' + LineEnding +
73 '' + LineEnding +
74 ' MaterialInfo material_info;' + LineEnding +
75 '' + LineEnding +
76 ' material_info.ambient = castle_MaterialAmbient;' + LineEnding +
77 ' /* PLUG: material_ambient (material_info.ambient) */' + LineEnding +
78 ' material_info.specular = castle_MaterialSpecular;' + LineEnding +
79 ' /* PLUG: material_specular (material_info.specular) */' + LineEnding +
80 ' material_info.shininess = castle_MaterialShininess;' + LineEnding +
81 ' /* PLUG: material_shininess (material_info.shininess) */' + LineEnding +
82 '' + LineEnding +
83 ' material_info.diffuse_alpha = castle_apply_color_per_vertex(castle_MaterialDiffuseAlpha);' + LineEnding +
84 '' + LineEnding +
85 ' result = vec4(get_ambient_color(), material_info.diffuse_alpha.a);' + LineEnding +
86 '' + LineEnding +
87 ' /* PLUG: add_light (result, vertex_eye, normal_eye, material_info) */' + LineEnding +
88 '' + LineEnding +
89 ' vec3 emissive = castle_MaterialEmissive;' + LineEnding +
90 ' result.rgb += emissive;' + LineEnding +
91 '' + LineEnding +
92 ' /* Clamp sum of lights colors to be <= 1. See template_phong.fs for comments. */' + LineEnding +
93 ' result.rgb = min(result.rgb, 1.0);' + LineEnding +
94 '#else' + LineEnding +
95 ' /* Unlit case.' + LineEnding +
96 ' See shading_phong.fs for comments when this is used.' + LineEnding +
97 ' */' + LineEnding +
98 ' result = castle_UnlitColor;' + LineEnding +
99 '#endif' + LineEnding +
100 '}' + LineEnding +
101 ''