1
0
mirror of https://github.com/troisjs/trois.git synced 2024-11-24 04:12:02 +08:00

improve ShaderMaterial

This commit is contained in:
Kevin Levron 2021-03-12 23:14:49 +01:00
parent 9e062155f6
commit 3844b109f2
2 changed files with 5 additions and 6 deletions

View File

@ -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

View File

@ -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);
}`; }`;