Skip to content

Instantly share code, notes, and snippets.

@jeanlescure
Last active January 22, 2025 14:07
Show Gist options
  • Save jeanlescure/e27c93b73a10b64e85e4 to your computer and use it in GitHub Desktop.
Save jeanlescure/e27c93b73a10b64e85e4 to your computer and use it in GitHub Desktop.

Revisions

  1. jeanlescure revised this gist Aug 24, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion TransformationShader.js
    Original file line number Diff line number Diff line change
    @@ -53,7 +53,7 @@ THREE.TransformationShader = {
    "vec4(0.0,0.0,0.0,1.0));",

    "mat4 rZPos = mat4(vec4(cos(rotationZ),-sin(rotationZ),0.0,0.0),",
    "vec4(sin(rotationY),cos(rotationZ),0.0,0.0),",
    "vec4(sin(rotationZ),cos(rotationZ),0.0,0.0),",
    "vec4(0.0,0.0,1.0,0.0),",
    "vec4(0.0,0.0,0.0,1.0));",

  2. jeanlescure revised this gist Aug 17, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion TransformationShader.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    THREE.TransformationShader = {
    defines: {},
    uniforms: {
    uniforms: {

    "tDiffuse": { type: "t", value: texture },
    "opacity": { type: "f", value: 1.0 },
  3. jeanlescure revised this gist Aug 6, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions TransformationShader.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    THREE.TransformationShader = ( {
    THREE.TransformationShader = {
    defines: {},
    uniforms: {

    @@ -87,4 +87,4 @@ THREE.TransformationShader = ( {
    "}"

    ].join("\n")
    });
    };
  4. jeanlescure created this gist Aug 6, 2015.
    90 changes: 90 additions & 0 deletions TransformationShader.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,90 @@
    THREE.TransformationShader = ( {
    defines: {},
    uniforms: {

    "tDiffuse": { type: "t", value: texture },
    "opacity": { type: "f", value: 1.0 },
    "translationX": { type: "f", value: 1.0 },
    "translationY": { type: "f", value: 1.0 },
    "translationZ": { type: "f", value: 1.0 },
    "scaleX": { type: "f", value: 1.0 },
    "scaleY": { type: "f", value: 1.0 },
    "scaleZ": { type: "f", value: 1.0 },
    "rotationX": { type: "f", value: 0.75 },
    "rotationY": { type: "f", value: 0.75 },
    "rotationZ": { type: "f", value: 0.75 }

    },

    vertexShader: [

    "uniform float translationX;",
    "uniform float translationY;",
    "uniform float translationZ;",
    "uniform float scaleX;",
    "uniform float scaleY;",
    "uniform float scaleZ;",
    "uniform float rotationX;",
    "uniform float rotationY;",
    "uniform float rotationZ;",

    "varying vec2 vUv;",
    "varying mat4 vPosition;",

    "void main() {",

    "vUv = uv;",

    // Translate
    "mat4 tPos = mat4(vec4(1.0,0.0,0.0,0.0),",
    "vec4(0.0,1.0,0.0,0.0),",
    "vec4(0.0,0.0,1.0,0.0),",
    "vec4(translationX,translationY,translationZ,1.0));",

    // Rotate
    "mat4 rXPos = mat4(vec4(1.0,0.0,0.0,0.0),",
    "vec4(0.0,cos(rotationX),-sin(rotationX),0.0),",
    "vec4(0.0,sin(rotationX),cos(rotationX),0.0),",
    "vec4(0.0,0.0,0.0,1.0));",

    "mat4 rYPos = mat4(vec4(cos(rotationY),0.0,sin(rotationY),0.0),",
    "vec4(0.0,1.0,0.0,0.0),",
    "vec4(-sin(rotationY),0.0,cos(rotationY),0.0),",
    "vec4(0.0,0.0,0.0,1.0));",

    "mat4 rZPos = mat4(vec4(cos(rotationZ),-sin(rotationZ),0.0,0.0),",
    "vec4(sin(rotationY),cos(rotationZ),0.0,0.0),",
    "vec4(0.0,0.0,1.0,0.0),",
    "vec4(0.0,0.0,0.0,1.0));",

    // Scale
    "mat4 sPos = mat4(vec4(scaleX,0.0,0.0,0.0),",
    "vec4(0.0,scaleY,0.0,0.0),",
    "vec4(0.0,0.0,scaleZ,0.0),",
    "vec4(0.0,0.0,0.0,1.0));",

    "vPosition = tPos * rXPos * rZPos * rYPos * sPos;",

    "gl_Position = projectionMatrix * modelViewMatrix * vPosition * vec4(position,1.0);",

    "}"

    ].join("\n"),

    fragmentShader: [

    "uniform float opacity;",

    "uniform sampler2D tDiffuse;",

    "varying vec2 vUv;",

    "void main() {",

    "vec4 texel = texture2D( tDiffuse, vUv );",
    "gl_FragColor = opacity * texel;",

    "}"

    ].join("\n")
    });