#
luxiaotao1123
2022-08-19 bbdf281616894604d41a0381961fc5f3282ceb37
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// scene/demo-specific variables go here
let sunAngle = 0;
let sunDirection = new THREE.Vector3();
let waterLevel = 400;
let cameraUnderWater = 0.0;
let PerlinNoiseTexture;
 
// called automatically from within initTHREEjs() function (located in InitCommon.js file)
function initSceneData()
{
    demoFragmentShaderFileName = 'Terrain_Rendering_Fragment.glsl';
 
    // scene/demo-specific three.js objects setup goes here
    sceneIsDynamic = true;
    
    cameraFlightSpeed = 300;
 
    // pixelRatio is resolution - range: 0.5(half resolution) to 1.0(full resolution)
    pixelRatio = mouseControl ? 0.7 : 0.75;
 
    EPS_intersect = 0.2;
 
    // set camera's field of view
    worldCamera.fov = 60;
    focusDistance = 3000.0;
 
    // position and orient camera
    cameraControlsObject.position.set(-837, 1350, 2156);
    cameraControlsYawObject.rotation.y = 0.0;
    cameraControlsPitchObject.rotation.x = 0.0;
 
    PerlinNoiseTexture = new THREE.TextureLoader().load('textures/perlin256.png');
    PerlinNoiseTexture.wrapS = THREE.RepeatWrapping;
    PerlinNoiseTexture.wrapT = THREE.RepeatWrapping;
    PerlinNoiseTexture.flipY = false;
    PerlinNoiseTexture.minFilter = THREE.LinearFilter;
    PerlinNoiseTexture.magFilter = THREE.LinearFilter;
    PerlinNoiseTexture.generateMipmaps = false;
 
 
    // scene/demo-specific uniforms go here
    pathTracingUniforms.t_PerlinNoise = { value: PerlinNoiseTexture };
    pathTracingUniforms.uCameraUnderWater = { value: 0.0 };
    pathTracingUniforms.uWaterLevel = { value: 0.0 };
    pathTracingUniforms.uSunDirection = { value: new THREE.Vector3() };
 
} // end function initSceneData()
 
 
 
// called automatically from within the animate() function (located in InitCommon.js file)
function updateVariablesAndUniforms()
{
 
    // scene/demo-specific variables
    sunAngle = (elapsedTime * 0.035) % (Math.PI + 0.2) - 0.11;
    sunDirection.set(Math.cos(sunAngle), Math.sin(sunAngle), -Math.cos(sunAngle) * 2.0);
    sunDirection.normalize();
 
    // scene/demo-specific uniforms
    if (cameraControlsObject.position.y < waterLevel)
        cameraUnderWater = 1.0;
    else cameraUnderWater = 0.0;
 
    pathTracingUniforms.uCameraUnderWater.value = cameraUnderWater;
    pathTracingUniforms.uWaterLevel.value = waterLevel;
    pathTracingUniforms.uSunDirection.value.copy(sunDirection);
 
    // INFO
    cameraInfoElement.innerHTML = "FOV: " + worldCamera.fov + " / Aperture: " + apertureSize.toFixed(2) + " / FocusDistance: " + focusDistance + "<br>" + "Samples: " + sampleCounter;
 
} // end function updateUniforms()
 
 
 
init(); // init app and start animating