From: Mikko Rasa Date: Sat, 8 May 2021 11:45:28 +0000 (+0300) Subject: Use PBR with IBL for the sphere in desert pillars X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e03a752116ab28283bf89dddf1228804cc853a7b;p=libs%2Fgl.git Use PBR with IBL for the sphere in desert pillars --- diff --git a/demos/desertpillars/data/exported/Iron.tech b/demos/desertpillars/data/exported/Iron.tech index 57d0f12d..d3852af9 100644 --- a/demos/desertpillars/data/exported/Iron.tech +++ b/demos/desertpillars/data/exported/Iron.tech @@ -5,12 +5,12 @@ pass "" type pbr; base_color 0.550000 0.570000 0.570000 1.00000; metalness 1.00000; - roughness 0.0500000; + roughness 0.200000; emission 0.00000 0.00000 0.00000; }; - receive_shadows true; + shader "sphere.shader"; }; pass "shadow" { - shader "_occluder.glsl.shader"; + shader "sphere_shadow.glsl.shader"; }; diff --git a/demos/desertpillars/data/sphere.glsl b/demos/desertpillars/data/sphere.glsl index 6144acaa..0dd872bd 100644 --- a/demos/desertpillars/data/sphere.glsl +++ b/demos/desertpillars/data/sphere.glsl @@ -1,38 +1,2 @@ -import phong; - -uniform Morph -{ - float morph; -}; - -const float PI = 3.1415926535; -const float OFFSET = 0.001; - -#pragma MSP stage(vertex) -vec3 deform(vec3 p) -{ - vec3 d = cos(p*(2.0*PI)+morph)*0.05; - return p*(1.0+(d.x+d.y+d.z)*sin(morph*0.2)); -} - -vec4 get_vertex_position() override -{ - return vec4(deform(vertex.xyz), 1.0); -} - -vec3 get_vertex_normal() override -{ - vec3 tangent; - if(abs(normal.x)>abs(normal.y)) - tangent = normalize(vec3(-normal.z, 0.0, normal.x)); - else - tangent = normalize(vec3(0.0, -normal.z, normal.y)); - vec3 binormal = cross(normal, tangent); - - vec3 xn = deform(vertex.xyz-tangent*OFFSET); - vec3 xp = deform(vertex.xyz+tangent*OFFSET); - vec3 yn = deform(vertex.xyz-binormal*OFFSET); - vec3 yp = deform(vertex.xyz+binormal*OFFSET); - - return normalize(cross(xp-xn, yp-yn)); -} +import cooktorrance; +import sphere_morph; diff --git a/demos/desertpillars/data/sphere.shader b/demos/desertpillars/data/sphere.shader index ba938ff3..d203cd1b 100644 --- a/demos/desertpillars/data/sphere.shader +++ b/demos/desertpillars/data/sphere.shader @@ -1,5 +1,4 @@ module "sphere.glsl" { - specialize "use_specular" true; - specialize "use_reflectivity" true; + specialize "use_image_based_lighting" true; }; diff --git a/demos/desertpillars/data/sphere_morph.glsl b/demos/desertpillars/data/sphere_morph.glsl new file mode 100644 index 00000000..e020ed68 --- /dev/null +++ b/demos/desertpillars/data/sphere_morph.glsl @@ -0,0 +1,36 @@ +uniform Morph +{ + float morph; +}; + +const float PI = 3.1415926535; +const float OFFSET = 0.001; + +#pragma MSP stage(vertex) +vec3 deform(vec3 p) +{ + vec3 d = cos(p*(2.0*PI)+morph)*0.05; + return p*(1.0+(d.x+d.y+d.z)*sin(morph*0.2)); +} + +vec4 get_vertex_position() override +{ + return vec4(deform(vertex.xyz), 1.0); +} + +vec3 get_vertex_normal() override +{ + vec3 tangent; + if(abs(normal.x)>abs(normal.y)) + tangent = normalize(vec3(-normal.z, 0.0, normal.x)); + else + tangent = normalize(vec3(0.0, -normal.z, normal.y)); + vec3 binormal = cross(normal, tangent); + + vec3 xn = deform(vertex.xyz-tangent*OFFSET); + vec3 xp = deform(vertex.xyz+tangent*OFFSET); + vec3 yn = deform(vertex.xyz-binormal*OFFSET); + vec3 yp = deform(vertex.xyz+binormal*OFFSET); + + return normalize(cross(xp-xn, yp-yn)); +} diff --git a/demos/desertpillars/data/sphere_phong.object b/demos/desertpillars/data/sphere_phong.object deleted file mode 100644 index b8f75dcb..00000000 --- a/demos/desertpillars/data/sphere_phong.object +++ /dev/null @@ -1,2 +0,0 @@ -mesh "Sphere.mesh"; -technique "sphere_phong.tech"; diff --git a/demos/desertpillars/data/sphere_phong.tech b/demos/desertpillars/data/sphere_phong.tech deleted file mode 100644 index 638d243c..00000000 --- a/demos/desertpillars/data/sphere_phong.tech +++ /dev/null @@ -1,16 +0,0 @@ -pass "" -{ - material - { - type basic; - diffuse 0.0 0.0 0.0; - specular 0.77 0.78 0.78; - reflectivity 0.77; - }; - shader "sphere.shader"; -}; -pass "shadow" -{ - //shader "_occluder.glsl.shader"; - shader "sphere.shader"; -}; diff --git a/demos/desertpillars/data/sphere_shadow.glsl b/demos/desertpillars/data/sphere_shadow.glsl new file mode 100644 index 00000000..1064389c --- /dev/null +++ b/demos/desertpillars/data/sphere_shadow.glsl @@ -0,0 +1,8 @@ +import common; +import sphere_morph; + +#pragma MSP stage(fragment) +void main() +{ + frag_color = vec4(1.0); +} diff --git a/demos/desertpillars/scene.blend b/demos/desertpillars/scene.blend index e519cfb5..847ef1a4 100644 Binary files a/demos/desertpillars/scene.blend and b/demos/desertpillars/scene.blend differ diff --git a/demos/desertpillars/source/desertpillars.cpp b/demos/desertpillars/source/desertpillars.cpp index bdbc069e..6cde69b0 100644 --- a/demos/desertpillars/source/desertpillars.cpp +++ b/demos/desertpillars/source/desertpillars.cpp @@ -24,7 +24,7 @@ DesertPillars::DesertPillars(int, char **): keyboard(window), view(window, gl_ctx), camera(resources.get("Camera.camera")), - sphere(resources.get("sphere_phong.object")), + sphere(resources.get("Sphere.object")), sphere_morph(0.0f), sphere_frozen(false), sphere_stopped(false), @@ -55,7 +55,7 @@ DesertPillars::DesertPillars(int, char **): step->set_lighting(&resources.get("Desert.lightn")); step->set_depth_test(&GL::DepthTest::lequal()); - env_map = make_unique(256, GL::RGB16F, sphere, *env_seq); + env_map = make_unique(256, GL::RGB16F, 7, sphere, *env_seq); sphere.set_matrix(GL::Matrix::translation(GL::Vector3(0.0f, 0.0f, 3.3f))); content.add(resources.get("Background.scene"));