Making two material with same shader

I have one material with shader code and I tried to make that shader inside a function so that it can be used for another material

I have two planes with the same characteristics only difference is what color to pass in each plane Mesh.

I am creating material with beforeCompileShader and both of them are using same function

const beforeCompileShader = (shader) => {};

  const tankGeometry = new THREE.PlaneGeometry(50, 90);
  tankMaterial = new THREE.MeshBasicMaterial({
    onBeforeCompile: (shader) => {
    },
  });

I was expecting different color in two plane but i am getting same color
Any help please

Works well for me. :thinking:
Create a new material with new instance of the uniform for colors.

I realised that i need colormap texture rather than few color values so i tried to pass that into shader but i am not able to. I am trying for last 4/5 hours but not able to find what is wrong in this

I am sorry for bugging you but i am so lost in this :frowning:

I have passed the texture with uniform and am also sampling that inside the fragment shader.

Do I have to do something more because when i use rawshader, i only do this.

Is there anything extra that i need to do in beforeCompile?

What do you expect, using these lines?
You sample the same color into two variables, as you use the same uv coordinates.

I wanted to get at least something because right now I am getting black ( for debugging)

This is the image

I wanted to sample the center of the image

Where is that line, or something similar, in your code: shader.uniforms.heatTexture = tankMaterial.userData.uniforms.heatTexture;?

A reminder: It is better to use a pure gradient texture without back border. Otherwise you may accidentally pick the color of a border pixel.

1 Like

Oh yes I had not passed the uniform value in

(shader)=> {
}

Thank you so much, it never occurred to my mind that I have to pass there as well.

Oh god !! thank you so much. i was so busted

Thank you, the posted image is a screenshot and the colored image in that screenshot is the colormap image. Thank you :smiley:

1 Like

I leave it here just in case :slight_smile: https://codepen.io/prisoner849/full/wvxOYWV

3 Likes

I never realized that fractal brownian motion (FBM) could be used to create such a beautiful effect in tanks.

This water-flowing effect is so so beautiful.

Thank you so so much !!!

Hi @prisoner849 I realized that i want particle( i mean particle with the colors) with it’s the expected movement inside the simulation container.

To achieve that i tried to make particle falling but I am not able to !! Specially making particle from one end to another and transitioning in betwen

What simulation? What particles with the colors? What code? Any working live code examples and/or explanatory pics/vids?
Sorry, I’m not that good at telepathy ¯\_(ツ)_/¯

I am sorry for not being clear

THREE.Path() of multiple half-circles (.absarc())

Didn’t get what you mean.

Depents on your goal and needs. Use THREE.Points(), or a plane mesh with a matrial with an animated looped texture with small circles, or a modified material, where you draw small circles in shaders.

Creativity is up to you :slight_smile: