Comments (11)
Hey! Thanks for using this!
there are a couple reasons why it wouldn’t work:
- You have to use the output variables provided by CustomShaderMaterial. They can be found here: https://github.com/FarazzShaikh/THREE-CustomShaderMaterial#output-variables
- MeshPhysicalMaterial requires Lights in the scene, so make sure you have lights
from three-customshadermaterial.
I changed shaders to use csm_ variables but no change.
I do have lights, PhysicalMaterial shows empty.
With ShaderMaterial I can see red cube. uTime is not coming through
export const vertex =`
precision mediump float;
uniform float uTime;
void main(){
vec4 pos = vec4(position, 1.0);
vec4 modelPosition = modelMatrix * pos;
vec4 viewPosition = viewMatrix * modelPosition;
vec4 projectedPosition = projectionMatrix * viewPosition;
csm_Position = position;
}
`
export const fragment = `
precision mediump float;
uniform float uTime;
void main() {
vec3 color = vec3(0.0, 0.0, sin(uTime));
csm_DiffuseColor = vec4(color, 1.0);
}
`
export const LandingPage = ():JSX.Element => {
return <div className="landing-container">
<div className='canvas-container'>
<Canvas>
<ambientLight/>
<pointLight position={[2, 0, 0]} intensity={10}/>
<Box position={[1.2, 0, 0]} />
</Canvas>
</div>
</div>
}
from three-customshadermaterial.
I added lights like in your example, I do see it now with physical material. And uTIme is working
from three-customshadermaterial.
If I may ask, how can i map texture to this material ?
from three-customshadermaterial.
This is what I tried to to for texture
function Box(props: JSX.IntrinsicElements['mesh']) {
const materialRef = useRef<CustomShaderMaterialType | null>(null)
const texture = new THREE.TextureLoader
const projects = texture.load('/1.jpg')
console.log(projects)
useFrame(({clock}) => {
if (materialRef.current) {
materialRef.current.uniforms.uTime.value = clock.getElapsedTime()
}
})
return (
<mesh>
<boxGeometry args={[1, 1, 1]} />
<CustomShaderMaterial
ref={materialRef}
baseMaterial={MeshPhysicalMaterial}
vertexShader={vertex}
fragmentShader={fragment}
uniforms={{
uTime: {
value: 0,
},
uTexture: {
value: projects
}
}}
flatShading
map={projects}
// ...
/>
</mesh>
)
}
export const vertex =`
precision mediump float;
uniform float uTime;
varying vec2 vUv;
void main(){
vUv = uv;
csm_Position = position;
}
`
export const fragment = `
precision mediump float;
uniform float uTime;
uniform sampler2D uTexture;
varying vec2 vUv;
void main() {
vec3 color = vec3(0.0, 0.0, sin(uTime * 0.1));
csm_DiffuseColor = texture2D(uTexture, vUv);
}
`
I get error in vertex shader, it's saying redefinition of vUv ?
from three-customshadermaterial.
seems like vUv was a sepcial variable ? I changed it to vTUv and It worked.
from three-customshadermaterial.
Glad it worked!
yes vUv is defined by Physical material, since this is extending that, you can’t reuse it
from three-customshadermaterial.
Offtopic but, im learning GLSL shaders right now and I'm following a tutorial.
Using step function I should be drawing a yellow circle in the middle of my texture, however I get screen all black when I use this fragment shader.
export const vertex =`
precision mediump float;
uniform float uTime;
varying vec2 v_uv;
varying vec3 v_position;
void main(){
v_position = position;
v_uv = uv;
csm_Position = position;
}
`
export const fragment = `
precision mediump float;
uniform float uTime;
uniform sampler2D uTexture;
varying vec2 v_uv;
varying vec3 v_position;
void main() {
float inCircle = 1.0 - step(0.5, length(v_position.xy));
vec3 color = vec3(1.0, 1.0, 0.0) * inCircle;
csm_DiffuseColor = texture2D(uTexture, v_uv) * vec4(color, 1.0);
}
`
what is csm_DiffuseColor doing extra if it is not just gl_FragColor ?
from three-customshadermaterial.
As it says, it’s just the “diffuse color”, this way Physical material’s Roughness, metalness, etc still work when you override the color.
option to override gl_FragColor will be added soon but it would defeat the purpose of this material.
from three-customshadermaterial.
Hi again, thought I'd write here instead of opening a new issue.
Im using drei to render Text and Text component can take a shader property like so
const AddText = () => {
return <mesh>
<Text
color="red"
anchorX="center"
anchorY="middle"
material={CustomShaderMaterial}
>
HELLO
</Text>
</mesh>
}
Problem is that it expects material to come from one of THREE materials and typescript wont recognize CSM as valid, error i get is that
Type 'ForwardRefExoticComponent<Pick<iCSMAllProps, "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "children" | "key" | "onUpdate" | "dispose" | "type" | "id" | "uuid" | "name" | ... 116 more ... | "uniforms"> & RefAttributes<...>>' is not assignable to type 'Material | Material[] | undefined'.
Type 'ForwardRefExoticComponent<Pick<iCSMAllProps, "attach" | "attachArray" | "attachObject" | "attachFns" | "args" | "children" | "key" | "onUpdate" | "dispose" | "type" | "id" | "uuid" | "name" | ... 116 more ... | "uniforms"> & RefAttributes<...>>' is missing the following properties from type 'Material[]': pop, push, concat, join, and 28 more.ts(2322)
The expected type comes from property 'material' which is declared here on type 'IntrinsicAttributes & Pick<Omit<ExtendedColors<Overwrite<Partial<Mesh<BufferGeometry, Material | Material[]>>, NodeProps<Mesh<BufferGeometry, Material | Material[]>, typeof Mesh>>>, NonFunctionKeys<...>> & { ...; } & EventHandlers & { ...; }, "attach" | ... 111 more ... | "debugSDF"> & RefAttributes<...>'
is there a way I could make this attachment happen ?
from three-customshadermaterial.
Are you using CSM From three-custom-shader-material/vanilla
? You must use the
CSM class from there if you want to use it imperatively
CSM extends the Material
base class like all other THREE materials, so there’s no reason it shouldn’t work
from three-customshadermaterial.
Related Issues (20)
- Can you disable projection in the vertex shader? HOT 3
- CustomShaderMaterial error HOT 6
- Add csm_Bump? HOT 2
- If the base material has a map, a CSM from it throws an error on three >= 0.151.0 HOT 1
- Shader compilation failure if csm_Feature used is not compatible with base material HOT 2
- Warning: Function copy already exists on CSM, renaming to base_copy HOT 2
- Support macro defines like THREE.ShaderMaterial HOT 1
- Waves example seems to be broken HOT 3
- Extended meshBasicMaterial does not have access to cameraPosition uniform HOT 3
- Problem with using csm_PositionRaw and InstancedMesh HOT 9
- TresJs implementation HOT 2
- How to change the opacity of extended material ? HOT 3
- Couldn't extend `<MeshReflectorMaterial/>` from `drei` HOT 1
- Feature request addition of transmision and thickness maps HOT 1
- Cannot use both csm_DiffuseColor and csm_FragColor in if/else HOT 3
- Extending ShadowMaterial HOT 22
- Accessing csm_FragColor values in if statement causes white rendering HOT 3
- Failed to resolve module specifier "crypto" HOT 2
- Textures HOT 3
- Broken examples HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from three-customshadermaterial.