mirror of
https://github.com/openglobus/openglobus.git
synced 2025-12-08 19:25:27 +00:00
#510 removed normalMatrix from geoObject. All light sources now are directional only.
This commit is contained in:
parent
e97232da1c
commit
8b643d567f
@ -203,8 +203,8 @@ let sat = new XYZ("sat", {
|
||||
|
||||
var highResTerrain = new MapboxTerrain(null, {
|
||||
maxZoom: 15,
|
||||
//url: "//terrain.openglobus.org/public/eu10/{z}/{x}/{y}.png",
|
||||
url: "//terrain.openglobus.org/public/austria10/{z}/{x}/{y}.png",
|
||||
url: "//terrain.openglobus.org/public/eu10/{z}/{x}/{y}.png",
|
||||
//url: "//terrain.openglobus.org/public/austria10/{z}/{x}/{y}.png",
|
||||
//url: "//terrain.openglobus.org/public/nz/{z}/{x}/{y}.png",
|
||||
//url: "//127.0.0.1/terrain/andorra/dest/{z}/{x}/{y}.png",
|
||||
//imageSize: 129,
|
||||
@ -221,9 +221,9 @@ var globus = new Globe({
|
||||
//frustums: [[100, 100000000]],
|
||||
maxAltitude: 15000000,
|
||||
minAltitude: 1,
|
||||
//terrain: highResTerrain,
|
||||
terrain: highResTerrain,
|
||||
//terrain: new MapboxTerrain(),
|
||||
terrain: new GlobusTerrain(),
|
||||
//terrain: new GlobusTerrain(),
|
||||
//maxEqualZoomAltitude: 1,
|
||||
layers: [sat, tg, osm],
|
||||
//frustums: [[1, 1e3 + 100], [1e3, 1e6 + 10000], [1e6, 1e9]],
|
||||
|
||||
@ -123,8 +123,10 @@ class Sun extends Control {
|
||||
var tr = Vec3.proj_b_to_plane(cam._r, n, cam._r)
|
||||
.normalize()
|
||||
.scale(this.offsetHorizontal); // right
|
||||
|
||||
var d = tu.add(tr);
|
||||
var pos = cam.eye.add(d);
|
||||
|
||||
if (this._k > 0) {
|
||||
this._k -= 0.01;
|
||||
let rot = Quat.getRotationBetweenVectors(
|
||||
|
||||
@ -358,7 +358,7 @@ class GeoObjectHandler {
|
||||
|
||||
sh.activate();
|
||||
|
||||
gl.disable(gl.CULL_FACE);
|
||||
gl.enable(gl.CULL_FACE);
|
||||
gl.uniform3fv(u.uScaleByDistance, ec.scaleByDistance);
|
||||
|
||||
gl.uniform3fv(u.eyePositionHigh, r.activeCamera.eyeHigh);
|
||||
@ -366,7 +366,6 @@ class GeoObjectHandler {
|
||||
|
||||
gl.uniformMatrix4fv(u.projectionMatrix, false, r.activeCamera.getProjectionMatrix());
|
||||
gl.uniformMatrix4fv(u.viewMatrix, false, r.activeCamera.getViewMatrix());
|
||||
gl.uniformMatrix3fv(u.normalMatrix, false, r.activeCamera.getNormalMatrix());
|
||||
|
||||
gl.uniform3fv(u.lightsPositions, this._planet._lightsPositions);
|
||||
gl.uniform3fv(u.lightsParamsv, this._planet._lightsParamsv);
|
||||
|
||||
@ -127,9 +127,11 @@ class LightSource {
|
||||
this._ambient.x = rn._lightsParamsv[index] = this._tempAmbient.x;
|
||||
this._ambient.y = rn._lightsParamsv[index + 1] = this._tempAmbient.y;
|
||||
this._ambient.z = rn._lightsParamsv[index + 2] = this._tempAmbient.z;
|
||||
|
||||
this._diffuse.x = rn._lightsParamsv[index + 3] = this._tempDiffuse.x;
|
||||
this._diffuse.y = rn._lightsParamsv[index + 4] = this._tempDiffuse.y;
|
||||
this._diffuse.z = rn._lightsParamsv[index + 5] = this._tempDiffuse.z;
|
||||
|
||||
this._specular.x = rn._lightsParamsv[index + 6] = this._tempSpecular.x;
|
||||
this._specular.y = rn._lightsParamsv[index + 7] = this._tempSpecular.y;
|
||||
this._specular.z = rn._lightsParamsv[index + 8] = this._tempSpecular.z;
|
||||
|
||||
@ -235,6 +235,21 @@ class RenderNode extends BaseNode {
|
||||
this._lightsPositions[ii + 1] = tp.y;
|
||||
this._lightsPositions[ii + 2] = tp.z;
|
||||
}
|
||||
|
||||
// for (var i = 0; i < this._lights.length; i++) {
|
||||
// var ii = i * 4;
|
||||
// var tp;
|
||||
// if (this._lights[i].directional) {
|
||||
// tp = r.activeCamera._normalMatrix.mulVec(this._lights[i]._position);
|
||||
// this._lightsTransformedPositions[ii + 3] = 0;
|
||||
// } else {
|
||||
// tp = r.activeCamera._viewMatrix.mulVec3(this._lights[i]._position);
|
||||
// this._lightsTransformedPositions[ii + 3] = 1;
|
||||
// }
|
||||
// this._lightsTransformedPositions[ii] = tp.x;
|
||||
// this._lightsTransformedPositions[ii + 1] = tp.y;
|
||||
// this._lightsTransformedPositions[ii + 2] = tp.z;
|
||||
// }
|
||||
}
|
||||
|
||||
updateBillboardsTexCoords() {
|
||||
|
||||
@ -500,6 +500,8 @@ export function drawnode_screen_wl_webgl2() {
|
||||
|
||||
v_height = height;
|
||||
v_vertex = aVertexPosition + normalize(aVertexPosition) * height;
|
||||
//v_vertex = viewMatrix * vec4(heightVertex, 1.0);
|
||||
|
||||
vTextureCoord.xy = aTextureCoord;
|
||||
vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;
|
||||
vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );
|
||||
@ -517,6 +519,8 @@ export function drawnode_screen_wl_webgl2() {
|
||||
uniform vec3 diffuse;
|
||||
uniform vec3 ambient;
|
||||
uniform vec4 specular;
|
||||
|
||||
//uniform mat3 normalMatrix;
|
||||
|
||||
uniform sampler2D uNormalMap;
|
||||
uniform vec3 lightsPositions[MAX_POINT_LIGHTS];
|
||||
@ -684,19 +688,19 @@ export function drawnode_screen_wl_webgl2() {
|
||||
|
||||
sunPos = lightsPositions[0];
|
||||
|
||||
vec3 texNormal = texture(uNormalMap, vTextureCoord.zw).rgb;
|
||||
vec3 texNormal = texture(uNormalMap, vTextureCoord.zw).rgb;
|
||||
vec3 normal = normalize((texNormal - 0.5) * 2.0);
|
||||
|
||||
float minH = 700000.0;
|
||||
float maxH = minH * 3.0;
|
||||
float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;
|
||||
|
||||
if(camHeight > 700000.0)
|
||||
{
|
||||
normal = normalize(v_vertex);
|
||||
}
|
||||
// if(camHeight > 700000.0)
|
||||
// {
|
||||
// normal = normalize(v_vertex);
|
||||
// }
|
||||
|
||||
vec3 lightDir = normalize(sunPos - v_vertex);
|
||||
vec3 lightDir = normalize(sunPos);
|
||||
vec3 viewDir = normalize(cameraPosition - v_vertex);
|
||||
|
||||
vec4 atmosColor;
|
||||
@ -706,6 +710,21 @@ export function drawnode_screen_wl_webgl2() {
|
||||
getSunIlluminance(v_vertex * SPHERE_TO_ELLIPSOID_SCALE, lightDir * SPHERE_TO_ELLIPSOID_SCALE, sunIlluminance);
|
||||
|
||||
float overGround = 1.0 - step(0.1, v_height);
|
||||
|
||||
// vec3 lightDirection = normalize(lightsPositions[0].xyz - v_vertex.xyz * lightsPositions[0].w);
|
||||
// vec3 eyeDirection = normalize(-v_vertex.xyz);
|
||||
// vec3 reflectionDirection = reflect(-lightDirection, normal); //normal = normalize(normalMatrix * normal)
|
||||
// vec4 nightImageColor = texture( nightTexture, vGlobalTextureCoord.st );
|
||||
//
|
||||
// float overGround = 1.0 - step(0.1, v_height);
|
||||
// shininess = texture( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;
|
||||
// reflection = max( dot(reflectionDirection, eyeDirection), 0.0);
|
||||
// diffuseLightWeighting = max(dot(normal, lightDirection), 0.0);
|
||||
// night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb;
|
||||
// night *= overGround * step(0.0, night);
|
||||
//
|
||||
// vec3 spec = specular.rgb * pow( reflection, specular.w) * shininess;
|
||||
// vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + spec + night * 3.0, 1.0);
|
||||
|
||||
float shininess = texture( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;
|
||||
vec3 reflectionDirection = reflect(-lightDir, normal);
|
||||
|
||||
@ -11,7 +11,6 @@ export const geo_object = () =>
|
||||
uniforms: {
|
||||
viewMatrix: "mat4",
|
||||
projectionMatrix: "mat4",
|
||||
normalMatrix: "mat3",
|
||||
|
||||
uScaleByDistance: "vec3",
|
||||
|
||||
@ -57,13 +56,13 @@ export const geo_object = () =>
|
||||
uniform vec3 uScaleByDistance;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform mat3 normalMatrix;
|
||||
|
||||
uniform vec3 eyePositionHigh;
|
||||
uniform vec3 eyePositionLow;
|
||||
|
||||
varying vec3 cameraPosition;
|
||||
varying vec3 vNormal;
|
||||
varying vec4 vPosition;
|
||||
varying vec3 v_vertex;
|
||||
varying vec4 vColor;
|
||||
varying float vDispose;
|
||||
varying float vUseTexture;
|
||||
@ -98,7 +97,7 @@ export const geo_object = () =>
|
||||
);
|
||||
|
||||
vec3 position = aPositionHigh + aPositionLow;
|
||||
vec3 cameraPosition = eyePositionHigh + eyePositionLow;
|
||||
cameraPosition = eyePositionHigh + eyePositionLow;
|
||||
vec3 r = cross(normalize(-position), aDirection);
|
||||
mat3 modelMatrix = mat3(r, normalize(position), -aDirection) * rotX * rotZ;
|
||||
|
||||
@ -112,7 +111,7 @@ export const geo_object = () =>
|
||||
|
||||
vec3 look = cameraPosition - position;
|
||||
float lookLength = length(look);
|
||||
vNormal = normalMatrix * modelMatrix * aVertexNormal;
|
||||
vNormal = aVertexNormal;
|
||||
|
||||
// if(lookLength > uScaleByDistance[1])
|
||||
// {
|
||||
@ -125,44 +124,44 @@ export const geo_object = () =>
|
||||
// ... is the same math
|
||||
float scd = uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];
|
||||
|
||||
vPosition = vec4((highDiff + lowDiff) + modelMatrix * aVertexPosition * aScale * scd, 1.0);
|
||||
gl_Position = projectionMatrix * viewMatrixRTE * vPosition;
|
||||
vec3 vert = aVertexPosition * aScale * scd;
|
||||
v_vertex = position + vert;
|
||||
|
||||
gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff + lowDiff + vert, 1.0);
|
||||
}`,
|
||||
|
||||
fragmentShader: `precision highp float;
|
||||
|
||||
varying vec4 vColor;
|
||||
#define MAX_POINT_LIGHTS 1
|
||||
|
||||
uniform vec3 lightsPositions[MAX_POINT_LIGHTS];
|
||||
uniform vec3 lightsParamsv[MAX_POINT_LIGHTS * 3];
|
||||
uniform float lightsParamsf[MAX_POINT_LIGHTS];
|
||||
|
||||
uniform float lightsParamsf[MAX_POINT_LIGHTS];
|
||||
uniform sampler2D uTexture;
|
||||
varying vec2 vTexCoords;
|
||||
|
||||
varying vec3 cameraPosition;
|
||||
varying vec3 v_vertex;
|
||||
varying vec4 vColor;
|
||||
varying vec3 vNormal;
|
||||
varying vec4 vPosition;
|
||||
varying vec2 vTexCoords;
|
||||
varying float vUseTexture;
|
||||
|
||||
void main(void) {
|
||||
vec3 lightWeighting;
|
||||
vec3 lightDirection;
|
||||
vec3 normal;
|
||||
vec3 eyeDirection;
|
||||
vec3 reflectionDirection;
|
||||
float specularLightWeighting;
|
||||
float diffuseLightWeighting;
|
||||
void main(void) {
|
||||
vec3 normal = normalize(vNormal);
|
||||
|
||||
lightDirection = normalize(lightsPositions[0].xyz - vPosition.xyz);
|
||||
normal = normalize(vNormal);
|
||||
eyeDirection = normalize(-vPosition.xyz);
|
||||
reflectionDirection = reflect(-lightDirection, normal);
|
||||
specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), lightsParamsf[0]);
|
||||
diffuseLightWeighting = max(dot(normal, lightDirection), 0.0);
|
||||
lightWeighting = lightsParamsv[0] + lightsParamsv[1] * diffuseLightWeighting + lightsParamsv[2] * specularLightWeighting;
|
||||
vec3 lightDir = normalize(lightsPositions[0]);
|
||||
vec3 viewDir = normalize(cameraPosition - v_vertex);
|
||||
vec3 reflectionDirection = reflect(-lightDir, normal);
|
||||
float reflection = max( dot(reflectionDirection, viewDir), 0.0);
|
||||
float specularLightWeighting = pow( reflection, lightsParamsf[0]);
|
||||
float diffuseLightWeighting = max(dot(normal, lightDir), 0.0);
|
||||
vec3 lightWeighting = lightsParamsv[0] + lightsParamsv[1] * diffuseLightWeighting + lightsParamsv[2] * specularLightWeighting;
|
||||
vec4 tColor = texture2D(uTexture, vTexCoords);
|
||||
gl_FragColor = vec4(lightWeighting , 1.0) * mix(vColor, tColor, vUseTexture);
|
||||
if(vUseTexture > 0.0){
|
||||
gl_FragColor = vec4(tColor.rgb * lightWeighting, tColor.a);
|
||||
} else {
|
||||
gl_FragColor = vec4(vColor.rgb * lightWeighting, vColor.a);
|
||||
}
|
||||
}`
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user