Skip to content
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

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Fog plus height and noise #1313

wants to merge 15 commits into from

Conversation

dmorehead
Copy link
Contributor

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

@andreasplesch
Copy link
Contributor

Please resolve conflicts. Probably easiest to git pull or sync master from github, and use a new branch.

@andreasplesch
Copy link
Contributor

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.

@dmorehead
Copy link
Contributor Author

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]
Copy link
Contributor

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 );
Copy link
Contributor

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 ?

@andreasplesch
Copy link
Contributor

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)

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" +
Copy link
Contributor

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" +
Copy link
Contributor

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" +
Copy link
Contributor

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" +
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants