Skip to content
Browse files

No commit message

  • Loading branch information...
2 parents f633b72 + 403051a commit 796d18637ad20dca50885aa98c9bd42864ccc40b Enigmadt committed Apr 28, 2012
View
1 .gitignore
@@ -0,0 +1 @@
+/nbproject/private/
View
BIN Waterworld example/Content/images/fels.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Waterworld example/Content/images/fels.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Waterworld example/Content/images/fels1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Waterworld example/Content/images/grass.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Waterworld example/Content/images/sand.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Waterworld example/Content/images/schnee.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN Waterworld example/Content/images/wasser.PNG
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
7 Waterworld example/Content/styles.css
@@ -0,0 +1,7 @@
+body
+{
+ font-family: Monospace;
+ background-color: #000;
+ margin: 0;
+ overflow: hidden;
+}
View
68 Waterworld example/Scripts/Shader/fragmentShader.fs
@@ -0,0 +1,68 @@
+varying vec3 vNormal;
+varying vec3 vPosition;
+varying float vNoise;
+varying vec2 vUv;
+uniform sampler2D texture0;
+uniform sampler2D texture1;
+uniform sampler2D texture2;
+uniform sampler2D texture3;
+uniform sampler2D texture4;
+uniform sampler2D grass1;
+
+varying vec3 tsPosition;
+varying vec3 tsCameraPosition;
+varying vec3 tsLightSource;
+varying float time1;
+
+uniform vec3 ambientColor; // color of ambient light
+uniform vec3 diffuseColor; // color of diffuse lighting
+uniform vec3 specularColor; // color of specular highlights
+uniform float shininess; // how shiny the surface is
+uniform vec2 scaleBias; // x = scale, y = bias
+
+void main()
+{
+ vec4 mycolor,
+ mc0 = texture2D(texture0,vUv), // Wasser.
+ mc1 = texture2D(texture1,vUv), // Sand.
+ mc2 = texture2D(texture2,vUv), // Gras.
+ mc3 = texture2D(texture3,vUv), // Fels.
+ mc4 = texture2D(texture4,vUv); // Schnee.
+ float wasserc = 1.0,
+ sandc = 1.0,
+ grasc = 1.0,
+ felsc = 1.0,
+ schneec = 1.0;
+
+ // Wasser.
+ if(vNoise < -0.1)
+ {
+ mycolor = mix(mc0, mc1, vNoise);
+ }
+ // Wasser-Sand.
+ if(vNoise < 0.0)
+ {
+ mycolor = mix(mc0,mc1,vNoise);
+ }
+ // Sand.
+ if(vNoise >= 0.0){}
+ // Sand-Gras.
+ if(vNoise > 0.05)
+ {
+ mycolor = mix(mc1,mc2,vNoise);
+ }
+ // Gras.
+ if(vNoise > 0.08){}
+ // Fels.
+ if(vNoise > 0.28){}
+ // Fels Schnee.
+ if(vNoise > 0.65)
+ {
+ mycolor = mix(mc3, mc4, vNoise);
+ }
+ // Schnee.
+ if(vNoise > 0.7){}
+
+ mycolor = mix(mc0, mc1, vNoise);// + mc2 + mc3 + mc4;
+ gl_FragColor = mycolor;
+}
View
59 Waterworld example/Scripts/Shader/vertexShader.vs
@@ -0,0 +1,59 @@
+varying vec3 vNormal;
+varying vec3 vPosition;
+varying float vNoise;
+varying vec3 vTangent;
+varying vec3 vBinormal;
+
+varying vec3 tsPosition;
+varying vec3 tsCameraPosition;
+varying vec3 tsLightSource;
+
+//attribute vec3 normal;
+attribute vec4 tangent;
+attribute vec2 texCoord;
+
+varying vec2 vUv;
+varying float time1;
+
+uniform sampler2D texture0;
+uniform sampler2D texture1;
+uniform sampler2D texture2;
+uniform sampler2D texture3;
+uniform sampler2D texture4;
+uniform float uscale;
+uniform float time;
+
+
+const float persist = 0.0565;
+float persistence = 1.0;
+const int oktave = 4;
+float h = 0.0;
+
+vec4 gpuGetCell3D(float x, const float y, float z)
+{
+ float u = (x + y * 31.0) / 256.0;
+ float v = (z - x * 31.0) / 256.0;
+
+ return (texture2D(texture0, vec2(u,v)));
+}
+
+void main()
+{
+ vNormal = normal;
+ vUv = uv * 8000.0;
+ vPosition = position;
+ time1 = time;
+
+ float noise = -1.0, temp=3000.0;
+
+ vNoise = noise;
+ vec3 noisefaktor = vec3(noise * 0.0515);
+
+ if(noise < 0.0)
+ {
+ noisefaktor = vec3(0.0);
+ }
+
+ vec3 newPosition = position + normal * noisefaktor;
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition,1.0 );
+}
View
225 Waterworld example/Scripts/functions.js
@@ -0,0 +1,225 @@
+ var camera, scene, renderer,
+ mouse = { X: 0, y: 0 },
+ scene = new THREE.Scene(),
+ camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000000000000),
+ light = new THREE.PointLight(0x8a4522, 3, 1000);
+ scene.add(camera);
+
+
+ renderer = new THREE.WebGLRenderer( { clearColor: 0x000000,antialias: true }); // CanvasRenderer();
+ renderer.setSize(window.innerWidth - 50, window.innerHeight - 50);
+
+ controls = new THREE.TrackballControls(camera);
+ controls.enabled = true;
+ controls.rotateSpeed = 1.0;
+ controls.zoomSpeed = 1.2;
+ controls.panSpeed = 0.2;
+ controls.noZoom = false;
+ controls.noPan = false;
+ controls.staticMoving = false;
+ controls.dynamicDampingFactor = 0.3;
+ controls.minDistance = 1.1;
+ controls.maxDistance = 2000000000000;
+ controls.keys = [65, 83, 68];
+ controls.target = new THREE.Vector3(-20000,0,0);
+
+
+
+ // licht einschalten -----------------------
+ light.position = new THREE.Vector3(0, 5, -5);
+ scene.add(light);
+
+ var ambilight = new THREE.AmbientLight(0xbbbbbb);
+ scene.add(ambilight);
+
+
+
+ attributes = {
+ displacement: {
+ size: { type: 'f', value: [] },
+ customColor: { type: 'c', value: [] }
+ }
+ };
+
+
+ uniforms = {
+ time: {type: "f", value: 0},
+ uscale: { type: "f", value: 100.0 },
+ ambientColor: { type: "vec3", value:(0.0,0.0,1.0) },
+ diffuseColor: { type: "vec3", value:(0.5,0.5,0.5) },
+ SpecularColor: { type: "vec", value:(0.5,0.5,0.5) },
+ shininess: { type: "f", value: 0.5 },
+ scaleBias: { type: "vec2", value:(1.0,0.5) },
+ texture0: { type: "t", value: 0, texture: THREE.ImageUtils.loadTexture( "Content/images/wasser.PNG" ) },
+ texture1: { type: "t", value: 1, texture: THREE.ImageUtils.loadTexture( "Content/images/sand.PNG" ) },
+ texture2: { type: "t", value: 2, texture: THREE.ImageUtils.loadTexture( "Content/images/grass.PNG" ) },
+ texture3: { type: "t", value: 3, texture: THREE.ImageUtils.loadTexture( "Content/images/fels1.png" ) },
+ texture4: { type: "t", value: 4, texture: THREE.ImageUtils.loadTexture( "Content/images/schnee.PNG" ) }
+ //grass1: { type: "t", value: 5, texture: THREE.ImageUtils.loadTexture( "images/grass1.PNG" ) }
+
+ };
+
+ uniforms.texture0.texture.wrapS = uniforms.texture0.texture.wrapT = THREE.RepeatWrapping;
+ uniforms.texture1.texture.wrapS = uniforms.texture1.texture.wrapT = THREE.RepeatWrapping;
+ uniforms.texture2.texture.wrapS = uniforms.texture2.texture.wrapT = THREE.RepeatWrapping;
+ uniforms.texture3.texture.wrapS = uniforms.texture3.texture.wrapT = THREE.RepeatWrapping;
+ uniforms.texture4.texture.wrapS = uniforms.texture4.texture.wrapT = THREE.RepeatWrapping;
+
+ camera.position.set(-20050,0,0)
+
+
+ var vShader = $("#vertexshader");
+ var fShader = $("#fragmentshader");
+
+ scene.add(new THREE.Mesh(new THREE.OctahedronGeometry(20000,6),new THREE.ShaderMaterial({wireframe:false, uniforms: uniforms, vertexShader: vShader.text(), fragmentShader: fShader.text() }) ));
+ //scene.add(new THREE.Mesh(new THREE.OctahedronGeometry(20000,6),new THREE.MeshBasicMaterial({color:0x0000ff, wireframe:true}) ));
+ var cubegeo = new THREE.CubeGeometry(1,1,1,2,2,2),
+ cubemat = new THREE.MeshBasicMaterial({}),
+ cube = new THREE.Mesh(cubegeo,cubemat);
+ scene.add(cube);
+ cube.position.set(-20000.5,0,0);
+ cube.scale.set(1,1,1);
+
+ var size = 1.51, length = 60000,pfeilgroese = 5000;
+
+ function v(x,y,z){
+ return new THREE.Vertex(new THREE.Vector3(x,y,z));
+ }
+
+ var lineGeor = new THREE.Geometry(),
+ lineGeog = new THREE.Geometry(),
+ lineGeob = new THREE.Geometry();
+
+ lineGeor.vertices.push(v(-length, 0, 0), v(length, 0, 0),v(length-pfeilgroese, 0, pfeilgroese),v(length-pfeilgroese, 0, -pfeilgroese),v(length, 0, 0) );
+ lineGeog.vertices.push(v(0, -length, 0), v(0, length, 0) );
+ lineGeob.vertices.push(v(0, 0, -length), v(0, 0, length) );
+
+ var lineMatr = new THREE.LineBasicMaterial({color: 0xff0000, lineWidth: size});
+ var lineMatg = new THREE.LineBasicMaterial({color: 0x00ff00, lineWidth: size});
+ var lineMatb = new THREE.LineBasicMaterial({color: 0x0000ff, lineWidth: size});
+
+ var liner = new THREE.Line(lineGeor, lineMatr),
+ lineg = new THREE.Line(lineGeog, lineMatg),
+ lineb = new THREE.Line(lineGeob, lineMatb);
+
+ // line.type = THREE.Lines;
+ scene.add(liner);scene.add(lineg);scene.add(lineb);
+
+
+ //################### Kamera Steuerung #####################################
+
+ var CameraAbstand = 30,
+ CameraDrehGeschwindigkeit = 0.4,
+ CameraTarget = new THREE.Vector3(0, 0, 0),
+ MouseDown = 0,
+ oldMouseX = 0,
+ oldMouseY = 0,
+ moveX = 0,
+ moveY = 0;
+
+
+ var rotateStart = new THREE.Vector3(),
+ rotateEnd = new THREE.Vector3(),
+ eye = new THREE.Vector3();
+
+
+ //document.addEventListener("mousemove", CameraControllMouseMove, false);
+ //document.addEventListener("mousedown", CameraControlMouseDown, false);
+ //document.addEventListener("mouseup", CameraControlMouseUp, false);
+ //window.addEventListener('DOMMouseScroll', CameraControlMouseWheel, false);
+ var moveto = 0;
+ function CameraControllMouseMove(event) {
+ event.preventDefault();
+
+
+
+
+ if (MouseDown === 1) {
+
+ moveto = 1;
+
+ window.mouse.X = ((event.clientX/ window.innerWidth) * 2 - 1);
+ window.mouse.Y = -((event.clientY / window.innerHeight) * 2 + 1);
+
+ //camera.position.z = Math.sin(mouse.X ) * Math.sin(mouse.Y ) * CameraAbstand;
+ // camera.position.x = Math.cos(mouse.X ) * CameraAbstand;
+ // camera.position.y = Math.cos(mouse.Y ) * CameraAbstand;
+
+ }
+
+ }
+
+ function CameraControlMouseDown(event) {
+ event.preventDefault();
+
+ if (event.button === 2) {
+ MouseDown = 1;
+ }
+ }
+ function CameraControlMouseUp(event) {
+ event.preventDefault();
+ if(event.button === 1){
+ MouseDown = 0;
+
+ }
+ }
+ function CameraControlMouseWheel(event) {
+ event.preventDefault();
+ $("#mouse").text(CameraAbstand);
+ if (CameraAbstand + event.detail / 3 > 0) CameraAbstand = CameraAbstand + event.detail / 3;
+
+ }
+
+
+ //#################### Kamera Steuerung ENDE ################################
+
+ function initalize() {
+ //ui();
+
+
+ document.body.appendChild(renderer.domElement);
+
+ animate();
+ }
+
+
+ var winkel = 0;
+ function animate() {
+
+ requestAnimationFrame(animate);
+
+ winkel = (winkel+1) % 360
+ var time = parseFloat(Date.now());
+ uniforms.time.value = winkel;
+ $("#mouse").text(winkel);
+ uniforms.uscale.value = camera.position.distanceTo(new THREE.Vector3(0,0,0));
+ render();
+ }
+
+
+ function render() {
+
+
+
+ //camera.position.x += 0.1;
+ // camera.lookAt(CameraTarget);
+ //particleSystem.rotation.y -= 0.00051 % 360
+
+
+ if (moveto == 1) {
+
+ if (camera.position.distanceTo(new THREE.Vector3(0, 0, 10000000)) <= 10) {
+
+ //moveto = 0;
+ }
+ else {
+ //camera.translateZ(-camera.position.distanceTo(new THREE.Vector3(0, 0, 3000000000))/5 );
+ }
+
+ }
+
+ controls.update();
+
+ renderer.clear();
+ renderer.render(scene, camera);
+ }
View
770 Waterworld example/Scripts/three.js
770 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
147 Waterworld example/example1.html
@@ -0,0 +1,147 @@
+<!DOCTYPE html>
+
+<html>
+ <head>
+ <title>Example1</title>
+ <meta charset="utf-8">
+
+ <link rel="stylesheet" type="text/css" href="Content/styles.css" />
+
+ <script type="x-shader/x-vertex" id="vertexshader" src="Scripts/Shader/vertexShader.js">
+ varying vec3 vNormal;
+ varying vec3 vPosition;
+ varying float vNoise;
+ varying vec3 vTangent;
+ varying vec3 vBinormal;
+
+ varying vec3 tsPosition;
+ varying vec3 tsCameraPosition;
+ varying vec3 tsLightSource;
+
+ //attribute vec3 normal;
+ attribute vec4 tangent;
+ attribute vec2 texCoord;
+
+ varying vec2 vUv;
+ varying float time1;
+
+ uniform sampler2D texture0;
+ uniform sampler2D texture1;
+ uniform sampler2D texture2;
+ uniform sampler2D texture3;
+ uniform sampler2D texture4;
+ uniform float uscale;
+ uniform float time;
+
+ const float persist = 0.0565;
+ float persistence = 1.0;
+ const int oktave = 4;
+ float h = 0.0;
+
+ vec4 gpuGetCell3D(float x, const float y, float z)
+ {
+ float u = (x + y * 31.0) / 256.0;
+ float v = (z - x * 31.0) / 256.0;
+
+ return (texture2D(texture0, vec2(u,v)));
+ }
+
+ void main()
+ {
+ vNormal = normal;
+ vUv = uv * 8000.0;
+ vPosition = position;
+ time1 = time;
+
+ float noise = -1.0, temp=3000.0;
+
+ vNoise = noise;
+ vec3 noisefaktor = vec3(noise * 0.0515);
+
+ if(noise < 0.0)
+ {
+ noisefaktor = vec3(0.0);
+ }
+
+ vec3 newPosition = position + normal * noisefaktor;
+ gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition,1.0 );
+ }
+ </script>
+ <script type="x-shader/x-fragment" id="fragmentshader">
+ varying vec3 vNormal;
+ varying vec3 vPosition;
+ varying float vNoise;
+ varying vec2 vUv;
+ uniform sampler2D texture0;
+ uniform sampler2D texture1;
+ uniform sampler2D texture2;
+ uniform sampler2D texture3;
+ uniform sampler2D texture4;
+ uniform sampler2D grass1;
+
+ varying vec3 tsPosition;
+ varying vec3 tsCameraPosition;
+ varying vec3 tsLightSource;
+ varying float time1;
+
+ uniform vec3 ambientColor; // color of ambient light
+ uniform vec3 diffuseColor; // color of diffuse lighting
+ uniform vec3 specularColor; // color of specular highlights
+ uniform float shininess; // how shiny the surface is
+ uniform vec2 scaleBias; // x = scale, y = bias
+
+ void main()
+ {
+ vec4 mycolor,
+ mc0 = texture2D(texture0,vUv), // Wasser.
+ mc1 = texture2D(texture1,vUv), // Sand.
+ mc2 = texture2D(texture2,vUv), // Gras.
+ mc3 = texture2D(texture3,vUv), // Fels.
+ mc4 = texture2D(texture4,vUv); // Schnee.
+ float wasserc = 1.0,
+ sandc = 1.0,
+ grasc = 1.0,
+ felsc = 1.0,
+ schneec = 1.0;
+
+ // Wasser.
+ if(vNoise < -0.1)
+ {
+ mycolor = mix(mc0, mc1, vNoise);
+ }
+ // Wasser-Sand.
+ if(vNoise < 0.0)
+ {
+ mycolor = mix(mc0, mc1, vNoise);
+ }
+ // Sand.
+ if(vNoise >= 0.0){}
+ // Sand-Gras.
+ if(vNoise > 0.05)
+ {
+ mycolor = mix(mc1,mc2,vNoise);
+ }
+ // Gras.
+ if(vNoise > 0.08){}
+ // Fels.
+ if(vNoise > 0.28){}
+ // Fels Schnee.
+ if(vNoise > 0.65)
+ {
+ mycolor = mix(mc3, mc4, vNoise);
+ }
+ // Schnee.
+ if(vNoise > 0.7){}
+
+ mycolor = mix(mc0, mc1, vNoise);// + mc2 + mc3 + mc4;
+ gl_FragColor = mycolor;
+ }
+ </script>
+ </head>
+
+ <body onload="initalize();">
+ <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" ></script>
+ <script type="text/javascript" src="Scripts/three.js"></script>
+ <script type="text/javascript" src="Scripts/functions.js"></script>
+ </body>
+</html>
View
BIN images/Thumbs.db
Binary file not shown.
View
BIN images/hm.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
1,413 js/Three.js
686 additions, 727 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
7 nbproject/project.properties
@@ -0,0 +1,7 @@
+include.path=${php.global.include.path}
+php.version=PHP_53
+source.encoding=UTF-8
+src.dir=.
+tags.asp=false
+tags.short=true
+web.root=.
View
9 nbproject/project.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1">
+ <type>org.netbeans.modules.php.project</type>
+ <configuration>
+ <data xmlns="http://www.netbeans.org/ns/php-project/1">
+ <name>shader</name>
+ </data>
+ </configuration>
+</project>
View
492 shader.html
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
-
+ <meta charset="utf-8" />
<style>
body {
font-family: Monospace;
@@ -22,9 +22,11 @@
<script type="x-shader/x-vertex" id="vertexshader">
+
+ attribute vec3 aVertexPosition;
+ attribute vec2 aTextureCoord;
varying vec3 vNormal;
varying vec3 vPosition;
- varying float vNoise;
varying vec3 vTangent;
varying vec3 vBinormal;
@@ -37,42 +39,27 @@
attribute vec2 texCoord;
varying vec2 vUv;
- varying float time1;
-
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D texture4;
+ uniform sampler2D heightMap;
uniform float uscale;
- uniform float time;
-
-
- const float persist = 0.0565;
- float persistence = 1.0;
- const int oktave = 4;
- float h = 0.0;
-
-
-
+
void main() {
vNormal = normal;
- vUv = uv*8000.0;
+ vUv = uv*100.0;
vPosition = position;
- time1 = time;
-
- float noise,temp=3000.0;
-
- noise = ^^ 1.0;
-
-
- vNoise = noise;
- vec3 noisefaktor = vec3(noise*0.0515);
- if(noise < 0.0) {noisefaktor = vec3(0.0); }
+
- vec3 newPosition = position + normal * noisefaktor;
+ //noise = texture2D(heightMap,uv).r + texture2D(heightMap,uv).g + texture2D(heightMap,uv).b;
+
+ vec3 newPosition = position + normal ;
gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition,1.0 );
+
+
}
@@ -82,53 +69,219 @@
varying vec3 vNormal;
varying vec3 vPosition;
- varying float vNoise;
+
varying vec2 vUv;
uniform sampler2D texture0;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D texture4;
+ uniform sampler2D heightMap;
+
varying vec3 tsPosition;
varying vec3 tsCameraPosition;
varying vec3 tsLightSource;
- varying float time1;
uniform vec3 ambientColor; // color of ambient light
uniform vec3 diffuseColor; // color of diffuse lighting
uniform vec3 specularColor; // color of specular highlights
uniform float shininess; // how shiny the surface is
uniform vec2 scaleBias; // x = scale, y = bias
-
+
+ const float persist = 0.388515;
+ float persistence = 1.0;
+ const int frequenz = 4;
+ float h = 0.0;
+
+
+ vec3 mod289(vec3 x)
+ {
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
+ }
+
+ vec4 mod289(vec4 x)
+ {
+ return x - floor(x * (1.0 / 289.0)) * 289.0;
+ }
+
+ vec4 permute(vec4 x)
+ {
+ return mod289(((x*34.0)+1.0)*x);
+ }
+
+ vec4 taylorInvSqrt(vec4 r)
+ {
+ return 1.79284291400159 - 0.85373472095314 * r;
+ }
+
+ vec3 fade(vec3 t) {
+ return t*t*t*(t*(t*6.0-15.0)+10.0);
+ }
+
+ // Classic Perlin noise
+ float cnoise(vec3 P)
+ {
+ vec3 Pi0 = floor(P); // Integer part for indexing
+ vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1
+ Pi0 = mod289(Pi0);
+ Pi1 = mod289(Pi1);
+ vec3 Pf0 = fract(P); // Fractional part for interpolation
+ vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0
+ vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
+ vec4 iy = vec4(Pi0.yy, Pi1.yy);
+ vec4 iz0 = Pi0.zzzz;
+ vec4 iz1 = Pi1.zzzz;
+
+ vec4 ixy = permute(permute(ix) + iy);
+ vec4 ixy0 = permute(ixy + iz0);
+ vec4 ixy1 = permute(ixy + iz1);
+
+ vec4 gx0 = ixy0 * (1.0 / 7.0);
+ vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
+ gx0 = fract(gx0);
+ vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
+ vec4 sz0 = step(gz0, vec4(0.0));
+ gx0 -= sz0 * (step(0.0, gx0) - 0.5);
+ gy0 -= sz0 * (step(0.0, gy0) - 0.5);
+
+ vec4 gx1 = ixy1 * (1.0 / 7.0);
+ vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
+ gx1 = fract(gx1);
+ vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
+ vec4 sz1 = step(gz1, vec4(0.0));
+ gx1 -= sz1 * (step(0.0, gx1) - 0.5);
+ gy1 -= sz1 * (step(0.0, gy1) - 0.5);
+
+ vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);
+ vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);
+ vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);
+ vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);
+ vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);
+ vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);
+ vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);
+ vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);
+
+ vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
+ g000 *= norm0.x;
+ g010 *= norm0.y;
+ g100 *= norm0.z;
+ g110 *= norm0.w;
+ vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
+ g001 *= norm1.x;
+ g011 *= norm1.y;
+ g101 *= norm1.z;
+ g111 *= norm1.w;
+
+ float n000 = dot(g000, Pf0);
+ float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));
+ float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));
+ float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));
+ float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));
+ float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));
+ float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));
+ float n111 = dot(g111, Pf1);
+
+ vec3 fade_xyz = fade(Pf0);
+ vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);
+ vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);
+ float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
+ return 2.2 * n_xyz;
+ }
+
+ // Classic Perlin noise, periodic variant
+ float pnoise(vec3 P, vec3 rep)
+ {
+ vec3 Pi0 = mod(floor(P), rep); // Integer part, modulo period
+ vec3 Pi1 = mod(Pi0 + vec3(1.0), rep); // Integer part + 1, mod period
+ Pi0 = mod289(Pi0);
+ Pi1 = mod289(Pi1);
+ vec3 Pf0 = fract(P); // Fractional part for interpolation
+ vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0
+ vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
+ vec4 iy = vec4(Pi0.yy, Pi1.yy);
+ vec4 iz0 = Pi0.zzzz;
+ vec4 iz1 = Pi1.zzzz;
+
+ vec4 ixy = permute(permute(ix) + iy);
+ vec4 ixy0 = permute(ixy + iz0);
+ vec4 ixy1 = permute(ixy + iz1);
+
+ vec4 gx0 = ixy0 * (1.0 / 7.0);
+ vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;
+ gx0 = fract(gx0);
+ vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);
+ vec4 sz0 = step(gz0, vec4(0.0));
+ gx0 -= sz0 * (step(0.0, gx0) - 0.5);
+ gy0 -= sz0 * (step(0.0, gy0) - 0.5);
+
+ vec4 gx1 = ixy1 * (1.0 / 7.0);
+ vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;
+ gx1 = fract(gx1);
+ vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);
+ vec4 sz1 = step(gz1, vec4(0.0));
+ gx1 -= sz1 * (step(0.0, gx1) - 0.5);
+ gy1 -= sz1 * (step(0.0, gy1) - 0.5);
+
+ vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);
+ vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);
+ vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);
+ vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);
+ vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);
+ vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);
+ vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);
+ vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);
+
+ vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));
+ g000 *= norm0.x;
+ g010 *= norm0.y;
+ g100 *= norm0.z;
+ g110 *= norm0.w;
+ vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));
+ g001 *= norm1.x;
+ g011 *= norm1.y;
+ g101 *= norm1.z;
+ g111 *= norm1.w;
+
+ float n000 = dot(g000, Pf0);
+ float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));
+ float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));
+ float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));
+ float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));
+ float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));
+ float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));
+ float n111 = dot(g111, Pf1);
+
+ vec3 fade_xyz = fade(Pf0);
+ vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);
+ vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);
+ float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);
+ return 2.2 * n_xyz;
+ }
void main() {
-
- vec4 mycolor,
- mc0 = texture2D(texture0,vUv), //Wasser
- mc1 = texture2D(texture1,vUv), //Sand
- mc2 = texture2D(texture2,vUv), //Gras
- mc3 = texture2D(texture3,vUv), //Fels
- mc4 = texture2D(texture4,vUv); //Schnee
- float wasserc=1.0,
- sandc=1.0,
- grasc=1.0,
- felsc=1.0,
- schneec=1.0;
-
+ float vNoise;
+
+ for(int i=0; i < frequenz; i++){
+ vNoise = cnoise(vec3(vUv.x,vUv.y,1.0)* persistence);
+ persistence *= persist;
+ }
+ vec4 mycolor;
+
+ float interpolate = vNoise+0.50;
+
+ if( vNoise < -0.1 ) { mycolor = texture2D(texture0, vUv ); }
+ if( vNoise < 0.0) { mycolor = (1.0 - interpolate) * texture2D(texture0,vUv ) + interpolate * texture2D(texture1,vUv ); }
+ if( vNoise >= 0.0 ) { mycolor = texture2D(texture1,vUv ); }
+ if( vNoise > 0.05 ) { mycolor = (1.0 - interpolate) * texture2D(texture1,vUv ) + interpolate * texture2D(texture2,vUv ); }
+ if( vNoise > 0.08 ) { mycolor = texture2D(texture2, vUv ); }
+ if( vNoise > 0.28 ) { mycolor = texture2D(texture3,vUv ); }
+ if( vNoise > 0.65 ) { mycolor = (1.0 - interpolate) * texture2D(texture3,vUv ) + interpolate * texture2D(texture4,vUv ); }
+ if( vNoise > 0.7 ) { mycolor = texture2D(texture4, vUv ); }
- if( vNoise < -0.1 ) { mycolor = mix(mc0,mc1,vNoise); } //wasser
- if( vNoise < 0.0) { mycolor = mix(mc0,mc1,vNoise); } //Wasser sand
- if( vNoise >= 0.0 ) { } //Sand
- if( vNoise > 0.05 ) { mycolor = mix(mc1,mc2,vNoise); } //Sand Gras
- if( vNoise > 0.08 ) { } //Gras
- if( vNoise > 0.28 ) { } //Fels
- if( vNoise > 0.65 ) { mycolor = mix(mc3,mc4,vNoise); } //Fels Schnee
- if( vNoise > 0.7 ) { } //Schnee
-
- mycolor = mix(mc0,mc1,vNoise);// + mc2 + mc3 + mc4;
+ //mycolor = mix(texture2D(texture2, vUv*100.0 ),texture2D(heightMap, vUv ),texture2D(heightMap, vUv )*1.8);
-
+
gl_FragColor = mycolor;
}
@@ -143,11 +296,13 @@
mouse = { X: 0, y: 0 },
scene = new THREE.Scene(),
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 1000000000000),
- light = new THREE.PointLight(0x8a4522, 3, 1000);
+ light = new THREE.PointLight(0xFFFFFF, 3, 1000);
scene.add(camera);
- renderer = new THREE.WebGLRenderer( { clearColor: 0x000000,antialias: true }); // CanvasRenderer();
+ renderer = new THREE.WebGLRenderer( { clearColor: 0x000000,
+ antialias: true
+ }); // CanvasRenderer();
renderer.setSize(window.innerWidth - 50, window.innerHeight - 50);
controls = new THREE.TrackballControls(camera);
@@ -162,15 +317,16 @@
controls.minDistance = 1.1;
controls.maxDistance = 2000000000000;
controls.keys = [65, 83, 68];
- controls.target = new THREE.Vector3(-20000,0,0);
+
// licht einschalten -----------------------
- light.position = new THREE.Vector3(0, 5, -5);
+ light.position = new THREE.Vector3(0, 0, 0);
+ light.castShadow = true;
scene.add(light);
- var ambilight = new THREE.AmbientLight(0xbbbbbb);
+ var ambilight = new THREE.AmbientLight(0xffffff);
scene.add(ambilight);
@@ -184,19 +340,18 @@
uniforms = {
- time: {type: "f", value: 0},
uscale: { type: "f", value: 100.0 },
ambientColor: { type: "vec3", value:(0.0,0.0,1.0) },
diffuseColor: { type: "vec3", value:(0.5,0.5,0.5) },
SpecularColor: { type: "vec", value:(0.5,0.5,0.5) },
shininess: { type: "f", value: 0.5 },
- scaleBias: { type: "vec2", value:(1.0,0.5) },
- texture0: { type: "t", value: 0, texture: THREE.ImageUtils.loadTexture( "images/wasser.PNG" ) },
- texture1: { type: "t", value: 1, texture: THREE.ImageUtils.loadTexture( "images/sand.PNG" ) },
- texture2: { type: "t", value: 2, texture: THREE.ImageUtils.loadTexture( "images/grass.PNG" ) },
- texture3: { type: "t", value: 3, texture: THREE.ImageUtils.loadTexture( "images/fels1.png" ) },
- texture4: { type: "t", value: 4, texture: THREE.ImageUtils.loadTexture( "images/schnee.PNG" ) },
- grass1: { type: "t", value: 5, texture: THREE.ImageUtils.loadTexture( "images/grass1.PNG" ) }
+ scaleBias: { type: "vec2", value: (1.0, 0.5) },
+ heightMap:{ type: "t", value: 0, texture: THREE.ImageUtils.loadTexture("images/hm.jpg") },
+ texture0: { type: "t", value: 1, texture: THREE.ImageUtils.loadTexture( "images/wasser.PNG" ) },
+ texture1: { type: "t", value: 2, texture: THREE.ImageUtils.loadTexture( "images/sand.PNG" ) },
+ texture2: { type: "t", value: 3, texture: THREE.ImageUtils.loadTexture( "images/grass.PNG" ) },
+ texture3: { type: "t", value: 4, texture: THREE.ImageUtils.loadTexture( "images/fels1.png" ) },
+ texture4: { type: "t", value: 5, texture: THREE.ImageUtils.loadTexture( "images/schnee.PNG" ) }
};
@@ -205,47 +360,107 @@
uniforms.texture2.texture.wrapS = uniforms.texture2.texture.wrapT = THREE.RepeatWrapping;
uniforms.texture3.texture.wrapS = uniforms.texture3.texture.wrapT = THREE.RepeatWrapping;
uniforms.texture4.texture.wrapS = uniforms.texture4.texture.wrapT = THREE.RepeatWrapping;
+ uniforms.heightMap.texture.wrapS = uniforms.heightMap.texture.wrapT = THREE.RepeatWrapping;
- camera.position.set(-20050,0,0)
+ camera.position.z = 851000;
+ //controls.target = new THREE.Vector3(851000, 0, 0);
-
var vShader = $("#vertexshader");
var fShader = $("#fragmentshader");
-
- scene.add(new THREE.Mesh(new THREE.OctahedronGeometry(20000,6),new THREE.ShaderMaterial({wireframe:false, uniforms: uniforms, vertexShader: vShader.text(), fragmentShader: fShader.text() }) ));
- //scene.add(new THREE.Mesh(new THREE.OctahedronGeometry(20000,6),new THREE.MeshBasicMaterial({color:0x0000ff, wireframe:true}) ));
- var cubegeo = new THREE.CubeGeometry(1,1,1,2,2,2),
- cubemat = new THREE.MeshBasicMaterial({}),
- cube = new THREE.Mesh(cubegeo,cubemat);
- scene.add(cube);
- cube.position.set(-20000.5,0,0);
- cube.scale.set(1,1,1);
+ var scale=80000, detail=4,
+
+ meshgeo = [[new THREE.IcosahedronGeometry(scale,detail), scale*1.5],
+ [new THREE.IcosahedronGeometry(scale,detail-1), scale*4],
+ [new THREE.IcosahedronGeometry(scale,detail-2), scale*8],
+ [new THREE.IcosahedronGeometry(scale,detail-3), scale*15],
+ [new THREE.IcosahedronGeometry(scale,detail-3), scale*20],
+ [new THREE.IcosahedronGeometry(scale,detail-3), scale*25]
+ ],
+ meshmat=new THREE.ShaderMaterial({ wireframe: false, smooth: true, uniforms: uniforms, vertexShader: vShader.text(), fragmentShader: fShader.text() });
+
+ var lod1 = new THREE.LOD(),
+ lod2 = new THREE.LOD(),
+ lod3 = new THREE.LOD(),
+ lod4 = new THREE.LOD(),
+ lod5 = new THREE.LOD();
- var size = 1.51, length = 60000,pfeilgroese = 5000;
-
- function v(x,y,z){
- return new THREE.Vertex(new THREE.Vector3(x,y,z));
- }
+
- var lineGeor = new THREE.Geometry(),
- lineGeog = new THREE.Geometry(),
- lineGeob = new THREE.Geometry();
+ for (i = 0; i < meshgeo.length; i++) {
+
- lineGeor.vertices.push(v(-length, 0, 0), v(length, 0, 0),v(length-pfeilgroese, 0, pfeilgroese),v(length-pfeilgroese, 0, -pfeilgroese),v(length, 0, 0) );
- lineGeog.vertices.push(v(0, -length, 0), v(0, length, 0) );
- lineGeob.vertices.push(v(0, 0, -length), v(0, 0, length) );
+ var mesh1 = new THREE.Mesh(meshgeo[i][0], meshmat);
+ var mesh2 = new THREE.Mesh(meshgeo[i][0], meshmat);
+ var mesh3 = new THREE.Mesh(meshgeo[i][0], meshmat);
+ var mesh4 = new THREE.Mesh(meshgeo[i][0], meshmat);
+ var mesh5 = new THREE.Mesh(meshgeo[i][0], meshmat);
+
+
+ lod2.position = new THREE.Vector3(scale*3, 0, 0);
+ lod3.position = new THREE.Vector3(-scale*3, 0, 0);
+ lod4.position = new THREE.Vector3(0, scale*3, 0);
+ lod5.position = new THREE.Vector3(0, -scale*3, 0);
+
+ lod1.addLevel(mesh1, meshgeo[i][1]);
+ lod2.addLevel(mesh2, meshgeo[i][1]);
+ lod3.addLevel(mesh3, meshgeo[i][1]);
+ lod4.addLevel(mesh4, meshgeo[i][1]);
+ lod5.addLevel(mesh5, meshgeo[i][1]);
+
+ }
+ scene.add(lod1);
+ scene.add(lod2);
+ scene.add(lod3);
+ scene.add(lod4);
+ scene.add(lod5);
- var lineMatr = new THREE.LineBasicMaterial({color: 0xff0000, lineWidth: size});
- var lineMatg = new THREE.LineBasicMaterial({color: 0x00ff00, lineWidth: size});
- var lineMatb = new THREE.LineBasicMaterial({color: 0x0000ff, lineWidth: size});
+ var debugaxis = function (axisLength) {
+ //Shorten the vertex function
+ function v(x, y, z) {
+ return new THREE.Vector3(x, y, z);
+ }
+
+ //Create axis (point1, point2, colour)
+ function createAxis(p1, p2, color) {
+ var line, lineGeometry = new THREE.Geometry(),
+ lineMat = new THREE.LineBasicMaterial({ color: color, lineWidth: 1 });
+ lineGeometry.vertices.push(p1, p2);
+ line = new THREE.Line(lineGeometry, lineMat);
+ scene.add(line);
+ }
+
+ createAxis(v(-axisLength, 0, 0), v(axisLength, 0, 0), 0xFF0000);
+ createAxis(v(0, -axisLength, 0), v(0, axisLength, 0), 0x00FF00);
+ createAxis(v(0, 0, -axisLength), v(0, 0, axisLength), 0x0000FF);
+ };
+
+ debugaxis(500000);
+
+
+ function v(x, y, z) {
+ return new THREE.Vector3(x, y, z);
+ }
+
+ var line, linegeometry = new THREE.Geometry(),
+ linemat = new THREE.LineBasicMaterial({color: 0xaaaaaa, linewidth: 1});
+
+ var radius=200000,winkel = 0;
+ for (i = 0; i <= 360; i+=5) {
+
+ linegeometry.vertices.push(v(Math.cos( i * Math.PI/180)* radius, Math.sin(i * Math.PI/180) * radius, 0));
+
+ }
- var liner = new THREE.Line(lineGeor, lineMatr),
- lineg = new THREE.Line(lineGeog, lineMatg),
- lineb = new THREE.Line(lineGeob, lineMatb);
-
- // line.type = THREE.Lines;
- scene.add(liner);scene.add(lineg);scene.add(lineb);
+ line = new THREE.Line(linegeometry, linemat);
+ scene.add(line);
+
+ var meshGeom = new THREE.SphereGeometry(3000,8,8), meshMater = new THREE.MeshBasicMaterial({color:0xff0000});
+ mesh = new THREE.Mesh(meshGeom, meshmat);
+ mesh.position = new THREE.Vector3(Math.sin(90) * radius, Math.cos(90) * radius, 0);
+ scene.add(mesh);
+ //mesh.add(camera);
+
//################### Kamera Steuerung #####################################
@@ -266,17 +481,15 @@
//document.addEventListener("mousemove", CameraControllMouseMove, false);
//document.addEventListener("mousedown", CameraControlMouseDown, false);
- //document.addEventListener("mouseup", CameraControlMouseUp, false);
+ document.addEventListener("mouseup", CameraControlMouseUp, false);
//window.addEventListener('DOMMouseScroll', CameraControlMouseWheel, false);
var moveto = 0;
function CameraControllMouseMove(event) {
event.preventDefault();
-
-
if (MouseDown === 1) {
-
+
moveto = 1;
window.mouse.X = ((event.clientX/ window.innerWidth) * 2 - 1);
@@ -301,7 +514,7 @@
event.preventDefault();
if(event.button === 1){
MouseDown = 0;
-
+
}
}
function CameraControlMouseWheel(event) {
@@ -317,90 +530,47 @@
function initalize() {
//ui();
-
+
document.body.appendChild(renderer.domElement);
animate();
}
- var winkel = 0;
+
function animate() {
-
+
requestAnimationFrame(animate);
-
- winkel = (winkel+1) % 360
- var time = parseFloat(Date.now());
- uniforms.time.value = winkel;
- $("#mouse").text(winkel);
uniforms.uscale.value = camera.position.distanceTo(new THREE.Vector3(0,0,0));
render();
}
-
+ var winkel = 0,rendern=0;
function render() {
+ var time = Date.now() * 0.005;
+ winkel = (winkel + 1.536) % 360;
+ lod1.rotation = new THREE.Vector3(Math.cos(winkel* Math.PI / 180), Math.sin(winkel* Math.PI / 180), 0);
+ mesh.position = new THREE.Vector3(Math.cos(winkel * Math.PI / 180) * radius, Math.sin(winkel * Math.PI / 180) * radius, 0);
+
+ THREE.SceneUtils.traverseHierarchy(scene, function (node) { if (node instanceof THREE.LOD) node.update(camera) });
-
- //camera.position.x += 0.1;
- // camera.lookAt(CameraTarget);
- //particleSystem.rotation.y -= 0.00051 % 360
-
-
- if (moveto == 1) {
-
- if (camera.position.distanceTo(new THREE.Vector3(0, 0, 10000000)) <= 10) {
-
- //moveto = 0;
- }
- else {
- //camera.translateZ(-camera.position.distanceTo(new THREE.Vector3(0, 0, 3000000000))/5 );
- }
-
- }
-
controls.update();
-
+
renderer.clear();
renderer.render(scene, camera);
+
}
</script>
- <script type="text/javascript" >
-
- function ui() {
-
- $("#button").click(function () {
-
- var PSpiralForm = parseFloat($("#spiralForm").val()),
- PRauschen = parseFloat($("#rauschen").val()),
- PSchritweite = parseFloat($("#schritweiteEntfernung").val()),
- PEntfernung = parseFloat($("#entfernung").val()),
- PSpiralarmabstand = parseFloat($("#spiralabstand").val()),
- PAnzahlParticle = parseFloat($("#AnzahlParticle").val());
-
- createGalaxy(PSpiralForm, PRauschen, PSchritweite, PEntfernung, PSpiralarmabstand, PAnzahlParticle);
- });
- }
- </script>
+
</head>
- <body onload="initalize();" >
- <div style="position:absolute;background:#dcdcdc;width:200px;visibility:visible" id="mouse" >
- <!--
- <input type=text value="0.021" id="spiralForm" /> SpiralForm
- <input type=text value="0.2" id="rauschen" /> Rauschen
- <input type=text value="1" id="schritweiteEntfernung" /> Schritweite
- <input type=text value="50000000" id="entfernung" /> Entfernung
- <input type=text value="0.225" id="spiralabstand" /> Spiralarmabstand
- <input type=text value="26007" id="AnzahlParticle" /> AnzahlParticle
- <input type="button" id="button" value="los" />
- -->
-
- </div>
+ <body onload="initalize();">
+
</body >
-</html>
+</html>

0 comments on commit 796d186

Please sign in to comment.
Something went wrong with that request. Please try again.