Created
November 22, 2023 14:39
-
-
Save CaptainGPU/fa8fc5c3ab1176b41bea776ab32394f9 to your computer and use it in GitHub Desktop.
Cel.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
// Вхідні начення нормалі поверхні моделі | |
varying vec4 v_normal; | |
// Позиція камери | |
vec3 cameraPosition = vec3(0.0, 0.0, 1.0); | |
// Позиції джерел світла | |
vec3 lightPosition = vec3(1.0, 1.0, 1.0); | |
// Кількість рівнів cel-shading | |
const float celLevels = 3.0; | |
// Фактор cel-shading | |
const float celFactor = 1.0 / celLevels; | |
void main() { | |
// Фінальний колір пикселя, обчислений у шейдері | |
vec3 finalColor = vec3(0.0); | |
// Колір моделі | |
vec3 modelColor = vec3(0.8863, 0.8706, 0.0); | |
// Нормаль поверхні | |
vec3 normal = normalize(v_normal.xyz); | |
// Нормалізований напрямок до джерела світла | |
vec3 lightDir = normalize(lightPosition); | |
// Значення освітлення | |
vec3 lighting = vec3(.0); | |
// Ambient освітлення - непряме освітленя | |
vec3 ambientLighting = vec3(0.3); | |
// Додаємо до значення освітлення Ambient освітлення | |
lighting += ambientLighting; | |
// Обчислюємо значення diffuse освітлення, | |
// використовуючи скалярне множення вектора до джерела світла | |
// на нормаль поверхні | |
float diffuse = dot(normalize(lightPosition), normal); | |
// Відкидаємо значення нижче нуля | |
diffuse = max(0.0, diffuse); | |
// Дискретизация diffuse освітлення | |
diffuse = ceil(diffuse * celLevels) * celFactor; | |
// Додаємо до значення освітлення diffuse освітлення | |
lighting += diffuse; | |
// Фінальний колір пікселя = колір моделі * значення освітлення | |
finalColor = modelColor * lighting; | |
// Виводимо обчислений колір пікселя | |
gl_FragColor = vec4(finalColor, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment