mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:01:18 +02:00
basic flower petal
This commit is contained in:
parent
7fe555d3a5
commit
b4340f7b70
3 changed files with 129 additions and 1 deletions
60
examples/homeContent/plant/flower.fs
Normal file
60
examples/homeContent/plant/flower.fs
Normal file
|
@ -0,0 +1,60 @@
|
|||
#line 2
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// REPLACE BELOW
|
||||
//
|
||||
// Replace the contents of this section with a shadertoy that includes a mainImage
|
||||
// function
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define TWO_PI 6.28318530718
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
|
||||
vec2 st = fragCoord.xy/iWorldScale.xz;
|
||||
vec3 color = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
vec2 toCenter = vec2(0.5) - st;
|
||||
float angle = atan(toCenter.y, toCenter.x);
|
||||
float radius = length(toCenter) * 2.0;
|
||||
|
||||
if (radius > 0.8) {
|
||||
discard;
|
||||
}
|
||||
|
||||
color = hsb2rgb(vec3((angle/TWO_PI) + 0.5, radius, 1.0));
|
||||
|
||||
// Map the angle (-PI to PI) to the Hue (from 0 to 1)
|
||||
// and the Saturation to the radius
|
||||
// angle = pow(angle, 0.2);
|
||||
|
||||
|
||||
fragColor = vec4(color, 1.0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// REPLACE ABOVE
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
vec4 getProceduralColor() {
|
||||
vec4 result;
|
||||
vec2 position = _position.xz;
|
||||
position += 0.5;
|
||||
|
||||
mainImage(result, position * iWorldScale.xz);
|
||||
|
||||
return result;
|
||||
}
|
54
examples/homeContent/plant/growingPlantEntityScript.js
Normal file
54
examples/homeContent/plant/growingPlantEntityScript.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
//
|
||||
// growingPlantEntityScript.js
|
||||
// examples/homeContent/
|
||||
//
|
||||
// Created by Eric Levin on 2/10/16.
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// This entity script handles the logic for growing a plant when it has water poured on it
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
var _this;
|
||||
GrowingPlant = function() {
|
||||
_this = this;
|
||||
};
|
||||
|
||||
GrowingPlant.prototype = {
|
||||
|
||||
createLeaf: function() {
|
||||
var userData = JSON.stringify({
|
||||
ProceduralEntity: {
|
||||
shaderUrl: "file:///C:/Users/Eric/hifi/examples/homeContent/plant/flower.fs",
|
||||
// shaderUrl: "file:///C:/Users/Eric/hifi/examples/shaders/shaderToyWrapper.fs",
|
||||
}
|
||||
});
|
||||
this.leaf = Entities.addEntity({
|
||||
type: "Box",
|
||||
position: Vec3.sum(this.position, {x: 0, y: this.dimensions.y/2, z: 0 }),
|
||||
color: {red: 100, green: 10, blue: 100},
|
||||
dimensions: {x: 0.3, y: 0.001, z: 0.3},
|
||||
userData: userData
|
||||
});
|
||||
},
|
||||
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
this.props = Entities.getEntityProperties(this.entityID, ["position", "dimensions"]);
|
||||
this.position = this.props.position;
|
||||
this.dimensions = this.props.dimensions;
|
||||
this.createLeaf();
|
||||
},
|
||||
|
||||
unload: function() {
|
||||
Entities.deleteEntity(this.leaf);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// entity scripts always need to return a newly constructed object of our type
|
||||
return new GrowingPlant();
|
||||
});
|
|
@ -1,3 +1,15 @@
|
|||
//
|
||||
// growingPlantSpawner.js
|
||||
// examples/homeContent/
|
||||
//
|
||||
// Created by Eric Levin on 2/10/16.
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// This entity script handles the logic for growing a plant when it has water poured on it
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
|
||||
|
||||
var orientation = Camera.getOrientation();
|
||||
orientation = Quat.safeEulerAngles(orientation);
|
||||
orientation.x = 0;
|
||||
|
@ -9,6 +21,8 @@ initializePlant();
|
|||
|
||||
function initializePlant() {
|
||||
var MODEL_URL = "file:///C:/Users/Eric/Desktop/pot.fbx";
|
||||
var SCRIPT_URL = Script.resolvePath("growingPlantEntityScript.js?v1" + Math.random());
|
||||
|
||||
pot = Entities.addEntity({
|
||||
type: "Model",
|
||||
modelURL: MODEL_URL,
|
||||
|
@ -17,7 +31,7 @@ function initializePlant() {
|
|||
|
||||
Script.setTimeout(function() {
|
||||
var naturalDimensions = Entities.getEntityProperties(pot, "naturalDimensions").naturalDimensions;
|
||||
Entities.editEntity(pot, {dimensions: naturalDimensions});
|
||||
Entities.editEntity(pot, {dimensions: naturalDimensions, script: SCRIPT_URL});
|
||||
}, 2000);
|
||||
|
||||
}
|
Loading…
Reference in a new issue