implement grid and heightmap with lambert shading

This commit is contained in:
2018-12-24 22:22:16 +01:00
parent 4d2706bfab
commit 52c87d9ec6
16 changed files with 297 additions and 101 deletions

View File

@@ -485,7 +485,28 @@ void App::initShaders()
"void main(){"
" frag = c;"
"}";
// LAMBERT
static const char* shader_lambert_v =
SHADER_VERSION
"uniform mat4 mvp;\n"
"in vec4 pos;\n"
"in vec3 nor;\n"
"out vec3 n;\n"
"void main(){\n"
" n = nor;\n"
" gl_Position = mvp * pos;\n"
"}";
static const char* shader_lambert_f =
SHADER_VERSION
"uniform mediump vec3 light_dir;\n"
"in mediump vec3 n;\n"
"out mediump vec4 frag;\n"
"void main(){\n"
" mediump float d = max(0.0, dot(normalize(n), light_dir));\n"
" frag = vec4(vec3(d), 1.0);\n"
"}";
LOG("initializing shaders");
if (!ShaderManager::create(kShader::Texture, shader_v, shader_f))
@@ -524,6 +545,8 @@ void App::initShaders()
LOG("Failed to create shader BrushStroke");
if (!ShaderManager::create(kShader::VertexColor, shader_vertcol_v, shader_vertcol_f))
LOG("Failed to create shader VertexColor");
if (!ShaderManager::create(kShader::Lambert, shader_lambert_v, shader_lambert_f))
LOG("Failed to create shader Lambert");
LOG("shaders initialized");
}