-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCahvoreDistortionMaterial.js
157 lines (99 loc) · 2.8 KB
/
CahvoreDistortionMaterial.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { ShaderMaterial } from 'three';
import { cahvoreUnprojectShader, CAHV, CAHVOR, CAHVORE } from './shader/cahvoreDistortionShader.js';
import { getLinearFrustumInfo, frameBoundsToProjectionMatrix } from './utils.js';
export class CahvoreDistortionMaterial extends ShaderMaterial {
get checkerboard() {
return Boolean( this.defines.CHECKERBOARD );
}
set checkerboard( value ) {
const v = Number( value );
if ( this.defines.CHECKERBOARD !== v ) {
this.defines.CHECKERBOARD = v;
this.needsUpdate = true;
}
}
get passthrough() {
return Boolean( this.defines.PASSTHROUGH );
}
set passthrough( value ) {
const v = Number( value );
if ( this.defines.PASSTHROUGH !== v ) {
this.defines.PASSTHROUGH = v;
this.needsUpdate = true;
}
}
constructor( parameters ) {
super( cahvoreUnprojectShader );
[ 'C', 'A', 'H', 'V', 'O', 'R', 'E', 'maxFoV', 'inverseFrame', 'cahvoreProjectionMatrix' ]
.forEach( key => {
Object.defineProperty( this, key, {
get() {
return this.uniforms[ key ].value;
},
} );
} );
[ 'imageWidth', 'imageHeight', 'linearity' ]
.forEach( key => {
Object.defineProperty( this, key, {
get() {
return this.uniforms[ key ].value;
},
set( v ) {
this.uniforms[ key ].value = v;
},
} );
} );
Object.defineProperty( this, 'map', {
get() {
return this.uniforms[ 'map' ].value;
},
set( v ) {
if ( this.uniforms[ 'map' ] === null ) {
this.needsUpdate = true;
}
this.uniforms[ 'map' ].value = v;
},
} );
this.setValues( parameters );
}
setModelType( modelType ) {
if ( typeof modelType === 'string' ) {
switch ( modelType.toLowerCase() ) {
case 'cahv':
this.setModelType( CAHV );
break;
case 'cahvor':
this.setModelType( CAHVOR );
break;
case 'cahvore':
this.setModelType( CAHVORE );
break;
default:
throw new Error( `CahvoreDistortionMaterial: Camera model type ${ modelType } not supported` );
}
} else {
const defines = this.defines;
if ( defines.MODEL_TYPE !== modelType ) {
this.needsUpdate = true;
}
defines.MODEL_TYPE = modelType;
}
}
setFromCameraModel( model ) {
this.setModelType( model.type );
this.C.copy( model.C );
this.A.copy( model.A );
this.H.copy( model.H );
this.V.copy( model.V );
if ( model.O ) this.O.copy( model.O );
if ( model.R ) this.R.copy( model.R );
if ( model.E ) this.E.copy( model.E );
this.imageWidth = model.width;
this.imageHeight = model.height;
this.linearity = model.linearity;
const info = getLinearFrustumInfo( model );
const { maxFrameBounds, frame } = info;
this.inverseFrame.copy( frame ).invert();
frameBoundsToProjectionMatrix( maxFrameBounds, 1.0, 2.0, this.cahvoreProjectionMatrix );
}
}