1
0
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:
Sander Moolin 2021-03-12 09:29:10 -05:00
parent faefaef1db
commit 5bd7bcc70f
2 changed files with 26 additions and 2 deletions

View File

@ -1,9 +1,12 @@
import { ShaderMaterial } from 'three'
import { propsValues, defaultFragmentShader, defaultVertexShader } from '../tools.js';
export default {
inject: ['three', 'mesh'],
props: {
uniforms: Object,
vertexShader: String,
fragmentShader: String,
vertexShader: { type: String, default: defaultVertexShader },
fragmentShader: { type: String, default: defaultFragmentShader },
},
created() {
this.createMaterial();
@ -13,6 +16,11 @@ export default {
unmounted() {
this.material.dispose();
},
methods: {
createMaterial() {
this.material = new ShaderMaterial(propsValues(this.$props));
},
},
render() {
return [];
},

View File

@ -73,3 +73,19 @@ function getMatcapFormatString(format) {
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);
}`;