starting color

This commit is contained in:
ericrius1 2016-03-08 16:09:19 -08:00
parent 41782dbd8d
commit c928b9e411
2 changed files with 56 additions and 27 deletions

View file

@ -13,19 +13,51 @@
#define TWO_PI 6.28318530718
uniform float iBloomPct = 0.2;
uniform float hueAngleRange = 20.0;
uniform float hueOffset = 0.5;
uniform vec3 iHSLColor = vec3(0.7, 0.5, 0.5);
vec3 hsb2rgb( in vec3 c ){
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),
6.0)-3.0)-1.0,
0.0,
1.0 );
rgb = rgb*rgb*(3.0-2.0*rgb);
return c.z * mix( vec3(1.0), rgb, c.y);
float hue2rgb(float f1, float f2, float hue) {
if (hue < 0.0)
hue += 1.0;
else if (hue > 1.0)
hue -= 1.0;
float res;
if ((6.0 * hue) < 1.0)
res = f1 + (f2 - f1) * 6.0 * hue;
else if ((2.0 * hue) < 1.0)
res = f2;
else if ((3.0 * hue) < 2.0)
res = f1 + (f2 - f1) * ((2.0 / 3.0) - hue) * 6.0;
else
res = f1;
return res;
}
vec3 hsl2rgb(vec3 hsl) {
vec3 rgb;
if (hsl.y == 0.0) {
rgb = vec3(hsl.z); // Luminance
} else {
float f2;
if (hsl.z < 0.5)
f2 = hsl.z * (1.0 + hsl.y);
else
f2 = hsl.z + hsl.y - hsl.y * hsl.z;
float f1 = 2.0 * hsl.z - f2;
rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0));
rgb.g = hue2rgb(f1, f2, hsl.x);
rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0));
}
return rgb;
}
vec3 hsl2rgb(float h, float s, float l) {
return hsl2rgb(vec3(h, s, l));
}
void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
vec2 st = fragCoord.xy/iWorldScale.xz;
@ -41,12 +73,10 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
}
// simulate ambient occlusion
float brightness = pow(radius, 0.8);
float hueTimeOffset = sin(iGlobalTime * 0.01) + hueOffset;
color = hsb2rgb(vec3( abs(angle/hueAngleRange) + hueTimeOffset, 0.7, brightness));
fragColor = vec4(1.0, 0.1, 1.0, 1.0);
vec3 rgbColor =hsl2rgb(iHSLColor);
fragColor = vec4(rgbColor, 1.0);
}

View file

@ -66,23 +66,11 @@
return;
}
var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal);
_this.flowerUserData.ProceduralEntity.uniforms.hueAngleRange = randFloat(20, 40);
_this.flowerUserData.ProceduralEntity.uniforms.hueOffset = Math.random();
var flowerEntityID = Entities.addEntity({
type: "Sphere",
name: "flower",
position: position,
collisionless: true,
rotation: flowerRotation,
dimensions: _this.STARTING_FLOWER_DIMENSIONS,
userData: JSON.stringify(_this.flowerUserData)
});
// var xzGrowthRate = randFloat(0.00005, 0.00015);
var xzGrowthRate = randFloat(0.0005, 0.0015);
// var growthRate = {x: xzGrowthRate, y: randFloat(0.001, 0.0025, z: xzGrowthRate)};
var growthRate = {x: xzGrowthRate, y: randFloat(0.01, 0.025), z: xzGrowthRate};
var flower = {
id: flowerEntityID,
dimensions: {
x: _this.STARTING_FLOWER_DIMENSIONS.x,
y: _this.STARTING_FLOWER_DIMENSIONS.y,
@ -92,8 +80,20 @@
rotation: flowerRotation,
// maxYDimension: randFloat(0.4, 1.0),
maxYDimension: randFloat(4, 10.0),
startingHSLColor: {hue: 80/360, saturation: 0.47, light: 0.48},
endingHSLColor: {hue: 19/260, saturation: 0.92, light: 0.41},
growthRate: growthRate
};
_this.flowerUserData.ProceduralEntity.uniforms.iHSLColor= [flower.startingHSLColor.hue, flower.startingHSLColor.saturation, flower.startingHSLColor.light];
flower.id = Entities.addEntity({
type: "Sphere",
name: "flower",
position: position,
collisionless: true,
rotation: flowerRotation,
dimensions: _this.STARTING_FLOWER_DIMENSIONS,
userData: JSON.stringify(_this.flowerUserData)
});
flower.grow = function() {
// grow flower a bit
if (flower.dimensions.y > flower.maxYDimension) {
@ -120,7 +120,6 @@
shaderUrl: SHADER_URL,
uniforms: {
iBloomPct: randFloat(0.4, 0.8),
hueTwerking: Math.random()
}
}
};