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

Lens Flare #5498

Closed
wants to merge 16 commits into from
Closed

Lens Flare #5498

wants to merge 16 commits into from

Conversation

byumjin
Copy link
Contributor

@byumjin byumjin commented Jun 19, 2017

The algorithm of this Lens flare is, actually, for HDR texutre.
But, Cesium does not use HDR texture. So, I have to modify the implementing way to fit with Cesium.
I would like to notify some issues for later maintainer

  • Zero, there is some kind of initialization problem (Sean already knew this problem).
    It will disappear when the user updates variables ( ex) Lens Flare check box, Intensity slide .......)

  • First, about algorithm, instead of using HDR texture, I used Scene Image for creating Lensflare effect.
    So, I masked the portion of sun with shader codes, if then it can also address the situation what sun is blocked by the earth.

  • Second, at the inner Earth mode, if the sun exists with terrains in the screen space, the terrains are also used to create Lens flare effect.

  • Third, two texture made by me are being used for Lens Flare (DirtMaskTextureExample.png, StarBurst.png)
    It seems that those size are little bit bigger than the images already used for Cesium.
    Feel free to modify these, if you want

lilleyse and others added 2 commits June 15, 2017 11:28
The algorithm of this Lens flare is, actually, for HDR texutre.
But, Cesium does not use HDR texture. So, I have to modify the implementing way to fit with Cesium.
I would like to notify some issues for later maintainer

- Zero, there is some kind of initialization problem (Sean already knew this problem).
  It will disappear when the user updates variables ( ex) Lens Flare check box, Intensity slide .......)

- First, about algorithm, instead of using HDR texture, I used Scene Image for creating Lensflare effect.
  So, I masked the portion of sun with shader codes, if then it can also address the situation what sun is blocked by the earth.

- Second, at the inner Earth mode, if the sun exists with terrains in the screen space, the terrains are also used to create Lens flare effect.

- Third, two texture made by me are being used for Lens Flare (DirtMaskTextureExample.png, StarBurst.png)
  It seems that those size are little bit bigger than the images already used for Cesium.
  Feel free to modify these, if you want
@byumjin
Copy link
Contributor Author

byumjin commented Jun 19, 2017

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 19, 2017

Very cool, thanks @byumjin!

When I run your branch locally, I get this:

image

Perhaps I did something wrong merging in the latest version of the post-processing branch?

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 19, 2017

http://localhost:8080/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=f32e90b16dbefd3176d30bfcaea122e9

Could you also make this a Sandcastle example inside Cesium, including a screenshot? For examples, see https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Apps/Sandcastle/gallery

We can figure out the public API later since this is going into the in-progress post-processing branch.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 19, 2017

Also, please add yourself to CONTRIBUTORS.md.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 19, 2017

Did you create both .png files yourself? If not, do you know the source(s)? I need to determine if we are allowed to use them and what credit they would require.

Also, these .png files are pretty large. Do they need to be .png or could they be .jpg? Could they also be a lower resolution? Or would this impact visual quality too much?

@lilleyse
Copy link
Contributor

That initial image is due to all the post-processing stages being on by default in that branch. Also the initialization of the Sandcastle UI with the actual code is not quite right. A bunch of those changes will be fixed in the post-processing branch.

@byumjin
Copy link
Contributor Author

byumjin commented Jun 19, 2017 via email

@pjcozzi pjcozzi mentioned this pull request Jun 19, 2017
@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 19, 2017

@lilleyse gotcha. Please bump when fixed.

byumjin added 2 commits June 19, 2017 16:10
add Byumjin Kim
Add SendCastle for LensFlare
@byumjin
Copy link
Contributor Author

byumjin commented Jun 19, 2017

I made StartBurst.png by my self
But, I modified the source image from below url to create DirtMaskTextureExample,png

https://www.google.com/search?q=dirt+mask+texture&num=100&rlz=1C1CHZL_enUS746US746&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjQ-uXj7srUAhVLND4KHcFpCREQ_AUICigB&biw=1884&bih=927#imgrc=sqsQ1z8ufMbglM:

And, yes, it could be jpg and also find to use lower resolution version.

Fixed Mix tap and spacevvvvvvvvvvvv
@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 19, 2017

But, I modified the source image from below url to create DirtMaskTextureExample,png

There is not an obvious license associated with that image so we can't include it. Do you want to try to create a new image? Or I can ask if someone on the Cesium team could do it.

@byumjin
Copy link
Contributor Author

byumjin commented Jun 19, 2017 via email

Sry for concern about the source image. I just made new one. And disable other postprocess. Now, you can check the lens flare on SandCastle. But, it is still have an initialization issue.
@byumjin
Copy link
Contributor Author

byumjin commented Jun 19, 2017

Sry for concern about the source image. I just made new one. And disable other postprocess. Now, you can check the lens flare on SandCastle. But, it is still have an initialization issue.

Delete previous images
@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 19, 2017

Thanks for creating the new image! We'll do a code review soon.

Optimization
@byumjin
Copy link
Contributor Author

byumjin commented Jun 22, 2017

@lilleyse Could you please do a review?

Copy link
Contributor

@pjcozzi pjcozzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick review, mostly style changes. @lilleyse or @bagnell should still look at this.

];

this._postProcessor = new PostProcessor({
stages : stages
});
}

function createLensFlareStage() {
var url_Dirt = buildModuleUrl('Assets/Textures/LensFlare/DirtMask.jpg');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For local variable naming conventions, we use camelCase.

If you haven't already browse through our Coding Guide.


var uniformValues = {

DirtTexture: url_Dirt,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same camelCase comment here and throughout.

var url_Star = buildModuleUrl('Assets/Textures/LensFlare/StarBurst.jpg');

var uniformValues = {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra whitespace.

'uniform sampler2D u_DirtTexture; \n' +
'uniform sampler2D u_StarTexture; \n' +

'uniform float u_Distortion; \n' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is currently possible with the post-processing framework, I would combine all these floats into a vec4...and generally pack uniforms together as much as possible. We'll still want to expose these in JavaScript as separate variables then map to the uniforms x, y, z, w components like we do here.

Since this shader isn't called often, this isn't a huge performance issue, but this is the common practice throughout Cesium.

If the post-process framework doesn't support this, @lilleyse can add it and we can wait on this change or @byumjin you are welcome to go for it.

Copy link
Contributor

@lilleyse lilleyse Jun 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does support vec4, should work by sending a Cartesian4 to the uniform values area.

'varying vec2 v_textureCoordinates; \n' +

//return ndc from world coordinate biased EarthRadius
'vec4 GetNDCFromWC(in vec3 WC, in float EarthRadius) \n' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this a built-in Cesium GLSL function including a unit test?

For example, see

https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Source/Shaders/Builtin/Functions

and

https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Specs/Renderer/BuiltinFunctionsSpec.js

To learn more about unit tests in general, see our Testing Guide, especially the GLSL section.

Also rename this to czm_WorldCoordinatestoNDC like our color transform functions.

'bool bSpace = true; \n' +

//whether it is in space or not
'if(length(czm_viewerPositionWC.xyz) < 6500000.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.

How did you determine 6500000.0?

' vec2 offset = fract(texcoord + ghostVec * float(i)); \n' +

//Only bright spots from the centre of the source image
//' float weight = length(vec2(0.5) - offset) / length(vec2(0.5)); \n' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete commented out code.

If you really need it, it could stay for now, but once this is merged into master, we do not leave in commented out code.

//Rotating starburst texture's coordinate
' vec3 camx = vec3(czm_view[0][0], czm_view[0][1], czm_view[0][2] ); \n' +
' vec3 camz = vec3(czm_view[1][0], czm_view[1][1], czm_view[1][2] ); \n' +
' float camrot = dot(camx, vec3(0, 0, 1)) + dot(camz, vec3(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.

Throughout GLSL, when your intention is floating point, always include .0, e.g., 0.0, etc.

On some implementations, not doing so at least use to result in a compiler error.

' vec3 camz = vec3(czm_view[1][0], czm_view[1][1], czm_view[1][2] ); \n' +
' float camrot = dot(camx, vec3(0, 0, 1)) + dot(camz, vec3(0, 1, 0)); \n' +

' mat3 rotation = mat3( \n' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't trust that all GLSL compilers for factor out the common cos and sin calls. Call each function once above here and assign to local variables.

@@ -0,0 +1,5024 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this file should be included? I think you should remove it from git.

@byumjin
Copy link
Contributor Author

byumjin commented Jun 23, 2017 via email

byumjin added 2 commits June 23, 2017 13:22
LensFlare codes refine
Add WorldCoordinatestoNDC for a built-in Cesium GLSL function including a unit test
Delete pakage-lock.json
remove package-lock
@byumjin
Copy link
Contributor Author

byumjin commented Jun 23, 2017 via email

@byumjin
Copy link
Contributor Author

byumjin commented Jun 23, 2017 via email

@byumjin
Copy link
Contributor Author

byumjin commented Jun 23, 2017 via email

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 23, 2017

@byumjin not 100% sure about the build error. At some point you have ran

npm install

correct?

Then you get this error when running the following command (or another build step)?

npm run build

You could try deleting your node_modules directory then re-running npm install then npm run build.

Also, we usually use the GitHub UI to add comments to issues instead of replying to the GitHub notification email since replying to the email includes all the quoted text in the GitHub comment.

@byumjin
Copy link
Contributor Author

byumjin commented Jun 23, 2017

Yes, I just deleted my node_modules directory and re-running npm install then npm run build.
But, it still made package-lock.json. And, it worked well....
Even if it doesn't have package-lock.json, it seems to be fine when I tested it locally.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 23, 2017

Yes, I just deleted my node_modules directory and re-running npm install then npm run build.
But, it still made package-lock.json. And, it worked well....
Even if it doesn't have package-lock.json, it seems to be fine when I tested it locally.

@mramato do you know if we should add package-lock.json to the .gitignore? (@byumjin this would prevent it from being submitted to git).

@byumjin
Copy link
Contributor Author

byumjin commented Jun 23, 2017

Then, how can I make my fork to be built correctly?
Current status works well in my machine, but it still failed on Travis CI

byumjin added 2 commits June 24, 2017 10:33
(Test) commits new files when I run new server
+ add my name on Analytical Graphics, Inc. in CONTRIBUTORS.md
@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 26, 2017

Can you send me a link to the failure in Travis CI? Looks like it is passing now: https://travis-ci.org/AnalyticalGraphicsInc/cesium/builds/247264174

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 26, 2017

@byumjin please remove all the .vs/* files in one commit and then add that directory to .gitignore so they are not adding to Cesium's git repo.

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 26, 2017

@lilleyse please help see this one over the finish line when you are available.

@byumjin
Copy link
Contributor Author

byumjin commented Jun 26, 2017 via email

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 26, 2017

That is an older commit; Travis is passing now.

removed .vs files
@byumjin
Copy link
Contributor Author

byumjin commented Jun 26, 2017 via email

@pjcozzi
Copy link
Contributor

pjcozzi commented Jun 27, 2017

Perfect, thanks!

@lilleyse lilleyse mentioned this pull request Jul 11, 2017
12 tasks
@lilleyse lilleyse changed the base branch from post-processing to post-processing-1.0 July 11, 2017 20:48
lilleyse and others added 3 commits July 11, 2017 16:54
Has added HBAO codes and SandCastle
and fixed broken parts of LensFlare when it was merged
@lilleyse
Copy link
Contributor

Lens flare is also included in #5645, I'll do the final review there.

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.

3 participants