• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#version 460
2uniform int uTDInstanceIDOffset;
3uniform int uTDNumInstances;
4uniform float uTDAlphaTestVal;
5#define TD_NUM_COLOR_BUFFERS 1
6#define TD_NUM_LIGHTS 0
7#define TD_NUM_SHADOWED_LIGHTS 0
8#define TD_NUM_ENV_LIGHTS 0
9#define TD_LIGHTS_ARRAY_SIZE 1
10#define TD_ENV_LIGHTS_ARRAY_SIZE 1
11#define TD_NUM_CAMERAS 1
12struct TDLight
13{
14	vec4 position;
15	vec3 direction;
16	vec3 diffuse;
17	vec4 nearFar;
18	vec4 lightSize;
19	vec4 misc;
20	vec4 coneLookupScaleBias;
21	vec4 attenScaleBiasRoll;
22	mat4 shadowMapMatrix;
23	mat4 shadowMapCamMatrix;
24	vec4 shadowMapRes;
25	mat4 projMapMatrix;
26};
27struct TDEnvLight
28{
29	vec3 color;
30	mat3 rotate;
31};
32layout(std140) uniform TDLightBlock
33{
34	TDLight	uTDLights[TD_LIGHTS_ARRAY_SIZE];
35};
36layout(std140) uniform TDEnvLightBlock
37{
38	TDEnvLight	uTDEnvLights[TD_ENV_LIGHTS_ARRAY_SIZE];
39};
40layout(std430) readonly restrict buffer TDEnvLightBuffer
41{
42	vec3 shCoeffs[9];
43} uTDEnvLightBuffers[TD_ENV_LIGHTS_ARRAY_SIZE];
44struct TDPhongResult
45{
46	vec3 diffuse;
47	vec3 specular;
48	vec3 specular2;
49	float shadowStrength;
50};
51struct TDPBRResult
52{
53	vec3 diffuse;
54	vec3 specular;
55	float shadowStrength;
56};
57struct TDMatrix
58{
59	mat4 world;
60	mat4 worldInverse;
61	mat4 worldCam;
62	mat4 worldCamInverse;
63	mat4 cam;
64	mat4 camInverse;
65	mat4 camProj;
66	mat4 camProjInverse;
67	mat4 proj;
68	mat4 projInverse;
69	mat4 worldCamProj;
70	mat4 worldCamProjInverse;
71	mat4 quadReproject;
72	mat3 worldForNormals;
73	mat3 camForNormals;
74	mat3 worldCamForNormals;
75};
76layout(std140) uniform TDMatricesBlock {
77	TDMatrix uTDMats[TD_NUM_CAMERAS];
78};
79struct TDCameraInfo
80{
81	vec4 nearFar;
82	vec4 fog;
83	vec4 fogColor;
84	int renderTOPCameraIndex;
85};
86layout(std140) uniform TDCameraInfoBlock {
87	TDCameraInfo uTDCamInfos[TD_NUM_CAMERAS];
88};
89struct TDGeneral
90{
91	vec4 ambientColor;
92	vec4 nearFar;
93	vec4 viewport;
94	vec4 viewportRes;
95	vec4 fog;
96	vec4 fogColor;
97};
98layout(std140) uniform TDGeneralBlock {
99	TDGeneral uTDGeneral;
100};
101
102layout(binding = 15) uniform samplerBuffer sTDInstanceT;
103layout(binding = 16) uniform samplerBuffer sTDInstanceTexCoord;
104layout(binding = 17) uniform samplerBuffer sTDInstanceColor;
105#define TD_NUM_BONES 0
106vec4 TDWorldToProj(vec4 v);
107vec4 TDWorldToProj(vec3 v);
108vec4 TDWorldToProj(vec4 v, vec3 uv);
109vec4 TDWorldToProj(vec3 v, vec3 uv);
110int TDPickID();
111int TDInstanceID();
112int TDCameraIndex();
113vec3 TDUVUnwrapCoord();
114vec3 TDInstanceTexCoord(int index, vec3 t) {
115	vec3 v;
116	int coord = index;
117	vec4 samp = texelFetch(sTDInstanceTexCoord, coord);
118	v[0] = t.s;
119	v[1] = t.t;
120	v[2] = samp[0];
121    t.stp = v.stp;
122	return t;
123}
124bool TDInstanceActive(int index) {
125	index -= uTDInstanceIDOffset;
126	float v;
127	int coord = index;
128	vec4 samp = texelFetch(sTDInstanceT, coord);
129	v = samp[0];
130	return v != 0.0;
131}
132vec3 iTDInstanceTranslate(int index, out bool instanceActive) {
133	int origIndex = index;
134	index -= uTDInstanceIDOffset;
135	vec3 v;
136	int coord = index;
137	vec4 samp = texelFetch(sTDInstanceT, coord);
138	v[0] = samp[1];
139	v[1] = samp[2];
140	v[2] = samp[3];
141	instanceActive = samp[0] != 0.0;
142	return v;
143}
144vec3 TDInstanceTranslate(int index) {
145	index -= uTDInstanceIDOffset;
146	vec3 v;
147	int coord = index;
148	vec4 samp = texelFetch(sTDInstanceT, coord);
149	v[0] = samp[1];
150	v[1] = samp[2];
151	v[2] = samp[3];
152	return v;
153}
154mat3 TDInstanceRotateMat(int index) {
155	index -= uTDInstanceIDOffset;
156	vec3 v = vec3(0.0, 0.0, 0.0);
157	mat3 m = mat3(1.0);
158{
159	mat3 r;
160}
161	return m;
162}
163vec3 TDInstanceScale(int index) {
164	index -= uTDInstanceIDOffset;
165	vec3 v = vec3(1.0, 1.0, 1.0);
166	return v;
167}
168vec3 TDInstancePivot(int index) {
169	index -= uTDInstanceIDOffset;
170	vec3 v = vec3(0.0, 0.0, 0.0);
171	return v;
172}
173vec3 TDInstanceRotTo(int index) {
174	index -= uTDInstanceIDOffset;
175	vec3 v = vec3(0.0, 0.0, 1.0);
176	return v;
177}
178vec3 TDInstanceRotUp(int index) {
179	index -= uTDInstanceIDOffset;
180	vec3 v = vec3(0.0, 1.0, 0.0);
181	return v;
182}
183mat4 TDInstanceMat(int id) {
184	bool instanceActive = true;
185	vec3 t = iTDInstanceTranslate(id, instanceActive);
186	if (!instanceActive)
187	{
188		return mat4(0.0);
189	}
190	mat4 m = mat4(1.0);
191	{
192		vec3 tt = t;
193		m[3][0] += m[0][0]*tt.x;
194		m[3][1] += m[0][1]*tt.x;
195		m[3][2] += m[0][2]*tt.x;
196		m[3][3] += m[0][3]*tt.x;
197		m[3][0] += m[1][0]*tt.y;
198		m[3][1] += m[1][1]*tt.y;
199		m[3][2] += m[1][2]*tt.y;
200		m[3][3] += m[1][3]*tt.y;
201		m[3][0] += m[2][0]*tt.z;
202		m[3][1] += m[2][1]*tt.z;
203		m[3][2] += m[2][2]*tt.z;
204		m[3][3] += m[2][3]*tt.z;
205	}
206	return m;
207}
208mat3 TDInstanceMat3(int id) {
209	mat3 m = mat3(1.0);
210	return m;
211}
212mat3 TDInstanceMat3ForNorm(int id) {
213	mat3 m = TDInstanceMat3(id);
214	return m;
215}
216vec4 TDInstanceColor(int index, vec4 curColor) {
217	index -= uTDInstanceIDOffset;
218	vec4 v;
219	int coord = index;
220	vec4 samp = texelFetch(sTDInstanceColor, coord);
221	v[0] = samp[0];
222	v[1] = samp[1];
223	v[2] = samp[2];
224	v[3] = 1.0;
225	curColor[0] = v[0];
226;
227	curColor[1] = v[1];
228;
229	curColor[2] = v[2];
230;
231	return curColor;
232}
233vec4 TDInstanceDeform(int id, vec4 pos) {
234	pos = TDInstanceMat(id) * pos;
235	return uTDMats[TDCameraIndex()].world * pos;
236}
237
238vec3 TDInstanceDeformVec(int id, vec3 vec)
239{
240	mat3 m = TDInstanceMat3(id);
241	return mat3(uTDMats[TDCameraIndex()].world) * (m * vec);
242}
243vec3 TDInstanceDeformNorm(int id, vec3 vec)
244{
245	mat3 m = TDInstanceMat3ForNorm(id);
246	return mat3(uTDMats[TDCameraIndex()].worldForNormals) * (m * vec);
247}
248vec4 TDInstanceDeform(vec4 pos) {
249	return TDInstanceDeform(TDInstanceID(), pos);
250}
251vec3 TDInstanceDeformVec(vec3 vec) {
252	return TDInstanceDeformVec(TDInstanceID(), vec);
253}
254vec3 TDInstanceDeformNorm(vec3 vec) {
255	return TDInstanceDeformNorm(TDInstanceID(), vec);
256}
257bool TDInstanceActive() { return TDInstanceActive(TDInstanceID()); }
258vec3 TDInstanceTranslate() { return TDInstanceTranslate(TDInstanceID()); }
259mat3 TDInstanceRotateMat() { return TDInstanceRotateMat(TDInstanceID()); }
260vec3 TDInstanceScale() { return TDInstanceScale(TDInstanceID()); }
261mat4 TDInstanceMat() { return TDInstanceMat(TDInstanceID());
262 }
263mat3 TDInstanceMat3() { return TDInstanceMat3(TDInstanceID());
264}
265vec3 TDInstanceTexCoord(vec3 t) {
266	return TDInstanceTexCoord(TDInstanceID(), t);
267}
268vec4 TDInstanceColor(vec4 curColor) {
269	return TDInstanceColor(TDInstanceID(), curColor);
270}
271vec4 TDSkinnedDeform(vec4 pos) { return pos; }
272
273vec3 TDSkinnedDeformVec(vec3 vec) { return vec; }
274
275vec3 TDFastDeformTangent(vec3 oldNorm, vec4 oldTangent, vec3 deformedNorm)
276{   return oldTangent.xyz;   }
277mat4 TDBoneMat(int index) {
278   return mat4(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);
279}
280vec4 TDDeform(vec4 pos) {
281    pos = TDSkinnedDeform(pos);
282    pos = TDInstanceDeform(pos);
283    return pos;
284}
285
286vec4 TDDeform(int instanceID, vec3 p) {
287	vec4 pos = vec4(p, 1.0);
288    pos = TDSkinnedDeform(pos);
289    pos = TDInstanceDeform(instanceID, pos);
290    return pos;
291}
292
293vec4 TDDeform(vec3 pos) {
294	return TDDeform(TDInstanceID(), pos);
295}
296
297vec3 TDDeformVec(int instanceID, vec3 vec) {
298    vec = TDSkinnedDeformVec(vec);
299    vec = TDInstanceDeformVec(instanceID, vec);
300    return vec;
301}
302
303vec3 TDDeformVec(vec3 vec) {
304	return TDDeformVec(TDInstanceID(), vec);
305}
306
307vec3 TDDeformNorm(int instanceID, vec3 vec) {
308    vec = TDSkinnedDeformVec(vec);
309    vec = TDInstanceDeformNorm(instanceID, vec);
310    return vec;
311}
312
313vec3 TDDeformNorm(vec3 vec) {
314	return TDDeformNorm(TDInstanceID(), vec);
315}
316
317vec3 TDSkinnedDeformNorm(vec3 vec) {
318    vec = TDSkinnedDeformVec(vec);
319	return vec;
320}
321