mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-24 09:34:03 +02:00
slower growth
This commit is contained in:
parent
65c8f7cc45
commit
cdd4fdb03e
4 changed files with 67 additions and 32 deletions
|
@ -3,7 +3,8 @@
|
||||||
#define TWO_PI 6.28318530718
|
#define TWO_PI 6.28318530718
|
||||||
|
|
||||||
uniform float iBloomPct = 0.2;
|
uniform float iBloomPct = 0.2;
|
||||||
uniform float hueTwerking = 10.0;
|
uniform float hueAngleRange = 20.0;
|
||||||
|
uniform float hueOffset = 0.5;
|
||||||
|
|
||||||
|
|
||||||
vec3 hsb2rgb( in vec3 c ){
|
vec3 hsb2rgb( in vec3 c ){
|
||||||
|
@ -30,9 +31,9 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// simulate ambient occlusion
|
// simulate ambient occlusion
|
||||||
float brightness = pow(radius, 0.7);
|
float brightness = pow(radius, 0.8);
|
||||||
float hueOffset = sin(iGlobalTime * 0.07) + hueTwerking;
|
float hueTimeOffset = sin(iGlobalTime * 0.01) + hueOffset;
|
||||||
color = hsb2rgb(vec3( abs(angle/hueTwerking) + hueOffset, 0.8, brightness));
|
color = hsb2rgb(vec3( abs(angle/hueAngleRange) + hueTimeOffset, 0.7, brightness));
|
||||||
|
|
||||||
|
|
||||||
fragColor = vec4(color, 1.0);
|
fragColor = vec4(color, 1.0);
|
||||||
|
|
|
@ -25,7 +25,13 @@
|
||||||
z: 0.001
|
z: 0.001
|
||||||
}
|
}
|
||||||
|
|
||||||
_this.debounceRange = {min: 500, max: 1000};
|
_this.MAX_FLOWERS = 50;
|
||||||
|
_this.MIN_FLOWER_TO_FLOWER_DISTANCE = 0.03;
|
||||||
|
|
||||||
|
_this.debounceRange = {
|
||||||
|
min: 500,
|
||||||
|
max: 1000
|
||||||
|
};
|
||||||
_this.canCreateFlower = true;
|
_this.canCreateFlower = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -38,13 +44,13 @@
|
||||||
// If we don't have any flowers yet, immediately grow one
|
// If we don't have any flowers yet, immediately grow one
|
||||||
var data = JSON.parse(data[0]);
|
var data = JSON.parse(data[0]);
|
||||||
|
|
||||||
if(_this.canCreateFlower) {
|
if (_this.canCreateFlower && _this.flowers.length < _this.MAX_FLOWERS) {
|
||||||
_this.createFlower(data.position, data.surfaceNormal);
|
_this.createFlower(data.position, data.surfaceNormal);
|
||||||
_this.canCreateFlower = false;
|
_this.canCreateFlower = false;
|
||||||
Script.setTimeout(function() {
|
Script.setTimeout(function() {
|
||||||
_this.canCreateFlower = true;
|
_this.canCreateFlower = true;
|
||||||
}, randFloat(_this.debounceRange.min, this.debounceRange.max));
|
}, randFloat(_this.debounceRange.min, this.debounceRange.max));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_this.flowers.forEach(function(flower) {
|
_this.flowers.forEach(function(flower) {
|
||||||
|
@ -56,7 +62,13 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
createFlower: function(position, surfaceNormal) {
|
createFlower: function(position, surfaceNormal) {
|
||||||
|
if (_this.previousFlowerPosition && Vec3.distance(position, _this.previousFlowerPosition) < _this.MIN_FLOWER_TO_FLOWER_DISTANCE) {
|
||||||
|
// Reduces flower overlap
|
||||||
|
return;
|
||||||
|
}
|
||||||
var flowerRotation = Quat.rotationBetween(Vec3.UNIT_Y, surfaceNormal);
|
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({
|
var flowerEntityID = Entities.addEntity({
|
||||||
type: "Sphere",
|
type: "Sphere",
|
||||||
name: "flower",
|
name: "flower",
|
||||||
|
@ -66,16 +78,23 @@
|
||||||
dimensions: _this.STARTING_FLOWER_DIMENSIONS,
|
dimensions: _this.STARTING_FLOWER_DIMENSIONS,
|
||||||
userData: JSON.stringify(_this.flowerUserData)
|
userData: JSON.stringify(_this.flowerUserData)
|
||||||
});
|
});
|
||||||
|
var xzGrowthRate = randFloat(0.0001, 0.0002);
|
||||||
var flower = {
|
var flower = {
|
||||||
id: flowerEntityID,
|
id: flowerEntityID,
|
||||||
dimensions: {x: _this.STARTING_FLOWER_DIMENSIONS.x, y: _this.STARTING_FLOWER_DIMENSIONS.y, z: _this.STARTING_FLOWER_DIMENSIONS.z},
|
dimensions: {
|
||||||
|
x: _this.STARTING_FLOWER_DIMENSIONS.x,
|
||||||
|
y: _this.STARTING_FLOWER_DIMENSIONS.y,
|
||||||
|
z: _this.STARTING_FLOWER_DIMENSIONS.z
|
||||||
|
},
|
||||||
startingPosition: position,
|
startingPosition: position,
|
||||||
rotation: flowerRotation,
|
rotation: flowerRotation,
|
||||||
maxYDimension: randFloat(0.2, 1.5),
|
maxYDimension: randFloat(0.4, 1.0),
|
||||||
growthRate: {x: 0.0002, y: 0.001, z: 0.0002}
|
growthRate: {
|
||||||
|
x: xzGrowthRate,
|
||||||
|
y: randFloat(0.001, 0.0025),
|
||||||
|
z: xzGrowthRate
|
||||||
|
}
|
||||||
};
|
};
|
||||||
print(_this.STARTING_FLOWER_DIMENSIONS.y)
|
|
||||||
flower.grow = function() {
|
flower.grow = function() {
|
||||||
// grow flower a bit
|
// grow flower a bit
|
||||||
if (flower.dimensions.y > flower.maxYDimension) {
|
if (flower.dimensions.y > flower.maxYDimension) {
|
||||||
|
@ -90,16 +109,19 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_this.flowers.push(flower);
|
_this.flowers.push(flower);
|
||||||
|
_this.previousFlowerPosition = position;
|
||||||
},
|
},
|
||||||
|
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
_this.entityID = entityID;
|
_this.entityID = entityID;
|
||||||
|
var SHADER_URL = "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs"
|
||||||
|
// var SHADER_URL = "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs";
|
||||||
_this.flowerUserData = {
|
_this.flowerUserData = {
|
||||||
ProceduralEntity: {
|
ProceduralEntity: {
|
||||||
shaderUrl: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/shaders/flower.fs",
|
shaderUrl: SHADER_URL,
|
||||||
uniforms: {
|
uniforms: {
|
||||||
iBloomPct: randFloat(0.4, 0.8),
|
iBloomPct: randFloat(0.4, 0.8),
|
||||||
hueTwerking: randFloat(10, 30)
|
hueTwerking: Math.random()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,7 +62,7 @@ var waterCan = Entities.addEntity({
|
||||||
|
|
||||||
|
|
||||||
var waterSpoutPosition = Vec3.sum(waterCanPosition, Vec3.multiply(0.2, Quat.getFront(orientation)))
|
var waterSpoutPosition = Vec3.sum(waterCanPosition, Vec3.multiply(0.2, Quat.getFront(orientation)))
|
||||||
var waterSpoutRotation = Quat.multiply(waterCanRotation, Quat.fromPitchYawRollDegrees(30, 0, 0));
|
var waterSpoutRotation = Quat.multiply(waterCanRotation, Quat.fromPitchYawRollDegrees(10, 0, 0));
|
||||||
var waterSpout = Entities.addEntity({
|
var waterSpout = Entities.addEntity({
|
||||||
type: "Box",
|
type: "Box",
|
||||||
name: "hifi-water-spout",
|
name: "hifi-water-spout",
|
||||||
|
@ -70,7 +70,8 @@ var waterSpout = Entities.addEntity({
|
||||||
color: {red: 200, green: 10, blue: 200},
|
color: {red: 200, green: 10, blue: 200},
|
||||||
position: waterSpoutPosition,
|
position: waterSpoutPosition,
|
||||||
rotation: waterSpoutRotation,
|
rotation: waterSpoutRotation,
|
||||||
parentID: waterCan
|
parentID: waterCan,
|
||||||
|
visible: false
|
||||||
});
|
});
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
WaterSpout = function() {
|
WaterSpout = function() {
|
||||||
_this = this;
|
_this = this;
|
||||||
_this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav");
|
_this.waterSound = SoundCache.getSound("https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/shower.wav");
|
||||||
_this.POUR_ANGLE_THRESHOLD = -10;
|
_this.POUR_ANGLE_THRESHOLD = 0;
|
||||||
_this.waterPouring = false;
|
_this.waterPouring = false;
|
||||||
_this.WATER_SPOUT_NAME = "hifi-water-spout";
|
_this.WATER_SPOUT_NAME = "hifi-water-spout";
|
||||||
|
|
||||||
|
@ -42,13 +42,22 @@
|
||||||
var rotation = Entities.getEntityProperties(_this.entityID, "rotation").rotation;
|
var rotation = Entities.getEntityProperties(_this.entityID, "rotation").rotation;
|
||||||
var pitch = Quat.safeEulerAngles(rotation).x;
|
var pitch = Quat.safeEulerAngles(rotation).x;
|
||||||
if (pitch < _this.POUR_ANGLE_THRESHOLD) {
|
if (pitch < _this.POUR_ANGLE_THRESHOLD) {
|
||||||
|
// Water is pouring
|
||||||
|
var spoutProps = Entities.getEntityProperties(_this.waterSpout, ["rotation", "position"]);
|
||||||
if (!_this.waterPouring) {
|
if (!_this.waterPouring) {
|
||||||
Entities.editEntity(_this.waterEffect, {
|
Entities.editEntity(_this.waterEffect, {
|
||||||
isEmitting: true
|
isEmitting: true
|
||||||
});
|
});
|
||||||
_this.waterPouring = true;
|
_this.waterPouring = true;
|
||||||
|
if (!_this.waterInjector) {
|
||||||
|
print ("PLAY SOUND")
|
||||||
|
_this.waterInjector = Audio.playSound(_this.waterSound, {position: spoutProps.position, loop: true});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_this.waterInjector.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_this.waterSpoutRotation = Entities.getEntityProperties(_this.waterSpout, "rotation").rotation;
|
_this.waterSpoutRotation = spoutProps.rotation;
|
||||||
var waterEmitOrientation = Quat.multiply(_this.waterSpoutRotation, Quat.fromPitchYawRollDegrees(0, 180, 0));
|
var waterEmitOrientation = Quat.multiply(_this.waterSpoutRotation, Quat.fromPitchYawRollDegrees(0, 180, 0));
|
||||||
Entities.editEntity(_this.waterEffect, {
|
Entities.editEntity(_this.waterEffect, {
|
||||||
emitOrientation: waterEmitOrientation
|
emitOrientation: waterEmitOrientation
|
||||||
|
@ -58,6 +67,8 @@
|
||||||
isEmitting: false
|
isEmitting: false
|
||||||
});
|
});
|
||||||
_this.waterPouring = false;
|
_this.waterPouring = false;
|
||||||
|
//water no longer pouring...
|
||||||
|
_this.waterInjector.stop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -94,19 +105,19 @@
|
||||||
isEmitting: false,
|
isEmitting: false,
|
||||||
parentID: _this.waterSpout,
|
parentID: _this.waterSpout,
|
||||||
colorStart: {
|
colorStart: {
|
||||||
red: 50,
|
red: 90,
|
||||||
green: 50,
|
green: 90,
|
||||||
blue: 70
|
blue: 110
|
||||||
},
|
},
|
||||||
color: {
|
color: {
|
||||||
red: 30,
|
red: 70,
|
||||||
green: 30,
|
green: 70,
|
||||||
blue: 40
|
blue: 130
|
||||||
},
|
},
|
||||||
colorFinish: {
|
colorFinish: {
|
||||||
red: 50,
|
red: 60,
|
||||||
green: 50,
|
green: 30,
|
||||||
blue: 60
|
blue: 140
|
||||||
},
|
},
|
||||||
maxParticles: 20000,
|
maxParticles: 20000,
|
||||||
lifespan: 2,
|
lifespan: 2,
|
||||||
|
@ -124,7 +135,7 @@
|
||||||
z: 0
|
z: 0
|
||||||
},
|
},
|
||||||
polarStart: 0,
|
polarStart: 0,
|
||||||
polarFinish: .2,
|
polarFinish: .1,
|
||||||
accelerationSpread: {
|
accelerationSpread: {
|
||||||
x: 0.01,
|
x: 0.01,
|
||||||
y: 0.0,
|
y: 0.0,
|
||||||
|
|
Loading…
Reference in a new issue