Skip to content

Commit 1cb3e79

Browse files
committed
Fix sun positioning in ocean shader example
1 parent 5bd1155 commit 1cb3e79

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

examples/webgl_shaders_ocean.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,20 @@
9494
skyUniforms[ 'mieDirectionalG' ].value = 0.8;
9595

9696
const parameters = {
97-
inclination: 0.49,
98-
azimuth: 0.205
97+
inclination: 0.02,
98+
azimuth: 0.045
9999
};
100100

101101
const pmremGenerator = new THREE.PMREMGenerator( renderer );
102102

103103
function updateSun() {
104104

105-
const theta = Math.PI * ( parameters.inclination - 0.5 );
105+
const theta = 0.5 * Math.PI * ( 1 - parameters.inclination );
106106
const phi = 2 * Math.PI * ( parameters.azimuth - 0.5 );
107107

108-
sun.x = Math.cos( phi );
109-
sun.y = Math.sin( phi ) * Math.sin( theta );
110-
sun.z = Math.sin( phi ) * Math.cos( theta );
108+
sun.x = Math.sin( theta ) * Math.sin( phi );
109+
sun.y = Math.cos( theta );
110+
sun.z = Math.sin( theta ) * Math.cos( phi );
111111

112112
sky.material.uniforms[ 'sunPosition' ].value.copy( sun );
113113
water.material.uniforms[ 'sunDirection' ].value.copy( sun ).normalize();
@@ -145,7 +145,7 @@
145145
const gui = new GUI();
146146

147147
const folderSky = gui.addFolder( 'Sky' );
148-
folderSky.add( parameters, 'inclination', 0, 0.5, 0.0001 ).onChange( updateSun );
148+
folderSky.add( parameters, 'inclination', 0, 1, 0.0001 ).onChange( updateSun );
149149
folderSky.add( parameters, 'azimuth', 0, 1, 0.0001 ).onChange( updateSun );
150150
folderSky.open();
151151

0 commit comments

Comments
 (0)