mirror of
https://github.com/overte-org/overte.git
synced 2025-07-07 11:10:42 +02:00
81 lines
2.8 KiB
Text
81 lines
2.8 KiB
Text
<@include gpu/Config.slh@>
|
|
<$VERSION_HEADER$>
|
|
// Generated on <$_SCRIBE_DATE$>
|
|
//
|
|
// drawWorkloadProxy.vert
|
|
// vertex shader
|
|
//
|
|
// Created by Sam Gateau on 6/29/2015.
|
|
// Copyright 2015 High Fidelity, Inc.
|
|
// Copyright 2024 Overte e.V.
|
|
//
|
|
// Distributed under the Apache License, Version 2.0.
|
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
//
|
|
|
|
<@include gpu/Transform.slh@>
|
|
<$declareStandardTransform()$>
|
|
|
|
<@include WorkloadResource.slh@>
|
|
<$declareWorkloadProxies()$>
|
|
|
|
|
|
layout(location=0) out vec4 varColor;
|
|
layout(location=1) out vec3 varTexcoord;
|
|
layout(location=2) out vec3 varEyePos;
|
|
layout(location=3) out vec4 _prevPositionCS;
|
|
|
|
vec4 getPosition(WorkloadProxy proxy, vec4 spriteVert, vec4 proxyPosEye) {
|
|
vec3 dirZ = -normalize(proxyPosEye.xyz);
|
|
vec3 dirX = normalize(cross(vec3(0.0, 1.0, 0.0), dirZ));
|
|
vec3 dirY = vec3(0.0, 1.0, 0.0);
|
|
// Workaround for Nvidia driver bug
|
|
vec4 pos = vec4(1.0, 1.0, 1.0, 1.0);
|
|
pos.x = proxyPosEye.x + proxy.sphere.w * ( dirX.x * spriteVert.x + dirY.x * spriteVert.y + dirZ.x * spriteVert.z);
|
|
pos.y = proxyPosEye.y + proxy.sphere.w * ( dirX.y * spriteVert.x + dirY.y * spriteVert.y + dirZ.y * spriteVert.z);
|
|
pos.z = proxyPosEye.z + proxy.sphere.w * ( dirX.z * spriteVert.x + dirY.z * spriteVert.y + dirZ.z * spriteVert.z);
|
|
return pos;
|
|
//return vec4(proxyPosEye.xyz + proxy.sphere.w * (dirX * spriteVert.x + dirY * spriteVert.y /* + dirZ * spriteVert.z*/), 1.0);
|
|
}
|
|
|
|
void main(void) {
|
|
const vec4 UNIT_SPRITE[3] = vec4[3](
|
|
vec4(-1.0, -1.0, 0.0, 1.0),
|
|
vec4(3.0, -1.0, 0.0, 1.0),
|
|
vec4(-1.0, 3.0, 0.0, 1.0)
|
|
);
|
|
const int UNIT_SPRITE_INDICES[3] = int[3](
|
|
0, 1, 2
|
|
);
|
|
int proxyID = gl_VertexID / 3;
|
|
int vertexID = gl_VertexID - proxyID * 3;
|
|
|
|
vec4 spriteVert = UNIT_SPRITE[UNIT_SPRITE_INDICES[vertexID]];
|
|
|
|
WorkloadProxy proxy = getWorkloadProxy(proxyID);
|
|
vec4 proxyPosWorld = vec4(proxy.sphere.xyz, 1.0);
|
|
|
|
// standard transform, bring proxy in view space
|
|
TransformCamera cam = getTransformCamera();
|
|
TransformObject obj = getTransformObject();
|
|
vec4 proxyPosEye;
|
|
vec4 prevProxyPosEye;
|
|
<$transformModelToEyePosAndPrevEyePos(cam, obj, proxyPosWorld, proxyPosEye, prevProxyPosEye)$>
|
|
|
|
// Define the billboarded space
|
|
vec4 pos = getPosition(proxy, spriteVert, proxyPosEye);
|
|
vec4 prevPos = getPosition(proxy, spriteVert, prevProxyPosEye);
|
|
|
|
varEyePos = pos.xyz;
|
|
varTexcoord = spriteVert.xyz;
|
|
<$transformEyeToClipPos(cam, pos, gl_Position)$>
|
|
<$transformPrevEyeToPrevClipPos(cam, prevPos, _prevPositionCS)$>;
|
|
|
|
// Convert region to color
|
|
int region = floatBitsToInt(proxy.region.x);
|
|
region = (0x000000FF & region);
|
|
|
|
varColor = vec4(REGION_COLOR[region].xyz, proxy.sphere.w);
|
|
|
|
gl_Position = mix(gl_Position, vec4(0.0), float(region == 4));
|
|
}
|