Selaa lähdekoodia

添加各类材质

tags/1.0.0
Caven 5 vuotta sitten
vanhempi
commit
a1d1413686

+ 1
- 20
src/plugins/material/DC.PolylineEmissionMaterialProperty.js Näytä tiedosto

@@ -2,12 +2,10 @@
* @Author: Caven
* @Date: 2020-02-26 10:15:55
* @Last Modified by: Caven
* @Last Modified time: 2020-02-26 22:43:40
* @Last Modified time: 2020-02-26 23:39:38
*/
import Cesium from '@/namespace'

let LineEmissionShader = require('../shader/PolylineEmissionShader.glsl')

DC.PolylineEmissionMaterialProperty = class {
constructor(options) {
options = options || {}
@@ -52,20 +50,3 @@ DC.PolylineEmissionMaterialProperty = class {
Cesium.defineProperties(DC.PolylineEmissionMaterialProperty.prototype, {
color: Cesium.createPropertyDescriptor('color')
})

Cesium.Material.PolylineEmissionType = 'PolylineEmission'
Cesium.Material._materialCache.addMaterial(
Cesium.Material.PolylineEmissionType,
{
fabric: {
type: Cesium.Material.PolylineEmissionType,
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 0.7)
},
source: LineEmissionShader
},
translucent: function(material) {
return true
}
}
)

+ 1
- 18
src/plugins/material/DC.PolylineFlowMaterialProperty.js Näytä tiedosto

@@ -2,13 +2,11 @@
* @Author: Caven
* @Date: 2020-02-24 13:53:52
* @Last Modified by: Caven
* @Last Modified time: 2020-02-26 22:43:52
* @Last Modified time: 2020-02-26 23:52:52
*/

import Cesium from '@/namespace'

let LineFlowShader = require('../shader/PolylineFlowShader.glsl')

DC.PolylineFlowMaterialProperty = class {
constructor(options) {
options = options || {}
@@ -63,18 +61,3 @@ Cesium.defineProperties(DC.PolylineFlowMaterialProperty.prototype, {
color: Cesium.createPropertyDescriptor('color'),
duration: Cesium.createPropertyDescriptor('duration')
})

Cesium.Material.PolylineFlowType = 'PolylineFlow'
Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineFlowType, {
fabric: {
type: Cesium.Material.PolylineFlowType,
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 0.7),
duration: 45
},
source: LineFlowShader
},
translucent: function(material) {
return true
}
})

+ 1
- 22
src/plugins/material/DC.PolylineTrailMaterialProperty.js Näytä tiedosto

@@ -2,16 +2,11 @@
* @Author: Caven
* @Date: 2020-02-24 13:09:09
* @Last Modified by: Caven
* @Last Modified time: 2020-02-26 22:43:55
* @Last Modified time: 2020-02-26 23:53:43
*/

import Cesium from '@/namespace'

const IMG =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAAgCAYAAABkS8DlAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAADSSURBVHja7NYxEoUgDEDBYM39z2qHtZViwMFxt1FJnF/98ZXWWkRE7LWWOOt5Lsm9q/vsbu9Zdtazs/J19O5bs1XPZrwze/6V31zxbOZs1n905Wt2p3f25GzE7ohv6q3nLQCA3xEAACAAAAABAAAIAABAAAAAAgAAEAAAgAAAAAQAACAAAAABAAAIAABAAAAAAgAAEAAAgAAAAAQAACAAAEAAAAACAAAQAACAAAAABAAAIAAAAAEAAAgAAEAAAAACAAAQAACAAAAA8g4AAAD//wMA4WEFTJOT5UIAAAAASUVORK5CYII='

let LineTrailShader = require('../shader/PolylineTrailShader.glsl')

DC.PolylineTrailMaterialProperty = class {
constructor(options) {
options = options || {}
@@ -66,19 +61,3 @@ Cesium.defineProperties(DC.PolylineTrailMaterialProperty.prototype, {
color: Cesium.createPropertyDescriptor('color'),
duration: Cesium.createPropertyDescriptor('duration')
})

Cesium.Material.PolylineTrailType = 'PolylineTrail'
Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineTrailType, {
fabric: {
type: Cesium.Material.PolylineTrailType,
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 0.7),
image: IMG,
duration: 45
},
source: LineTrailShader
},
translucent: function(material) {
return true
}
})

+ 1
- 1
src/plugins/material/DC.RimLightingMaterialProperty.js Näytä tiedosto

@@ -2,7 +2,7 @@
* @Author: Caven
* @Date: 2020-02-25 22:49:56
* @Last Modified by: Caven
* @Last Modified time: 2020-02-26 22:44:11
* @Last Modified time: 2020-02-26 23:54:20
*/

import Cesium from '@/namespace'

+ 1
- 1
src/plugins/material/DC.WaterMaterialProperty.js Näytä tiedosto

@@ -2,7 +2,7 @@
* @Author: Caven
* @Date: 2020-02-25 21:16:00
* @Last Modified by: Caven
* @Last Modified time: 2020-02-25 23:14:25
* @Last Modified time: 2020-02-26 23:54:21
*/
import Cesium from '@/namespace'


+ 2
- 2
src/plugins/material/index.js Näytä tiedosto

@@ -2,9 +2,9 @@
* @Author: Caven
* @Date: 2020-02-24 13:28:37
* @Last Modified by: Caven
* @Last Modified time: 2020-02-26 10:19:38
* @Last Modified time: 2020-02-26 23:39:34
*/
import './material'
import './DC.PolylineTrailMaterialProperty'
import './DC.PolylineFlowMaterialProperty'
import './DC.PolylineEmissionMaterialProperty'

+ 295
- 0
src/plugins/material/material.js Näytä tiedosto

@@ -0,0 +1,295 @@
/*
* @Author: Caven
* @Date: 2020-02-26 23:38:41
* @Last Modified by: Caven
* @Last Modified time: 2020-02-27 00:20:29
*/
import Cesium from '@/namespace'

const IMG =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAAgCAYAAABkS8DlAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAIGNIUk0AAHolAACAgwAA+f8AAIDpAAB1MAAA6mAAADqYAAAXb5JfxUYAAADSSURBVHja7NYxEoUgDEDBYM39z2qHtZViwMFxt1FJnF/98ZXWWkRE7LWWOOt5Lsm9q/vsbu9Zdtazs/J19O5bs1XPZrwze/6V31zxbOZs1n905Wt2p3f25GzE7ohv6q3nLQCA3xEAACAAAAABAAAIAABAAAAAAgAAEAAAgAAAAAQAACAAAAABAAAIAABAAAAAAgAAEAAAgAAAAAQAACAAAEAAAAACAAAQAACAAAAABAAAIAAAAAEAAAgAAEAAAAACAAAQAACAAAAA8g4AAAD//wMA4WEFTJOT5UIAAAAASUVORK5CYII='

let LineEmissionMaterial = require('../shader/PolylineEmissionMaterial.glsl')
let LineFlowMaterial = require('../shader/PolylineFlowMaterial.glsl')
let LineTrailMaterial = require('../shader/PolylineTrailMaterial.glsl')
let czm_cellular = require('../shader/cellular.glsl')
let czm_snoise = require('../shader/snoise.glsl')
let AsphaltMaterial = require('../shader/AsphaltMaterial.glsl')
let BlobMaterial = require('../shader/BlobMaterial.glsl')
let BrickMaterial = require('../shader/BlobMaterial.glsl')
let CementMaterial = require('../shader/CementMaterial.glsl')
let ErosionMaterial = require('../shader/ErosionMaterial.glsl')
let FacetMaterial = require('../shader/FacetMaterial.glsl')
let FresnelMaterial = require('../shader/FresnelMaterial.glsl')
let GrassMaterial = require('../shader/GrassMaterial.glsl')
let ReflectionMaterial = require('../shader/ReflectionMaterial.glsl')
let RefractionMaterial = require('../shader/RefractionMaterial.glsl')
let TieDyeMaterial = require('../shader/TieDyeMaterial.glsl')
let WoodMaterial = require('../shader/WoodMaterial.glsl')

Cesium.ShaderSource._czmBuiltinsAndUniforms.czm_cellular = czm_cellular
Cesium.ShaderSource._czmBuiltinsAndUniforms.czm_snoise = czm_snoise

// PolylineEmission

Cesium.Material.PolylineEmissionType = 'PolylineEmission'
Cesium.Material._materialCache.addMaterial(
Cesium.Material.PolylineEmissionType,
{
fabric: {
type: Cesium.Material.PolylineEmissionType,
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 0.7)
},
source: LineEmissionMaterial
},
translucent: function(material) {
return true
}
}
)

// PolylineFlow
Cesium.Material.PolylineFlowType = 'PolylineFlow'
Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineFlowType, {
fabric: {
type: Cesium.Material.PolylineFlowType,
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 0.7),
duration: 45
},
source: LineFlowMaterial
},
translucent: function(material) {
return true
}
})

// PolylineTrail
Cesium.Material.PolylineTrailType = 'PolylineTrail'
Cesium.Material._materialCache.addMaterial(Cesium.Material.PolylineTrailType, {
fabric: {
type: Cesium.Material.PolylineTrailType,
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 0.7),
image: IMG,
duration: 45
},
source: LineTrailMaterial
},
translucent: function(material) {
return true
}
})

// Asphalt
Cesium.Material.AsphaltType = 'Asphalt'
Cesium.Material._materialCache.addMaterial(Cesium.Material.AsphaltType, {
fabric: {
type: Cesium.Material.AsphaltType,
uniforms: {
asphaltColor: new Cesium.Color(0.15, 0.15, 0.15, 1.0),
bumpSize: 0.02,
roughness: 0.2
},
source: AsphaltMaterial
},
translucent: function(material) {
return material.uniforms.asphaltColor.alpha < 1.0
}
})

// Blob
Cesium.Material.BlobType = 'Blob'
Cesium.Material._materialCache.addMaterial(Cesium.Material.BlobType, {
fabric: {
type: Cesium.Material.BlobType,
uniforms: {
lightColor: new Cesium.Color(1.0, 1.0, 1.0, 0.5),
darkColor: new Cesium.Color(0.0, 0.0, 1.0, 0.5),
frequency: 10.0
},
source: BlobMaterial
},
translucent: function(material) {
var uniforms = material.uniforms
return uniforms.lightColor.alpha < 1.0 || uniforms.darkColor.alpha < 0.0
}
})

// Brick
Cesium.Material.BrickType = 'Brick'
Cesium.Material._materialCache.addMaterial(Cesium.Material.BrickType, {
fabric: {
type: Cesium.Material.BrickType,
uniforms: {
brickColor: new Cesium.Color(0.6, 0.3, 0.1, 1.0),
mortarColor: new Cesium.Color(0.8, 0.8, 0.7, 1.0),
brickSize: new Cesium.Cartesian2(0.3, 0.15),
brickPct: new Cesium.Cartesian2(0.9, 0.85),
brickRoughness: 0.2,
mortarRoughness: 0.1
},
source: BrickMaterial
},
translucent: function(material) {
var uniforms = material.uniforms
return uniforms.brickColor.alpha < 1.0 || uniforms.mortarColor.alpha < 1.0
}
})

// Cement
Cesium.Material.CementType = 'Cement'
Cesium.Material._materialCache.addMaterial(Cesium.Material.CementType, {
fabric: {
type: Cesium.Material.CementType,
uniforms: {
cementColor: new Cesium.Color(0.95, 0.95, 0.85, 1.0),
grainScale: 0.01,
roughness: 0.3
},
source: CementMaterial
},
translucent: function(material) {
return material.uniforms.cementColor.alpha < 1.0
}
})

// Erosion
Cesium.Material.ErosionType = 'Erosion'
Cesium.Material._materialCache.addMaterial(Cesium.Material.ErosionType, {
fabric: {
type: Cesium.Material.ErosionType,
uniforms: {
color: new Cesium.Color(1.0, 0.0, 0.0, 0.5),
time: 1.0
},
source: ErosionMaterial
},
translucent: function(material) {
return material.uniforms.color.alpha < 1.0
}
})

// Facet
Cesium.Material.FacetType = 'Facet'
Cesium.Material._materialCache.addMaterial(Cesium.Material.FacetType, {
fabric: {
type: Cesium.Material.FacetType,
uniforms: {
lightColor: new Cesium.Color(0.25, 0.25, 0.25, 0.75),
darkColor: new Cesium.Color(0.75, 0.75, 0.75, 0.75),
frequency: 10.0
},
source: FacetMaterial
},
translucent: function(material) {
var uniforms = material.uniforms
return uniforms.lightColor.alpha < 1.0 || uniforms.darkColor.alpha < 0.0
}
})

// Fresnel
Cesium.Material.FresnelType = 'Fresnel'
Cesium.Material._materialCache.addMaterial(Cesium.Material.FresnelType, {
fabric: {
type: Cesium.Material.FresnelType,
materials: {
reflection: {
type: Cesium.Material.ReflectionType
},
refraction: {
type: Cesium.Material.RefractionType
}
},
source: FresnelMaterial
},
translucent: false
})

// Grass
Cesium.Material.GrassType = 'Grass'
Cesium.Material._materialCache.addMaterial(Cesium.Material.GrassType, {
fabric: {
type: Cesium.Material.GrassType,
uniforms: {
grassColor: new Cesium.Color(0.25, 0.4, 0.1, 1.0),
dirtColor: new Cesium.Color(0.1, 0.1, 0.1, 1.0),
patchiness: 1.5
},
source: GrassMaterial
},
translucent: function(material) {
var uniforms = material.uniforms
return uniforms.grassColor.alpha < 1.0 || uniforms.dirtColor.alpha < 1.0
}
})

// Grass
Cesium.Material.ReflectionType = 'Reflection'
Cesium.Material._materialCache.addMaterial(Cesium.Material.ReflectionType, {
fabric: {
type: Cesium.Material.ReflectionType,
uniforms: {
cubeMap: Cesium.Material.DefaultCubeMapId,
channels: 'rgb'
},
source: ReflectionMaterial
},
translucent: false
})

// Refraction
Cesium.Material.RefractionType = 'Refraction'
Cesium.Material._materialCache.addMaterial(Cesium.Material.RefractionType, {
fabric: {
type: Cesium.Material.RefractionType,
uniforms: {
cubeMap: Cesium.Material.DefaultCubeMapId,
channels: 'rgb',
indexOfRefractionRatio: 0.9
},
source: RefractionMaterial
},
translucent: false
})

// TieDye
Cesium.Material.TyeDyeType = 'TieDye'
Cesium.Material._materialCache.addMaterial(Cesium.Material.TyeDyeType, {
fabric: {
type: Cesium.Material.TyeDyeType,
uniforms: {
lightColor: new Cesium.Color(1.0, 1.0, 0.0, 0.75),
darkColor: new Cesium.Color(1.0, 0.0, 0.0, 0.75),
frequency: 5.0
},
source: TieDyeMaterial
},
translucent: function(material) {
var uniforms = material.uniforms
return uniforms.lightColor.alpha < 1.0 || uniforms.darkColor.alpha < 0.0
}
})

// Wood
Cesium.Material.WoodType = 'Wood'
Cesium.Material._materialCache.addMaterial(Cesium.Material.WoodType, {
fabric: {
type: Cesium.Material.WoodType,
uniforms: {
lightWoodColor: new Cesium.Color(0.6, 0.3, 0.1, 1.0),
darkWoodColor: new Cesium.Color(0.4, 0.2, 0.07, 1.0),
ringFrequency: 3.0,
noiseScale: new Cesium.Cartesian2(0.7, 0.5),
grainFrequency: 27.0
},
source: WoodMaterial
},
translucent: function(material) {
var uniforms = material.uniforms
return (
uniforms.lightWoodColor.alpha < 1.0 || uniforms.darkWoodColor.alpha < 1.0
)
}
})

+ 24
- 0
src/plugins/shader/AsphaltMaterial.glsl Näytä tiedosto

@@ -0,0 +1,24 @@
uniform vec4 asphaltColor;
uniform float bumpSize;
uniform float roughness;

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

// From Stefan Gustavson's Procedural Textures in GLSL in OpenGL Insights
//Main cellular pattern
vec4 color = asphaltColor;
vec2 st = materialInput.st;
vec2 F = czm_cellular(st / bumpSize);
color.rgb -= (F.x / F.y) * 0.1;

//Extra bumps for roughness
float noise = czm_snoise(st / bumpSize);
noise = pow(noise, 5.0) * roughness;
color.rgb += noise;

material.diffuse = color.rgb;
material.alpha = color.a;

return material;
}

+ 17
- 0
src/plugins/shader/BlobMaterial.glsl Näytä tiedosto

@@ -0,0 +1,17 @@
uniform vec4 lightColor;
uniform vec4 darkColor;
uniform float frequency;

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

// From Stefan Gustavson's Procedural Textures in GLSL in OpenGL Insights
vec2 F = czm_cellular(materialInput.st * frequency);
float t = 1.0 - F.x * F.x;

vec4 color = mix(lightColor, darkColor, t);
material.diffuse = color.rgb;
material.alpha = color.a;

return material;
}

+ 41
- 0
src/plugins/shader/BrickMaterial.glsl Näytä tiedosto

@@ -0,0 +1,41 @@
uniform vec4 brickColor;
uniform vec4 mortarColor;
uniform vec2 brickSize;
uniform vec2 brickPct;
uniform float brickRoughness;
uniform float mortarRoughness;

#define Integral(x, p) ((floor(x) * p) + max(fract(x) - (1.0 - p), 0.0))

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

// From OpenGL Shading Language (3rd edition) pg. 194, 501
vec2 st = materialInput.st;
vec2 position = st / brickSize;
if(fract(position.y * 0.5) > 0.5) {
position.x += 0.5;
}

//calculate whether to use brick or mortar (does AA)
vec2 filterWidth = vec2(0.02);
vec2 useBrick = (Integral(position + filterWidth, brickPct) -
Integral(position, brickPct)) / filterWidth;
float useBrickFinal = useBrick.x * useBrick.y;
vec4 color = mix(mortarColor, brickColor, useBrickFinal);

//Apply noise to brick
vec2 brickScaled = vec2(st.x / 0.1, st.y / 0.006);
float brickNoise = abs(czm_snoise(brickScaled) * brickRoughness / 5.0);
color.rg += brickNoise * useBrickFinal;

//Apply noise to mortar
vec2 mortarScaled = st / 0.005;
float mortarNoise = max(czm_snoise(mortarScaled) * mortarRoughness, 0.0);
color.rgb += mortarNoise * (1.0 - useBrickFinal);

material.diffuse = color.rgb;
material.alpha = color.a;

return material;
}

+ 18
- 0
src/plugins/shader/CementMaterial.glsl Näytä tiedosto

@@ -0,0 +1,18 @@
uniform vec4 cementColor;
uniform float grainScale;
uniform float roughness;

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

float noise = czm_snoise(materialInput.st / grainScale);
noise = pow(noise, 5.0) * roughness;

vec4 color = cementColor;
color.rgb += noise;

material.diffuse = color.rgb;
material.alpha = color.a;

return material;
}

+ 21
- 0
src/plugins/shader/ErosionMaterial.glsl Näytä tiedosto

@@ -0,0 +1,21 @@
uniform vec4 color;
uniform float time;

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);
float alpha = 1.0;
if (time != 1.0)
{
float t = 0.5 + (0.5 * czm_snoise(materialInput.str / (1.0 / 10.0))); // Scale [-1, 1] to [0, 1]

if (t > time)
{
alpha = 0.0;
}
}

material.diffuse = color.rgb;
material.alpha = color.a * alpha;

return material;
}

+ 17
- 0
src/plugins/shader/FacetMaterial.glsl Näytä tiedosto

@@ -0,0 +1,17 @@
uniform vec4 lightColor;
uniform vec4 darkColor;
uniform float frequency;

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

// From Stefan Gustavson's Procedural Textures in GLSL in OpenGL Insights
vec2 F = czm_cellular(materialInput.st * frequency);
float t = 0.1 + (F.y - F.x);

vec4 color = mix(lightColor, darkColor, t);
material.diffuse = color.rgb;
material.alpha = color.a;

return material;
}

+ 11
- 0
src/plugins/shader/FresnelMaterial.glsl Näytä tiedosto

@@ -0,0 +1,11 @@
czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

vec3 normalWC = normalize(czm_inverseViewRotation * material.normal);
vec3 positionWC = normalize(czm_inverseViewRotation * materialInput.positionToEyeEC);
float cosAngIncidence = max(dot(normalWC, positionWC), 0.0);

material.diffuse = mix(reflection.diffuse, refraction.diffuse, cosAngIncidence);

return material;
}

+ 27
- 0
src/plugins/shader/GrassMaterial.glsl Näytä tiedosto

@@ -0,0 +1,27 @@
uniform vec4 grassColor;
uniform vec4 dirtColor;
uniform float patchiness;

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

vec2 st = materialInput.st;
float noise1 = (czm_snoise(st * patchiness * 1.0)) * 1.0;
float noise2 = (czm_snoise(st * patchiness * 2.0)) * 0.5;
float noise3 = (czm_snoise(st * patchiness * 4.0)) * 0.25;
float noise = sin(noise1 + noise2 + noise3) * 0.1;

vec4 color = mix(grassColor, dirtColor, noise);

//Make thatch patterns
float verticalNoise = czm_snoise(vec2(st.x * 100.0, st.y * 20.0)) * 0.02;
float horizontalNoise = czm_snoise(vec2(st.x * 20.0, st.y * 100.0)) * 0.02;
float stripeNoise = min(verticalNoise, horizontalNoise);

color.rgb += stripeNoise;

material.diffuse = color.rgb;
material.alpha = color.a;

return material;
}

src/plugins/shader/PolylineEmissionShader.glsl → src/plugins/shader/PolylineEmissionMaterial.glsl Näytä tiedosto


src/plugins/shader/PolylineFlowShader.glsl → src/plugins/shader/PolylineFlowMaterial.glsl Näytä tiedosto


src/plugins/shader/PolylineTrailShader.glsl → src/plugins/shader/PolylineTrailMaterial.glsl Näytä tiedosto


+ 12
- 0
src/plugins/shader/ReflectionMaterial.glsl Näytä tiedosto

@@ -0,0 +1,12 @@
uniform samplerCube cubeMap;

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

vec3 normalWC = normalize(czm_inverseViewRotation * material.normal);
vec3 positionWC = normalize(czm_inverseViewRotation * materialInput.positionToEyeEC);
vec3 reflectedWC = reflect(positionWC, normalWC);
material.diffuse = textureCube(cubeMap, reflectedWC).channels;

return material;
}

+ 13
- 0
src/plugins/shader/RefractionMaterial.glsl Näytä tiedosto

@@ -0,0 +1,13 @@
uniform samplerCube cubeMap;
uniform float indexOfRefractionRatio;

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

vec3 normalWC = normalize(czm_inverseViewRotation * material.normal);
vec3 positionWC = normalize(czm_inverseViewRotation * materialInput.positionToEyeEC);
vec3 refractedWC = refract(positionWC, -normalWC, indexOfRefractionRatio);
material.diffuse = textureCube(cubeMap, refractedWC).channels;

return material;
}

+ 16
- 0
src/plugins/shader/TieDyeMaterial.glsl Näytä tiedosto

@@ -0,0 +1,16 @@
uniform vec4 lightColor;
uniform vec4 darkColor;
uniform float frequency;

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

vec3 scaled = materialInput.str * frequency;
float t = abs(czm_snoise(scaled));

vec4 color = mix(lightColor, darkColor, t);
material.diffuse = color.rgb;
material.alpha = color.a;

return material;
}

+ 35
- 0
src/plugins/shader/WoodMaterial.glsl Näytä tiedosto

@@ -0,0 +1,35 @@
uniform vec4 lightWoodColor;
uniform vec4 darkWoodColor;
uniform float ringFrequency;
uniform vec2 noiseScale;
uniform float grainFrequency;

czm_material czm_getMaterial(czm_materialInput materialInput){
czm_material material = czm_getDefaultMaterial(materialInput);

//Based on wood shader from OpenGL Shading Language (3rd edition) pg. 455
vec2 st = materialInput.st;

vec2 noisevec;
noisevec.x = czm_snoise(st * noiseScale.x);
noisevec.y = czm_snoise(st * noiseScale.y);

vec2 location = st + noisevec;
float dist = sqrt(location.x * location.x + location.y * location.y);
dist *= ringFrequency;

float r = fract(dist + noisevec[0] + noisevec[1]) * 2.0;
if(r > 1.0)
r = 2.0 - r;

vec4 color = mix(lightWoodColor, darkWoodColor, r);

//streaks
r = abs(czm_snoise(vec2(st.x * grainFrequency, st.y * grainFrequency * 0.02))) * 0.2;
color.rgb += lightWoodColor.rgb * r;

material.diffuse = color.rgb;
material.alpha = color.a;

return material;
}

+ 77
- 0
src/plugins/shader/cellular.glsl Näytä tiedosto

@@ -0,0 +1,77 @@
/**
* @license
* Cellular noise ("Worley noise") in 2D in GLSL.
* Copyright (c) Stefan Gustavson 2011-04-19. All rights reserved.
* This code is released under the conditions of the MIT license.
* See LICENSE file for details.
*/

//#ifdef GL_OES_standard_derivatives
// #extension GL_OES_standard_derivatives : enable
//#endif
//
//float aastep (float threshold , float value)
//{
// float afwidth = 0.7 * length ( vec2 ( dFdx ( value ), dFdy ( value )));
// return smoothstep ( threshold - afwidth , threshold + afwidth , value );
//}

// Permutation polynomial: (34x^2 + x) mod 289
vec3 _czm_permute289(vec3 x)
{
return mod((34.0 * x + 1.0) * x, 289.0);
}

/**
* DOC_TBA
*
* Implemented by Stefan Gustavson, and distributed under the MIT License. {@link http://openglinsights.git.sourceforge.net/git/gitweb.cgi?p=openglinsights/openglinsights;a=tree;f=proceduraltextures}
*
* @name czm_cellular
* @glslFunction
*
* @see Stefan Gustavson's chapter, <i>Procedural Textures in GLSL</i>, in <a href="http://www.openglinsights.com/">OpenGL Insights</a>.
*/
vec2 czm_cellular(vec2 P)
// Cellular noise, returning F1 and F2 in a vec2.
// Standard 3x3 search window for good F1 and F2 values
{
#define K 0.142857142857 // 1/7
#define Ko 0.428571428571 // 3/7
#define jitter 1.0 // Less gives more regular pattern
vec2 Pi = mod(floor(P), 289.0);
vec2 Pf = fract(P);
vec3 oi = vec3(-1.0, 0.0, 1.0);
vec3 of = vec3(-0.5, 0.5, 1.5);
vec3 px = _czm_permute289(Pi.x + oi);
vec3 p = _czm_permute289(px.x + Pi.y + oi); // p11, p12, p13
vec3 ox = fract(p*K) - Ko;
vec3 oy = mod(floor(p*K),7.0)*K - Ko;
vec3 dx = Pf.x + 0.5 + jitter*ox;
vec3 dy = Pf.y - of + jitter*oy;
vec3 d1 = dx * dx + dy * dy; // d11, d12 and d13, squared
p = _czm_permute289(px.y + Pi.y + oi); // p21, p22, p23
ox = fract(p*K) - Ko;
oy = mod(floor(p*K),7.0)*K - Ko;
dx = Pf.x - 0.5 + jitter*ox;
dy = Pf.y - of + jitter*oy;
vec3 d2 = dx * dx + dy * dy; // d21, d22 and d23, squared
p = _czm_permute289(px.z + Pi.y + oi); // p31, p32, p33
ox = fract(p*K) - Ko;
oy = mod(floor(p*K),7.0)*K - Ko;
dx = Pf.x - 1.5 + jitter*ox;
dy = Pf.y - of + jitter*oy;
vec3 d3 = dx * dx + dy * dy; // d31, d32 and d33, squared
// Sort out the two smallest distances (F1, F2)
vec3 d1a = min(d1, d2);
d2 = max(d1, d2); // Swap to keep candidates for F2
d2 = min(d2, d3); // neither F1 nor F2 are now in d3
d1 = min(d1a, d2); // F1 is now in d1
d2 = max(d1a, d2); // Swap to keep candidates for F2
d1.xy = (d1.x < d1.y) ? d1.xy : d1.yx; // Swap if smaller
d1.xz = (d1.x < d1.z) ? d1.xz : d1.zx; // F1 is in d1.x
d1.yz = min(d1.yz, d2.yz); // F2 is now not in d2.yz
d1.y = min(d1.y, d1.z); // nor in d1.z
d1.y = min(d1.y, d2.x); // F2 is in d1.y, we're done.
return sqrt(d1.xy);
}

+ 282
- 0
src/plugins/shader/snoise.glsl Näytä tiedosto

@@ -0,0 +1,282 @@
/**
* @license
* Description : Array and textureless GLSL 2D/3D/4D simplex
* noise functions.
* Author : Ian McEwan, Ashima Arts.
* Maintainer : ijm
* Lastmod : 20110822 (ijm)
* License : Copyright (C) 2011 Ashima Arts. All rights reserved.
* Distributed under the MIT License. See LICENSE file.
* https://github.com/ashima/webgl-noise
*/

vec4 _czm_mod289(vec4 x)
{
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec3 _czm_mod289(vec3 x)
{
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec2 _czm_mod289(vec2 x)
{
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

float _czm_mod289(float x)
{
return x - floor(x * (1.0 / 289.0)) * 289.0;
}

vec4 _czm_permute(vec4 x)
{
return _czm_mod289(((x*34.0)+1.0)*x);
}

vec3 _czm_permute(vec3 x)
{
return _czm_mod289(((x*34.0)+1.0)*x);
}

float _czm_permute(float x)
{
return _czm_mod289(((x*34.0)+1.0)*x);
}

vec4 _czm_taylorInvSqrt(vec4 r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}

float _czm_taylorInvSqrt(float r)
{
return 1.79284291400159 - 0.85373472095314 * r;
}

vec4 _czm_grad4(float j, vec4 ip)
{
const vec4 ones = vec4(1.0, 1.0, 1.0, -1.0);
vec4 p,s;

p.xyz = floor( fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0;
p.w = 1.5 - dot(abs(p.xyz), ones.xyz);
s = vec4(lessThan(p, vec4(0.0)));
p.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www;

return p;
}

/**
* DOC_TBA
*
* Implemented by Ian McEwan, Ashima Arts, and distributed under the MIT License. {@link https://github.com/ashima/webgl-noise}
*
* @name czm_snoise
* @glslFunction
*
* @see <a href="https://github.com/ashima/webgl-noise">https://github.com/ashima/webgl-noise</a>
* @see Stefan Gustavson's paper <a href="http://www.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf">Simplex noise demystified</a>
*/
float czm_snoise(vec2 v)
{
const vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0
0.366025403784439, // 0.5*(sqrt(3.0)-1.0)
-0.577350269189626, // -1.0 + 2.0 * C.x
0.024390243902439); // 1.0 / 41.0
// First corner
vec2 i = floor(v + dot(v, C.yy) );
vec2 x0 = v - i + dot(i, C.xx);

// Other corners
vec2 i1;
//i1.x = step( x0.y, x0.x ); // x0.x > x0.y ? 1.0 : 0.0
//i1.y = 1.0 - i1.x;
i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
// x0 = x0 - 0.0 + 0.0 * C.xx ;
// x1 = x0 - i1 + 1.0 * C.xx ;
// x2 = x0 - 1.0 + 2.0 * C.xx ;
vec4 x12 = x0.xyxy + C.xxzz;
x12.xy -= i1;

// Permutations
i = _czm_mod289(i); // Avoid truncation effects in permutation
vec3 p = _czm_permute( _czm_permute( i.y + vec3(0.0, i1.y, 1.0 )) + i.x + vec3(0.0, i1.x, 1.0 ));

vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
m = m*m ;
m = m*m ;

// Gradients: 41 points uniformly over a line, mapped onto a diamond.
// The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
vec3 x = 2.0 * fract(p * C.www) - 1.0;
vec3 h = abs(x) - 0.5;
vec3 ox = floor(x + 0.5);
vec3 a0 = x - ox;

// Normalise gradients implicitly by scaling m
// Approximation of: m *= inversesqrt( a0*a0 + h*h );
m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );

// Compute final noise value at P
vec3 g;
g.x = a0.x * x0.x + h.x * x0.y;
g.yz = a0.yz * x12.xz + h.yz * x12.yw;
return 130.0 * dot(m, g);
}

float czm_snoise(vec3 v)
{
const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);

// First corner
vec3 i = floor(v + dot(v, C.yyy) );
vec3 x0 = v - i + dot(i, C.xxx) ;

// Other corners
vec3 g = step(x0.yzx, x0.xyz);
vec3 l = 1.0 - g;
vec3 i1 = min( g.xyz, l.zxy );
vec3 i2 = max( g.xyz, l.zxy );

// x0 = x0 - 0.0 + 0.0 * C.xxx;
// x1 = x0 - i1 + 1.0 * C.xxx;
// x2 = x0 - i2 + 2.0 * C.xxx;
// x3 = x0 - 1.0 + 3.0 * C.xxx;
vec3 x1 = x0 - i1 + C.xxx;
vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y

// Permutations
i = _czm_mod289(i);
vec4 p = _czm_permute( _czm_permute( _czm_permute(
i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
+ i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
+ i.x + vec4(0.0, i1.x, i2.x, 1.0 ));

// Gradients: 7x7 points over a square, mapped onto an octahedron.
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
float n_ = 0.142857142857; // 1.0/7.0
vec3 ns = n_ * D.wyz - D.xzx;

vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)

vec4 x_ = floor(j * ns.z);
vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)

vec4 x = x_ *ns.x + ns.yyyy;
vec4 y = y_ *ns.x + ns.yyyy;
vec4 h = 1.0 - abs(x) - abs(y);

vec4 b0 = vec4( x.xy, y.xy );
vec4 b1 = vec4( x.zw, y.zw );

//vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
//vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
vec4 s0 = floor(b0)*2.0 + 1.0;
vec4 s1 = floor(b1)*2.0 + 1.0;
vec4 sh = -step(h, vec4(0.0));

vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;

vec3 p0 = vec3(a0.xy,h.x);
vec3 p1 = vec3(a0.zw,h.y);
vec3 p2 = vec3(a1.xy,h.z);
vec3 p3 = vec3(a1.zw,h.w);

//Normalise gradients
vec4 norm = _czm_taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;

// Mix final noise value
vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
m = m * m;
return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
dot(p2,x2), dot(p3,x3) ) );
}

float czm_snoise(vec4 v)
{
const vec4 C = vec4( 0.138196601125011, // (5 - sqrt(5))/20 G4
0.276393202250021, // 2 * G4
0.414589803375032, // 3 * G4
-0.447213595499958); // -1 + 4 * G4

// (sqrt(5) - 1)/4 = F4, used once below
#define F4 0.309016994374947451

// First corner
vec4 i = floor(v + dot(v, vec4(F4)) );
vec4 x0 = v - i + dot(i, C.xxxx);

// Other corners

// Rank sorting originally contributed by Bill Licea-Kane, AMD (formerly ATI)
vec4 i0;
vec3 isX = step( x0.yzw, x0.xxx );
vec3 isYZ = step( x0.zww, x0.yyz );
// i0.x = dot( isX, vec3( 1.0 ) );
i0.x = isX.x + isX.y + isX.z;
i0.yzw = 1.0 - isX;
// i0.y += dot( isYZ.xy, vec2( 1.0 ) );
i0.y += isYZ.x + isYZ.y;
i0.zw += 1.0 - isYZ.xy;
i0.z += isYZ.z;
i0.w += 1.0 - isYZ.z;

// i0 now contains the unique values 0,1,2,3 in each channel
vec4 i3 = clamp( i0, 0.0, 1.0 );
vec4 i2 = clamp( i0-1.0, 0.0, 1.0 );
vec4 i1 = clamp( i0-2.0, 0.0, 1.0 );

// x0 = x0 - 0.0 + 0.0 * C.xxxx
// x1 = x0 - i1 + 1.0 * C.xxxx
// x2 = x0 - i2 + 2.0 * C.xxxx
// x3 = x0 - i3 + 3.0 * C.xxxx
// x4 = x0 - 1.0 + 4.0 * C.xxxx
vec4 x1 = x0 - i1 + C.xxxx;
vec4 x2 = x0 - i2 + C.yyyy;
vec4 x3 = x0 - i3 + C.zzzz;
vec4 x4 = x0 + C.wwww;

// Permutations
i = _czm_mod289(i);
float j0 = _czm_permute( _czm_permute( _czm_permute( _czm_permute(i.w) + i.z) + i.y) + i.x);
vec4 j1 = _czm_permute( _czm_permute( _czm_permute( _czm_permute (
i.w + vec4(i1.w, i2.w, i3.w, 1.0 ))
+ i.z + vec4(i1.z, i2.z, i3.z, 1.0 ))
+ i.y + vec4(i1.y, i2.y, i3.y, 1.0 ))
+ i.x + vec4(i1.x, i2.x, i3.x, 1.0 ));

// Gradients: 7x7x6 points over a cube, mapped onto a 4-cross polytope
// 7*7*6 = 294, which is close to the ring size 17*17 = 289.
vec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ;

vec4 p0 = _czm_grad4(j0, ip);
vec4 p1 = _czm_grad4(j1.x, ip);
vec4 p2 = _czm_grad4(j1.y, ip);
vec4 p3 = _czm_grad4(j1.z, ip);
vec4 p4 = _czm_grad4(j1.w, ip);

// Normalise gradients
vec4 norm = _czm_taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
p0 *= norm.x;
p1 *= norm.y;
p2 *= norm.z;
p3 *= norm.w;
p4 *= _czm_taylorInvSqrt(dot(p4,p4));

// Mix contributions from the five corners
vec3 m0 = max(0.6 - vec3(dot(x0,x0), dot(x1,x1), dot(x2,x2)), 0.0);
vec2 m1 = max(0.6 - vec2(dot(x3,x3), dot(x4,x4) ), 0.0);
m0 = m0 * m0;
m1 = m1 * m1;
return 49.0 * ( dot(m0*m0, vec3( dot( p0, x0 ), dot( p1, x1 ), dot( p2, x2 )))
+ dot(m1*m1, vec2( dot( p3, x3 ), dot( p4, x4 ) ) ) ) ;
}

Loading…
Peruuta
Tallenna