空を描く前にファイルの準備を…
2020/4/18 作成
2020/4/18 更新
{ "sun_moon":{ ……… }, "stars":{ ……… }, "cubemap":{ ……… }, "skyplane":{ ……… }, "end_sky":{ ……… } }書くまでも無いとは思いますが一応↓
"skyplane": { "states": [ "DisableDepthWrite", "DisableAlphaWrite" ], "vertexShader" : "shaders/sky.vertex", "vrGeometryShader" : "shaders/sky.geometry", "fragmentShader" : "shaders/color.fragment", "vertexFields": [ { "field": "Position" }, { "field": "Color" } ], "msaaSupport": "Both" },statesやvertexFieldsはopengl本体に対する指令です
{ "skyplane":{ "fragmentShader":"shaders/sky.fsh" } }これで空の処理をcolor.fragmentから分離することができました
(前略) varying vec4 color; void main() { gl_Position = WORLDVIEWPROJ * POSITION; color = mix( CURRENT_COLOR, FOG_COLOR, COLOR.r ); }
(前略) varying vec4 color; void main() { gl_FragColor = color; }vertexでプログラムから渡された空の色と霧の色を混ぜて
// __multiversion__ // This signals the loading code to prepend either #version 100 or #version 300 es as apropriate. //@McbeEringi MIT_LICENSE mcbeeringi.github.io/how #include "vertexVersionSimple.h" uniform MAT4 WORLDVIEWPROJ; attribute mediump vec4 POSITION; attribute vec4 COLOR; varying float fog; varying POS3 pos; void main() { gl_Position = WORLDVIEWPROJ * POSITION; fog = COLOR.r; pos = POSITION.xyz; }
// __multiversion__ // This signals the loading code to prepend either #version 100 or #version 300 es as apropriate. //@McbeEringi MIT_LICENSE mcbeeringi.github.io/how #include "fragmentVersionSimple.h" uniform vec4 CURRENT_COLOR; uniform vec4 FOG_COLOR; varying float fog; varying POS3 pos; void main() { vec4 diffuse = CURRENT_COLOR; //write your codes here gl_FragColor = mix(diffuse,FOG_COLOR,fog); }最後の
gl_FragColor = mix(diffuse,FOG_COLOR,fog);
が霧の処理になっています