Skip to content
This repository
Browse code

Merge branch 'master' of https://github.com/Enigmadt/shader-example.git

  • Loading branch information...
commit 403051a2c96a57f415e95d65a15cc9adc3b2d720 2 parents 525fa61 + 6def359
authored April 24, 2012
68  Waterworld example/Scripts/Shader/fragmentShader.fs
... ...
@@ -0,0 +1,68 @@
  1
+varying vec3 vNormal;
  2
+varying vec3 vPosition;
  3
+varying float vNoise;
  4
+varying vec2 vUv;
  5
+uniform sampler2D texture0;
  6
+uniform sampler2D texture1;
  7
+uniform sampler2D texture2;
  8
+uniform sampler2D texture3;
  9
+uniform sampler2D texture4;
  10
+uniform sampler2D grass1;
  11
+
  12
+varying vec3 tsPosition;
  13
+varying vec3 tsCameraPosition;
  14
+varying vec3 tsLightSource;
  15
+varying float time1;
  16
+
  17
+uniform vec3 ambientColor; // color of ambient light
  18
+uniform vec3 diffuseColor; // color of diffuse lighting
  19
+uniform vec3 specularColor; // color of specular highlights
  20
+uniform float shininess; // how shiny the surface is
  21
+uniform vec2 scaleBias; // x = scale, y = bias
  22
+
  23
+void main()
  24
+{
  25
+   vec4 mycolor,
  26
+   mc0 = texture2D(texture0,vUv), // Wasser.
  27
+   mc1 = texture2D(texture1,vUv), // Sand.
  28
+   mc2 = texture2D(texture2,vUv), // Gras.
  29
+   mc3 = texture2D(texture3,vUv), // Fels.
  30
+   mc4 = texture2D(texture4,vUv); // Schnee.
  31
+   float wasserc = 1.0,
  32
+   sandc = 1.0,
  33
+   grasc = 1.0,
  34
+   felsc = 1.0,
  35
+   schneec = 1.0;
  36
+    
  37
+   // Wasser.
  38
+   if(vNoise < -0.1)
  39
+   {
  40
+      mycolor = mix(mc0, mc1, vNoise);
  41
+   }
  42
+   // Wasser-Sand.
  43
+   if(vNoise < 0.0)
  44
+   {
  45
+      mycolor = mix(mc0,mc1,vNoise);
  46
+   }
  47
+   // Sand.
  48
+   if(vNoise >= 0.0){}
  49
+   // Sand-Gras.
  50
+   if(vNoise > 0.05)
  51
+   {
  52
+      mycolor = mix(mc1,mc2,vNoise);
  53
+   }
  54
+   // Gras.
  55
+   if(vNoise > 0.08){}
  56
+   // Fels.
  57
+   if(vNoise > 0.28){}
  58
+   // Fels Schnee.
  59
+   if(vNoise > 0.65)
  60
+   {
  61
+      mycolor = mix(mc3, mc4, vNoise);
  62
+   }
  63
+   // Schnee.
  64
+   if(vNoise > 0.7){}
  65
+
  66
+   mycolor = mix(mc0, mc1, vNoise);// + mc2 + mc3 + mc4; 	
  67
+   gl_FragColor = mycolor;
  68
+}
59  Waterworld example/Scripts/Shader/vertexShader.vs
... ...
@@ -0,0 +1,59 @@
  1
+varying vec3 vNormal;
  2
+varying vec3 vPosition;
  3
+varying float vNoise;
  4
+varying vec3 vTangent;
  5
+varying vec3 vBinormal;
  6
+
  7
+varying vec3 tsPosition;
  8
+varying vec3 tsCameraPosition;
  9
+varying vec3 tsLightSource;
  10
+
  11
+//attribute vec3 normal;
  12
+attribute vec4 tangent;
  13
+attribute vec2 texCoord;
  14
+
  15
+varying vec2 vUv;
  16
+varying float time1;
  17
+
  18
+uniform sampler2D texture0;
  19
+uniform sampler2D texture1;
  20
+uniform sampler2D texture2;
  21
+uniform sampler2D texture3;
  22
+uniform sampler2D texture4;
  23
+uniform float uscale;
  24
+uniform float time;
  25
+
  26
+
  27
+const float persist = 0.0565;
  28
+float persistence = 1.0;
  29
+const int oktave = 4;
  30
+float h = 0.0;
  31
+
  32
+vec4 gpuGetCell3D(float x, const float y, float z)
  33
+{
  34
+   float u = (x + y * 31.0) / 256.0;
  35
+   float v = (z - x * 31.0) / 256.0;
  36
+   
  37
+    return (texture2D(texture0, vec2(u,v)));
  38
+}
  39
+
  40
+void main()
  41
+{
  42
+   vNormal = normal;
  43
+   vUv = uv * 8000.0;
  44
+   vPosition = position;
  45
+   time1 = time;
  46
+
  47
+   float noise = -1.0, temp=3000.0;
  48
+
  49
+   vNoise = noise;
  50
+   vec3 noisefaktor = vec3(noise * 0.0515);
  51
+
  52
+   if(noise < 0.0)
  53
+   {
  54
+       noisefaktor = vec3(0.0);
  55
+   }
  56
+
  57
+   vec3 newPosition = position + normal * noisefaktor;
  58
+   gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition,1.0 );
  59
+}
288  Waterworld example/example1.html
@@ -6,164 +6,140 @@
6 6
   <meta charset="utf-8">
7 7
  
8 8
   <link rel="stylesheet" type="text/css" href="Content/styles.css" />
  9
+  
  10
+  <script type="x-shader/x-vertex" id="vertexshader" src="Scripts/Shader/vertexShader.js">
  11
+   varying vec3 vNormal;
  12
+   varying vec3 vPosition;
  13
+   varying float vNoise;
  14
+   varying vec3 vTangent;
  15
+   varying vec3 vBinormal;
  16
+
  17
+   varying vec3 tsPosition;
  18
+   varying vec3 tsCameraPosition;
  19
+   varying vec3 tsLightSource;
  20
+
  21
+   //attribute vec3 normal;
  22
+   attribute vec4 tangent;
  23
+   attribute vec2 texCoord;
  24
+
  25
+   varying vec2 vUv;
  26
+   varying float time1;
  27
+
  28
+   uniform sampler2D texture0;
  29
+   uniform sampler2D texture1;
  30
+   uniform sampler2D texture2;
  31
+   uniform sampler2D texture3;
  32
+   uniform sampler2D texture4;
  33
+   uniform float uscale;
  34
+   uniform float time;
  35
+
  36
+   const float persist = 0.0565;
  37
+   float persistence = 1.0;
  38
+   const int oktave = 4;
  39
+   float h = 0.0;
  40
+
  41
+   vec4 gpuGetCell3D(float x, const float y, float z)
  42
+   {
  43
+      float u = (x + y * 31.0) / 256.0;
  44
+      float v = (z - x * 31.0) / 256.0;
  45
+   
  46
+       return (texture2D(texture0, vec2(u,v)));
  47
+   }
  48
+
  49
+   void main()
  50
+   {
  51
+      vNormal = normal;
  52
+      vUv = uv * 8000.0;
  53
+      vPosition = position;
  54
+      time1 = time;
  55
+
  56
+      float noise = -1.0, temp=3000.0;
  57
+
  58
+      vNoise = noise;
  59
+      vec3 noisefaktor = vec3(noise * 0.0515);
  60
+
  61
+      if(noise < 0.0)
  62
+      {
  63
+         noisefaktor = vec3(0.0);
  64
+      }
  65
+
  66
+      vec3 newPosition = position + normal * noisefaktor;
  67
+      gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition,1.0 );
  68
+   }
  69
+  </script>
  70
+  <script type="x-shader/x-fragment" id="fragmentshader">
  71
+   varying vec3 vNormal;
  72
+   varying vec3 vPosition;
  73
+   varying float vNoise;
  74
+   varying vec2 vUv;
  75
+   uniform sampler2D texture0;
  76
+   uniform sampler2D texture1;
  77
+   uniform sampler2D texture2;
  78
+   uniform sampler2D texture3;
  79
+   uniform sampler2D texture4;
  80
+   uniform sampler2D grass1;
  81
+
  82
+   varying vec3 tsPosition;
  83
+   varying vec3 tsCameraPosition;
  84
+   varying vec3 tsLightSource;
  85
+   varying float time1;
  86
+
  87
+   uniform vec3 ambientColor; // color of ambient light
  88
+   uniform vec3 diffuseColor; // color of diffuse lighting
  89
+   uniform vec3 specularColor; // color of specular highlights
  90
+   uniform float shininess; // how shiny the surface is
  91
+   uniform vec2 scaleBias; // x = scale, y = bias
  92
+
  93
+   void main()
  94
+   {
  95
+      vec4 mycolor,
  96
+      mc0 = texture2D(texture0,vUv), // Wasser.
  97
+      mc1 = texture2D(texture1,vUv), // Sand.
  98
+      mc2 = texture2D(texture2,vUv), // Gras.
  99
+      mc3 = texture2D(texture3,vUv), // Fels.
  100
+      mc4 = texture2D(texture4,vUv); // Schnee.
  101
+      float wasserc = 1.0,
  102
+      sandc = 1.0,
  103
+      grasc = 1.0,
  104
+      felsc = 1.0,
  105
+      schneec = 1.0;
  106
+    
  107
+      // Wasser.
  108
+      if(vNoise < -0.1)
  109
+      {
  110
+         mycolor = mix(mc0, mc1, vNoise);
  111
+      }
  112
+      // Wasser-Sand.
  113
+      if(vNoise < 0.0)
  114
+      {
  115
+         mycolor = mix(mc0, mc1, vNoise);
  116
+      }
  117
+      // Sand.
  118
+      if(vNoise >= 0.0){}
  119
+      // Sand-Gras.
  120
+      if(vNoise > 0.05)
  121
+      {
  122
+         mycolor = mix(mc1,mc2,vNoise);
  123
+      }
  124
+      // Gras.
  125
+      if(vNoise > 0.08){}
  126
+      // Fels.
  127
+      if(vNoise > 0.28){}
  128
+      // Fels Schnee.
  129
+      if(vNoise > 0.65)
  130
+      {
  131
+         mycolor = mix(mc3, mc4, vNoise);
  132
+      }
  133
+      // Schnee.
  134
+      if(vNoise > 0.7){}
  135
+
  136
+      mycolor = mix(mc0, mc1, vNoise);// + mc2 + mc3 + mc4;     
  137
+      gl_FragColor = mycolor;
  138
+   }
  139
+  </script>
9 140
  </head>        
10  
-        
11  
-       <script type="x-shader/x-vertex" id="vertexshader">
12  
-
13  
-            varying vec3 vNormal;
14  
-            varying vec3 vPosition;
15  
-            varying float vNoise;
16  
-            varying vec3 vTangent;
17  
-            varying vec3 vBinormal;
18  
- 
19  
-            varying vec3 tsPosition;
20  
-            varying vec3 tsCameraPosition;
21  
-            varying vec3 tsLightSource;
22  
-
23  
-            //attribute vec3 normal;
24  
-            attribute vec4 tangent;
25  
-            attribute vec2 texCoord;
26  
-
27  
-            varying vec2 vUv;
28  
-            varying float time1;
29  
-            
30  
-            uniform sampler2D texture0;
31  
-            uniform sampler2D texture1;
32  
-            uniform sampler2D texture2;
33  
-            uniform sampler2D texture3;
34  
-            uniform sampler2D texture4;
35  
-            uniform float uscale;
36  
-            uniform float time;
37  
-
38  
-
39  
-            const float persist = 0.0565;
40  
-            float persistence = 1.0;
41  
-            const int oktave = 4;
42  
-            float h = 0.0;
43  
-
44  
-            vec4 gpuGetCell3D(float x, const float y, float z)
45  
-            {
46  
-                float u = (x + y * 31.0) / 256.0;
47  
-                float v = (z - x * 31.0) / 256.0;
48  
-                return (texture2D(texture0, vec2(u,v)));
49  
-            }
50  
-            
51  
-            
52  
-     
53  
-
54  
-            void main() {
55  
-                
56  
-                vNormal = normal;
57  
-                vUv = uv*8000.0;
58  
-                vPosition = position;
59  
-                time1 = time;
60  
-
61  
-                
62  
-                float noise,temp=3000.0;
63  
-                
64  
-                noise = -1.0;
65  
-                
66  
-          
67  
-                vNoise = noise;
68  
-                vec3 noisefaktor = vec3(noise*0.0515);
69  
-                if(noise < 0.0) {noisefaktor = vec3(0.0); }
70  
-                
71  
-                vec3 newPosition = position + normal * noisefaktor;
72  
-                gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition,1.0 );
73  
-
74  
-                
75  
-
76  
-            }
77  
-
78  
-        </script>
79  
-
80  
-       <script type="x-shader/x-fragment" id="fragmentshader">
81  
-        
82  
-            varying vec3 vNormal;
83  
-            varying vec3 vPosition;
84  
-            varying float vNoise;
85  
-            varying vec2 vUv;
86  
-            uniform sampler2D texture0;
87  
-            uniform sampler2D texture1;
88  
-            uniform sampler2D texture2;
89  
-            uniform sampler2D texture3;
90  
-            uniform sampler2D texture4;
91  
-            uniform sampler2D grass1;
92  
-
93  
-            varying vec3 tsPosition;
94  
-            varying vec3 tsCameraPosition;
95  
-            varying vec3 tsLightSource;
96  
-            varying float time1;
97  
-
98  
-            uniform vec3 ambientColor; // color of ambient light
99  
-            uniform vec3 diffuseColor; // color of diffuse lighting
100  
-            uniform vec3 specularColor; // color of specular highlights
101  
-            uniform float shininess; // how shiny the surface is
102  
-            uniform vec2 scaleBias; // x = scale, y = bias
103  
-
104  
-            void main() {
105  
-
106  
-                vec4 mycolor,
107  
-                    mc0 = texture2D(texture0,vUv), //Wasser
108  
-                    mc1 = texture2D(texture1,vUv), //Sand
109  
-                    mc2 = texture2D(texture2,vUv), //Gras
110  
-                    mc3 = texture2D(texture3,vUv), //Fels
111  
-                    mc4 = texture2D(texture4,vUv); //Schnee
112  
-                 float   wasserc=1.0,
113  
-                    sandc=1.0,
114  
-                    grasc=1.0,
115  
-                    felsc=1.0,
116  
-                    schneec=1.0;
117  
-                    
118  
-                
119  
-
120  
-                if( vNoise < -0.1 ) { mycolor = mix(mc0,mc1,vNoise); } //wasser
121  
-                if( vNoise < 0.0)   { mycolor = mix(mc0,mc1,vNoise); } //Wasser sand
122  
-                if( vNoise >= 0.0 ) {  } //Sand
123  
-                if( vNoise > 0.05 ) { mycolor = mix(mc1,mc2,vNoise); } //Sand Gras
124  
-                if( vNoise > 0.08 ) {  } //Gras
125  
-                if( vNoise > 0.28 ) {  } //Fels
126  
-                if( vNoise > 0.65 ) { mycolor = mix(mc3,mc4,vNoise); } //Fels Schnee
127  
-                if( vNoise > 0.7 )  {  } //Schnee
128  
-                
129  
-                mycolor = mix(mc0,mc1,vNoise);// + mc2 + mc3 + mc4;
130  
-                
131  
-		
132  
-                gl_FragColor = mycolor;
133  
-            }
134  
-
135  
-        </script>
136  
-
137  
-        <!--<script type="text/javascript" >
138  
-
139  
-            function ui() {
140  
-
141  
-                $("#button").click(function () {
142  
-
143  
-                    var PSpiralForm = parseFloat($("#spiralForm").val()),
144  
-                        PRauschen = parseFloat($("#rauschen").val()),
145  
-                        PSchritweite = parseFloat($("#schritweiteEntfernung").val()),
146  
-                        PEntfernung = parseFloat($("#entfernung").val()),
147  
-                        PSpiralarmabstand = parseFloat($("#spiralabstand").val()),
148  
-                        PAnzahlParticle = parseFloat($("#AnzahlParticle").val());
149  
-
150  
-                    createGalaxy(PSpiralForm, PRauschen, PSchritweite, PEntfernung, PSpiralarmabstand, PAnzahlParticle);
151  
-                });
152  
-            }
153  
-        </script>-->
154  
-        
  141
+
155 142
  <body onload="initalize();">
156  
-  <!--<div style="position:absolute;background:#dcdcdc;width:200px;visibility:visible" id="mouse">
157  
-     
158  
-        <input type=text value="0.021" id="spiralForm" /> SpiralForm
159  
-        <input type=text value="0.2" id="rauschen" /> Rauschen
160  
-        <input type=text value="1" id="schritweiteEntfernung" /> Schritweite
161  
-        <input type=text value="50000000" id="entfernung" /> Entfernung
162  
-        <input type=text value="0.225" id="spiralabstand" /> Spiralarmabstand
163  
-        <input type=text value="26007" id="AnzahlParticle" /> AnzahlParticle
164  
-        <input type="button" id="button" value="los" />
165  
-  </div> -->
166  
-  
167 143
   <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" ></script>
168 144
   <script type="text/javascript" src="Scripts/three.js"></script>
169 145
   <script type="text/javascript" src="Scripts/functions.js"></script>

0 notes on commit 403051a

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