diff --git a/examples/42-bunnylod/bunnylod.cpp b/examples/42-bunnylod/bunnylod.cpp index 527beaa38..47fe4f2b9 100644 --- a/examples/42-bunnylod/bunnylod.cpp +++ b/examples/42-bunnylod/bunnylod.cpp @@ -265,7 +265,7 @@ public: u_tint = bgfx::createUniform("u_tint", bgfx::UniformType::Vec4); // Create program from shaders. - m_program = loadProgram("vs_callback", "fs_callback"); + m_program = loadProgram("vs_bunnylod", "fs_bunnylod"); Mesh* mesh = meshLoad("meshes/bunny_patched.bin", true); loadMesh(mesh); diff --git a/examples/42-bunnylod/fs_bunnylod.sc b/examples/42-bunnylod/fs_bunnylod.sc new file mode 100644 index 000000000..5ccdc6e1d --- /dev/null +++ b/examples/42-bunnylod/fs_bunnylod.sc @@ -0,0 +1,17 @@ +$input v_world, v_color0 + +/* + * Copyright 2011-2020 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ + +#include "../common/common.sh" + +void main() +{ + vec3 normal = normalize(cross(dFdx(v_world), dFdy(v_world) ) ); + vec3 lightDir = vec3(0.0, 0.0, 1.0); + float ndotl = max(dot(normal, lightDir), 0.0); + float spec = pow(ndotl, 30.0); + gl_FragColor = pow(pow(v_color0, vec4_splat(2.2) ) * ndotl + spec, vec4_splat(1.0/2.2) ); +} diff --git a/examples/42-bunnylod/makefile b/examples/42-bunnylod/makefile new file mode 100644 index 000000000..5c49b1667 --- /dev/null +++ b/examples/42-bunnylod/makefile @@ -0,0 +1,10 @@ +# +# Copyright 2011-2020 Branimir Karadzic. All rights reserved. +# License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause +# + +BGFX_DIR=../.. +RUNTIME_DIR=$(BGFX_DIR)/examples/runtime +BUILD_DIR=../../.build + +include $(BGFX_DIR)/scripts/shader.mk diff --git a/examples/42-bunnylod/varying.def.sc b/examples/42-bunnylod/varying.def.sc new file mode 100644 index 000000000..bdc7f97fc --- /dev/null +++ b/examples/42-bunnylod/varying.def.sc @@ -0,0 +1,5 @@ +vec3 v_world : TEXCOORD0 = vec3(0.0, 0.0, 0.0); +vec4 v_color0 : COLOR0 = vec4(1.0, 0.0, 0.0, 1.0); + +vec3 a_position : POSITION; +vec3 a_normal : NORMAL; diff --git a/examples/42-bunnylod/vs_bunnylod.sc b/examples/42-bunnylod/vs_bunnylod.sc new file mode 100644 index 000000000..4df11502b --- /dev/null +++ b/examples/42-bunnylod/vs_bunnylod.sc @@ -0,0 +1,16 @@ +$input a_position, a_normal +$output v_world, v_color0 + +/* + * Copyright 2011-2020 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ + +#include "../common/common.sh" + +void main() +{ + gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0) ); + v_world = mul(u_model[0], vec4(a_position, 1.0) ).xyz; + v_color0 = vec4(a_normal, 1.0); +}