mirror of
https://github.com/troisjs/trois.git
synced 2024-11-24 04:12:02 +08:00
Starting default shader material
This commit is contained in:
parent
faefaef1db
commit
5bd7bcc70f
@ -1,9 +1,12 @@
|
|||||||
|
import { ShaderMaterial } from 'three'
|
||||||
|
import { propsValues, defaultFragmentShader, defaultVertexShader } from '../tools.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
inject: ['three', 'mesh'],
|
inject: ['three', 'mesh'],
|
||||||
props: {
|
props: {
|
||||||
uniforms: Object,
|
uniforms: Object,
|
||||||
vertexShader: String,
|
vertexShader: { type: String, default: defaultVertexShader },
|
||||||
fragmentShader: String,
|
fragmentShader: { type: String, default: defaultFragmentShader },
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.createMaterial();
|
this.createMaterial();
|
||||||
@ -13,6 +16,11 @@ export default {
|
|||||||
unmounted() {
|
unmounted() {
|
||||||
this.material.dispose();
|
this.material.dispose();
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
createMaterial() {
|
||||||
|
this.material = new ShaderMaterial(propsValues(this.$props));
|
||||||
|
},
|
||||||
|
},
|
||||||
render() {
|
render() {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
|
16
src/tools.js
16
src/tools.js
@ -73,3 +73,19 @@ function getMatcapFormatString(format) {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shader defaults
|
||||||
|
export const defaultVertexShader = `
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
void main(){
|
||||||
|
vUv = uv;
|
||||||
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
|
||||||
|
}`;
|
||||||
|
|
||||||
|
export const defaultFragmentShader = `
|
||||||
|
varying vec2 vUv;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_FragColor = vec4(vUv.x, vUv.y, 0., 1.0);
|
||||||
|
}`;
|
Loading…
Reference in New Issue
Block a user