mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
improve ShaderMaterial
This commit is contained in:
parent
9e062155f6
commit
3844b109f2
@ -5,12 +5,13 @@ import { propsValues, defaultFragmentShader, defaultVertexShader } from '../tool
|
|||||||
export default {
|
export default {
|
||||||
inject: ['three', 'mesh'],
|
inject: ['three', 'mesh'],
|
||||||
props: {
|
props: {
|
||||||
uniforms: { type: Object, default: () => {} },
|
uniforms: { type: Object, default: () => { return {}; } },
|
||||||
vertexShader: { type: String, default: defaultVertexShader },
|
vertexShader: { type: String, default: defaultVertexShader },
|
||||||
fragmentShader: { type: String, default: defaultFragmentShader },
|
fragmentShader: { type: String, default: defaultFragmentShader },
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.createMaterial();
|
this.createMaterial();
|
||||||
|
console.log(this.uniforms);
|
||||||
['vertexShader', 'fragmentShader'].forEach(p => {
|
['vertexShader', 'fragmentShader'].forEach(p => {
|
||||||
watch(() => this[p], () => {
|
watch(() => this[p], () => {
|
||||||
// recreate material if we change either shader
|
// recreate material if we change either shader
|
||||||
|
@ -77,15 +77,13 @@ function getMatcapFormatString(format) {
|
|||||||
// shader defaults
|
// shader defaults
|
||||||
export const defaultVertexShader = `
|
export const defaultVertexShader = `
|
||||||
varying vec2 vUv;
|
varying vec2 vUv;
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
vUv = uv;
|
vUv = uv;
|
||||||
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
export const defaultFragmentShader = `
|
export const defaultFragmentShader = `
|
||||||
varying vec2 vUv;
|
varying vec2 vUv;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_FragColor = vec4(vUv.x, vUv.y, 0., 1.0);
|
gl_FragColor = vec4(vUv.x, vUv.y, 0., 1.0);
|
||||||
}`;
|
}`;
|
||||||
|
Loading…
Reference in New Issue
Block a user