shader - GLSL lightsaber - per vertex lighting -


i'm using script render lightsaber (in blender), works fine until start rotating lightsaber: @ point blade goes crazy. please suggest me better way write code? looked (to me) best way achieve this, there surely smarter ones.

vertexshader = """  varying vec3 varyingnormaldirection; varying vec3 varyingviewdirection;      void main() {           varyingnormaldirection = normalize(gl_normalmatrix * gl_normal);   varyingviewdirection = normalize(gl_modelviewmatrix * gl_vertex);  gl_position = gl_modelviewprojectionmatrix * gl_vertex; } """  fragmentshader = """  varying vec3 varyingnormaldirection; varying vec3 varyingviewdirection;      void main() {    // project 2 vectors on plane y = 0 vec2 normaldirection = normalize(varyingnormaldirection.xz); vec2 viewdirection = normalize(varyingviewdirection.xz);  const vec4 color = vec4(1.0,1.0,1.0,0.3);  //      opacity equals infinity when view , normal have angle of 0, //      equals 0.001 when have angle of 90 //      multiply dot product between view , normal //      1 @ center, 0 @ edge, increase falloff float dotproduct = abs(dot(viewdirection, normaldirection)); float opacity = min(1.0, dotproduct * 0.01 / (1.0 - dotproduct) );  //      opacity i'm varying color, green white gl_fragcolor = vec4(1.*opacity,1.0,1.*opacity,opacity*2.);  } """ 


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -