Skip to content

Commit

Permalink
Add TailMaterial
Browse files Browse the repository at this point in the history
  • Loading branch information
milcktoast committed Nov 12, 2014
1 parent 4b608c9 commit bb4885e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
6 changes: 3 additions & 3 deletions static/js/apps/medusae/MedusaeScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ Medusae.prototype.createTail = function (index, total) {
this.queueConstraints(linkConstraints);

this.addLinks(outerIndices);
this.addLinks(linkIndices);
// this.addLinks(linkIndices);
};

Medusae.prototype.queueConstraint = function (constraint) {
Expand Down Expand Up @@ -390,10 +390,10 @@ Medusae.prototype.createMaterials = function () {
tailFaceGeom.addAttribute('uv', uvs);

this.tailMesh = new THREE.Mesh(tailFaceGeom,
new App.UVMaterial({
new App.TailMaterial({
transparent : true,
blending : THREE.AdditiveBlending,
opacity : 0.05,
opacity : 0.5,
side : THREE.DoubleSide
}));
this.tailMesh.scale.multiplyScalar(1.1);
Expand Down
21 changes: 21 additions & 0 deletions static/js/materials/TailMaterial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require('./ShaderMaterial');
var ShaderMaterial = App.ShaderMaterial;
var uniforms = THREE.UniformsLib;

App.TailMaterial = TailMaterial;
function TailMaterial(parameters) {
parameters = parameters || {};
parameters.map = true;
ShaderMaterial.call(this, parameters);
}

TailMaterial.prototype = Object.create(ShaderMaterial.prototype);

TailMaterial.prototype.shader = {
vertexShader : 'basic-vert',
fragmentShader : 'tail-frag',

uniforms : THREE.UniformsUtils.merge([
uniforms.common
])
};
36 changes: 36 additions & 0 deletions static/js/shaders/tail-frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
uniform vec3 diffuse;
uniform float opacity;

{{{chunks.color_pars_fragment}}}
{{{chunks.map_pars_fragment}}}
{{{chunks.alphamap_pars_fragment}}}
{{{chunks.lightmap_pars_fragment}}}
{{{chunks.envmap_pars_fragment}}}
{{{chunks.fog_pars_fragment}}}
{{{chunks.shadowmap_pars_fragment}}}
{{{chunks.specularmap_pars_fragment}}}
{{{chunks.logdepthbuf_pars_fragment}}}

void main() {
gl_FragColor = vec4(diffuse, opacity);

{{{chunks.logdepthbuf_fragment}}}
{{{chunks.map_fragment}}}
{{{chunks.alphamap_fragment}}}
{{{chunks.alphatest_fragment}}}
{{{chunks.specularmap_fragment}}}
{{{chunks.lightmap_fragment}}}
{{{chunks.color_fragment}}}

vec2 uv = vUv;
float color = (sin(uv.y * 1000.0) - sin((1.0 - uv.x) * 3.0 + 1.2)) * uv.y;

gl_FragColor = vec4(vec3(color), color * opacity);

{{{chunks.envmap_fragment}}}
{{{chunks.shadowmap_fragment}}}

{{{chunks.linear_to_gamma_fragment}}}

{{{chunks.fog_fragment}}}
}

0 comments on commit bb4885e

Please sign in to comment.