David Lin avatar David Lin committed 6446f6e

demo

Comments (0)

Files changed (4)

data/assets/programs/scattering.fragment.glsl

 // distance
 float s_distance(vec3 posV, vec3 normalV) {
   // Shrink the position to avoid artifacts on the silhouette
-  posV = posV - 0.005 * normalV;
+  posV = posV - 0.01 * normalV;
   // Transform to light space (from view space)
   vec4 posL = u_LightFromView * vec4(posV, 1.0);
   posL.xy = posL.xy / posL.w * 0.5 + 0.5;
   // Fetch depth from the shadow map
   float d1 = texture(s_ShadowMap, posL.xy).r;
-  float d2 = posL.z;
+  float d2 = -posL.w;
   // Calculate the difference
   return abs(d1 - d2);
 } // END distance

data/assets/programs/shadow_map.fragment.glsl

 void main()
 { // BEGIN
   vec4 pos = u_Projection * vec4(gs_Position, 1.0);
-  fs_FragColor = vec4(pos.z);
+  fs_FragColor = vec4(-pos.w);
 } // END
     @render[:view] = Matrix3D.translate(0, 0, -5)
     @render[:inverse_view] = Matrix3D.translate(0, 0, 5)
     @render[:world] = Matrix3D.scale(10.0, 10.0, 10.0)
-    @render[:light_pos] = Vector[1.0, 1.0, -3.0, 1.0]
+    @render[:light_pos] = Vector[5.0, 5.0, -15.0, 1.0]
     @render[:light_dir] = Vector[-1, -1, 3, 0.0].normalize
     @render[:light_znear] = 1.0
     @render[:light_zfar] = 100.0
                                                 @render[:light_zfar]
     @render[:b_scatter] = true
     @render[:b_light] = true
-    @render[:scatter_strench] = 6.0
+    @render[:scatter_strench] = 0.1
   end
   
   def display
     glBindTexture GL_TEXTURE_2D, @shadow_map_tex
     glTexImage2D GL_TEXTURE_2D, 0, GL_R32F, 1024, 1024,
                  0, GL_RED, GL_FLOAT, nil
-    glTexParameterf GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
-    glTexParameterf GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
+    #glTexParameterf GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
     glBindRenderbuffer GL_RENDERBUFFER, @shadow_map_rbo
     glRenderbufferStorage GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, 1024, 1024
     glBindFramebuffer GL_FRAMEBUFFER, @shadow_map_fbo
     prog.set_3f 'u_Albedo', Vector[0.4, 0.4, 0.4]
     prog.set_3f 'u_Ks', Vector[0.5, 0.5, 0.5]
     prog.set_1f 'u_Ns', 2.0
-    prog.set_3f 'u_Light_Ka', Vector[0.0, 0.0, 0.0]
+    prog.set_3f 'u_Light_Ka', Vector[0.4, 0.4, 0.4]
     prog.set_3f 'u_Light_Kd', Vector[1.0, 1.0, 1.0]
     prog.set_3f 'u_Light_Ks', Vector[0.5, 0.5, 0.5]
     prog.set_3f 'u_Light_Pos', (self[:view] * self[:light_pos])
     # Bind Texture
     glActiveTexture GL_TEXTURE0
     glBindTexture GL_TEXTURE_2D, @shadow_map_tex
+    glGenerateMipmap GL_TEXTURE_2D
     glActiveTexture GL_TEXTURE1
     glBindTexture GL_TEXTURE_2D, @skin_tex.object
     glActiveTexture GL_TEXTURE2
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.