New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fog plus height and noise #1313
base: master
Are you sure you want to change the base?
Conversation
Please resolve conflicts. Probably easiest to |
Do you think it is possible to directly use fogHeight to normalize the WS .y component, rather than fogRange ? It would be good to decouple vertical fog gradients from view direction fog gradients. |
good suggestion, normalized fogHeight separately from fogRange. Its a bit less code and the result seems more visually predictable. Also updated the pen with these changes (codepen has a 1MB limit so I've only included x3dom.js, not x3dom-full.js) |
* @var {x3dom.fields.SFFloat} fogHeight | ||
* @memberof x3dom.nodeTypes.X3DFogNode | ||
* @initvalue 0 | ||
* @range [0, -inf] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[0, inf]
* @instance | ||
* Hint: Start with a low visibilityRange (very dense fog) to adjust fogHeight. | ||
*/ | ||
this.addField_SFFloat( ctx, "fogHeight", 1000000.0 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the default value be 0
?
The pen looks good. Did you want to incorporate these changes in the PR as well, eg. commit them to the branch ? |
" if (fogHeight == 0.0) {\n" + | ||
" color.rgb = mix( fcol, color.rgb, f0 );\n" + | ||
" } else if (fogHeight > 0.0) {\n" + | ||
" float f1 = clamp( 1.0 - ((abs(fogHeight)-fragPositionWS.y) / abs(fogHeight)), 0.0, 1.0);\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abs(fogHeight)
here always fogHeight
since positive. So use just fogHeight
" float f1 = clamp( 1.0 - ((abs(fogHeight)-fragPositionWS.y) / abs(fogHeight)), 0.0, 1.0);\n" + | ||
" color.rgb = mix( fcol, color.rgb, max(f1,f0) );\n" + | ||
" } else if (fogHeight < 0.0) {\n" + | ||
" float f1 = clamp( ((abs(fogHeight)-fragPositionWS.y) / abs(fogHeight)), 0.0, 1.0);\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since fogHeight negative, this is:
(-fogHeight-fragPositionWS.y)/-fogHeight = (fogHeight+fragPositionWS,y)/fogHeight
simplified.
May need more thinking.
" float f1 = clamp( ((abs(fogHeight)-fragPositionWS.y) / abs(fogHeight)), 0.0, 1.0);\n" + | ||
// de-couple fogHeight from fogRange | ||
//" color.rgb = mix( fcol, color.rgb, max(f1,f0) );\n" + | ||
" color.rgb = mix( fcol, color.rgb, min(f1,f0*2.0) );\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f0*2.0 ? May need clear thinking.
" } else if (fogHeight > 0.0) {\n" + | ||
" float f1 = clamp( 1.0 - ((abs(fogHeight)-fragPositionWS.y) / abs(fogHeight)), 0.0, 1.0);\n" + | ||
" color.rgb = mix( fcol, color.rgb, max(f1,f0) );\n" + | ||
" } else if (fogHeight < 0.0) {\n" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just else
The remaining if (..)
is not necessary. In the shader code branching logic should be avoided as much as possible since it is considered slow.
Optional fogHeight and fogNoise. Not setting them will maintain the original fog behavior. The height is best seen when lowering the visibility range. here is a working pen. https://codepen.io/mrmernan/pen/KKbYrdJ