This commit is contained in:
Alexander Bock
2018-02-05 17:00:05 -05:00
13 changed files with 195 additions and 419 deletions
@@ -627,13 +627,11 @@ void RenderableBillboardsCloud::initializeGL() {
_program = renderEngine.buildRenderProgram(
"RenderableBillboardsCloud",
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard2_vs.glsl"),
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard2_fs.glsl"),
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard2_gs.glsl")
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_vs.glsl"),
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_fs.glsl"),
absPath("${MODULE_DIGITALUNIVERSE}/shaders/billboard_gs.glsl")
);
//_uniformCache.projection = _program->uniformLocation("projection");
//_uniformCache.modelView = _program->uniformLocation("modelViewTransform");
_uniformCache.modelViewProjection = _program->uniformLocation(
"modelViewProjectionTransform"
);
@@ -646,7 +644,6 @@ void RenderableBillboardsCloud::initializeGL() {
_uniformCache.minBillboardSize = _program->uniformLocation("minBillboardSize");
_uniformCache.maxBillboardSize = _program->uniformLocation("maxBillboardSize");
_uniformCache.color = _program->uniformLocation("color");
//_uniformCache.sides = _program->uniformLocation("sides");
_uniformCache.alphaValue = _program->uniformLocation("alphaValue");
_uniformCache.scaleFactor = _program->uniformLocation("scaleFactor");
_uniformCache.up = _program->uniformLocation("up");
@@ -736,8 +733,7 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data,
"screenSize",
glm::vec2(OsEng.renderEngine().renderingResolution())
);
//_program->setUniform(_uniformCache.projection, projMatrix);
//_program->setUniform(_uniformCache.modelView, modelViewMatrix);
_program->setUniform(_uniformCache.modelViewProjection, projMatrix * modelViewMatrix);
_program->setUniform(
_uniformCache.cameraPos,
@@ -750,10 +746,6 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data,
)
);
//_program->setUniform("cameraPosition", data.camera.positionVec3());
//_program->setUniform("cameraLookUp", data.camera.lookUpVectorWorldSpace());
_program->setUniform(_uniformCache.renderOption, _renderOption.value());
glm::dvec4 centerScreenWorld = glm::inverse(data.camera.combinedViewMatrix()) *
glm::dvec4(0.0, 0.0, 0.0, 1.0);
@@ -763,7 +755,6 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data,
_program->setUniform(_uniformCache.minBillboardSize, _billboardMinSize); // in pixels
_program->setUniform(_uniformCache.maxBillboardSize, _billboardMaxSize); // in pixels
_program->setUniform(_uniformCache.color, _pointColor);
//_program->setUniform(_uniformCache.sides, 4);
_program->setUniform(_uniformCache.alphaValue, _alphaValue);
_program->setUniform(_uniformCache.scaleFactor, _scaleFactor);
@@ -934,7 +925,6 @@ void RenderableBillboardsCloud::render(const RenderData& data, RendererTasks&) {
glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale));
glm::dmat4 modelViewMatrix = data.camera.combinedViewMatrix() * modelMatrix;
// glm::mat4 viewMatrix = data.camera.viewMatrix();
glm::mat4 projectionMatrix = data.camera.projectionMatrix();
glm::dmat4 modelViewProjectionMatrix = glm::dmat4(projectionMatrix) *
@@ -142,7 +142,7 @@ private:
std::unique_ptr<ghoul::opengl::Texture> _spriteTexture;
std::unique_ptr<ghoul::filesystem::File> _spriteTextureFile;
std::unique_ptr<ghoul::opengl::ProgramObject> _program;
UniformCache(projection, modelView, modelViewProjection, cameraPos, cameraLookup,
UniformCache(modelViewProjection, cameraPos, cameraLookup,
renderOption, centerSceenInWorldPos, minBillboardSize, maxBillboardSize,
color, sides, alphaValue, scaleFactor, up, right, fadeInValue, screenSize,
spriteTexture, polygonTexture, hasPolygon, hasColormap) _uniformCache;
@@ -69,12 +69,12 @@ namespace {
"all point."
};
static const openspace::properties::Property::PropertyInfo ScaleFactorInfo = {
/*static const openspace::properties::Property::PropertyInfo ScaleFactorInfo = {
"ScaleFactor",
"Scale Factor",
"This value is used as a multiplicative factor that is applied to the apparent "
"size of each point."
};
};*/
static const openspace::properties::Property::PropertyInfo ColorInfo = {
"Color",
@@ -179,12 +179,12 @@ documentation::Documentation RenderableDUMeshes::Documentation() {
Optional::Yes,
TransparencyInfo.description
},
{
/*{
ScaleFactorInfo.identifier,
new DoubleVerifier,
Optional::Yes,
ScaleFactorInfo.description
},
},*/
{
DrawLabelInfo.identifier,
new BoolVerifier,
@@ -246,7 +246,7 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary)
, _hasLabel(false)
, _labelDataIsDirty(true)
, _alphaValue(TransparencyInfo, 1.f, 0.f, 1.f)
, _scaleFactor(ScaleFactorInfo, 1.f, 0.f, 64.f)
//, _scaleFactor(ScaleFactorInfo, 1.f, 0.f, 64.f)
, _textColor(
TextColorInfo,
glm::vec4(1.0f, 1.0, 1.0f, 1.f),
@@ -328,12 +328,12 @@ RenderableDUMeshes::RenderableDUMeshes(const ghoul::Dictionary& dictionary)
}
addProperty(_alphaValue);
if (dictionary.hasKey(ScaleFactorInfo.identifier)) {
/*if (dictionary.hasKey(ScaleFactorInfo.identifier)) {
_scaleFactor = static_cast<float>(
dictionary.value<double>(ScaleFactorInfo.identifier)
);
}
addProperty(_scaleFactor);
addProperty(_scaleFactor);*/
if (dictionary.hasKey(DrawLabelInfo.identifier)) {
_drawLabels = dictionary.value<bool>(DrawLabelInfo.identifier);
@@ -126,7 +126,7 @@ private:
bool _labelDataIsDirty;
properties::FloatProperty _alphaValue;
properties::FloatProperty _scaleFactor;
//properties::FloatProperty _scaleFactor;
//properties::Vec3Property _pointColor;
properties::Vec4Property _textColor;
properties::FloatProperty _textSize;
@@ -141,7 +141,7 @@ private:
std::unique_ptr<ghoul::opengl::ProgramObject> _program;
UniformCache(modelViewTransform, projectionTransform, alphaValue,
scaleFactor, color) _uniformCache;
/*scaleFactor,*/ color) _uniformCache;
std::unique_ptr<ghoul::fontrendering::FontRenderer> _fontRenderer;
std::shared_ptr<ghoul::fontrendering::Font> _font;
@@ -530,7 +530,6 @@ void RenderablePlanesCloud::initializeGL() {
"modelViewProjectionTransform"
);
_uniformCache.alphaValue = _program->uniformLocation("alphaValue");
//_uniformCache.scaleFactor = _program->uniformLocation("scaleFactor");
_uniformCache.fadeInValue = _program->uniformLocation("fadeInValue");
_uniformCache.galaxyTexture = _program->uniformLocation("galaxyTexture");
@@ -606,7 +605,6 @@ void RenderablePlanesCloud::renderPlanes(const RenderData&,
modelViewProjectionMatrix
);
_program->setUniform(_uniformCache.alphaValue, _alphaValue);
_program->setUniform(_uniformCache.scaleFactor, _scaleFactor);
_program->setUniform(_uniformCache.fadeInValue, fadeInVariable);
GLint viewport[4];
@@ -847,7 +845,6 @@ void RenderablePlanesCloud::update(const UpdateData&) {
"modelViewProjectionTransform"
);
_uniformCache.alphaValue = _program->uniformLocation("alphaValue");
_uniformCache.scaleFactor = _program->uniformLocation("scaleFactor");
_uniformCache.fadeInValue = _program->uniformLocation("fadeInValue");
_uniformCache.galaxyTexture = _program->uniformLocation("galaxyTexture");
}
@@ -1,69 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include "fragment.glsl"
in vec4 gs_colorMap;
in float vs_screenSpaceDepth;
in vec2 texCoord;
in float ta;
uniform float alphaValue;
uniform vec3 color;
uniform sampler2D spriteTexture;
uniform sampler2D polygonTexture;
uniform bool hasColorMap;
uniform bool hasPolygon;
uniform float fadeInValue;
Fragment getFragment() {
vec4 textureColor = texture(spriteTexture, texCoord);
vec4 fullColor = vec4(1.0);
if (hasColorMap) {
fullColor = vec4(gs_colorMap.rgb * textureColor.rgb, gs_colorMap.a * textureColor.a * alphaValue);
} else if (hasPolygon) {
vec4 polygon = texture(polygonTexture, texCoord);
fullColor = vec4(color.rgb * textureColor.rgb + polygon.rgb, textureColor.a * alphaValue);
} else {
fullColor = vec4(color.rgb * textureColor.rgb, textureColor.a * alphaValue);
}
fullColor.a *= fadeInValue * ta;
if (fullColor.a == 0.f) {
discard;
}
Fragment frag;
frag.color = fullColor;
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vec4(1e32, 1e32, 1e32, 1.0);
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
return frag;
}
@@ -1,191 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
#include "PowerScaling/powerScalingMath.hglsl"
layout(points) in;
layout(triangle_strip, max_vertices = 6) out;
//uniform dmat4 transformMatrix;
uniform dmat4 modelViewProjectionTransform;
uniform float scaleFactor;
uniform dvec3 up;
uniform dvec3 right;
uniform dvec3 cameraPosition;
uniform dvec3 cameraLookUp;
uniform dvec4 centerScreenInWorldPosition;
uniform int renderOption;
uniform vec2 screenSize;
uniform float maxBillboardSize;
uniform float minBillboardSize;
in vec4 colorMap[];
out vec4 gs_colorMap;
out vec2 texCoord;
out float vs_screenSpaceDepth;
out float ta;
const double PARSEC = 0.308567756e17LF;
const vec2 corners[4] = vec2[4](
vec2(0.0, 0.0),
vec2(1.0, 0.0),
vec2(1.0, 1.0),
vec2(0.0, 1.0)
);
void main() {
ta = 1.0f;
vec4 pos = gl_in[0].gl_Position;
gs_colorMap = colorMap[0];
double scaleMultiply = exp(scaleFactor/10);
dvec3 scaledRight = dvec3(0.0);
dvec3 scaledUp = dvec3(0.0);
if (renderOption == 0) {
scaledRight = scaleMultiply * right/2.0f;
scaledUp = scaleMultiply * up/2.0f;
} else if (renderOption == 1) {
dvec3 normal = normalize(cameraPosition - dvec3(pos.xyz));
dvec3 newRight = normalize(cross(cameraLookUp, normal));
dvec3 newUp = cross(normal, newRight);
scaledRight = scaleMultiply * newRight/2.0f;
scaledUp = scaleMultiply * newUp/2.0f;
} else if (renderOption == 2) {
dvec3 normal = normalize(centerScreenInWorldPosition.xyz - dvec3(pos.xyz));
dvec3 newRight = normalize(cross(cameraLookUp, normal));
dvec3 newUp = cross(normal, newRight);
scaledRight = scaleMultiply * newRight/2.0f;
scaledUp = scaleMultiply * newUp/2.0f;
}
double unit = PARSEC;
// Must be the same as the enum in RenderableBillboardsCloud.h
if (pos.w == 1.f) {
unit = 1E3;
} else if (pos.w == 2.f) {
unit = PARSEC;
} else if (pos.w == 3.f) {
unit = 1E3 * PARSEC;
} else if (pos.w == 4.f) {
unit = 1E6 * PARSEC;
} else if (pos.w == 5.f) {
unit = 1E9 * PARSEC;
} else if (pos.w == 6.f) {
unit = 306391534.73091 * PARSEC;
}
//dvec4 dpos = transformMatrix * dvec4(dvec3(pos.xyz) * unit, 1.0);
dvec4 dpos = dvec4(dvec3(pos.xyz) * unit, 1.0);
// texCoord = corners[0];
vec4 initialPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz - scaledRight - scaledUp, dpos.w)));
vs_screenSpaceDepth = initialPosition.w;
// texCoord = corners[1];
vec4 secondPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledRight - scaledUp, dpos.w)));
//texCoord = corners[2];
vec4 crossCorner = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledUp + scaledRight, dpos.w)));
// texCoord = corners[3];
vec4 thirdPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledUp - scaledRight, dpos.w)));
// Testing size:
vec4 topRight = secondPosition/secondPosition.w;
topRight = ((topRight + vec4(1.0)) / vec4(2.0)) * vec4(screenSize.x, screenSize.y, 1.0, 1.0);
vec4 bottomLeft = initialPosition/initialPosition.w;
bottomLeft = ((bottomLeft + vec4(1.0)) / vec4(2.0)) * vec4(screenSize.x, screenSize.y, 1.0, 1.0);
float height = abs(topRight.y - bottomLeft.y);
float width = abs(topRight.x - bottomLeft.x);
float var = (height + width);
if ((height > maxBillboardSize) ||
(width > maxBillboardSize)) {
// Set maximum size as Carter's instructions
float correctionScale = height > maxBillboardSize ? maxBillboardSize / (topRight.y - bottomLeft.y) :
maxBillboardSize / (topRight.x - bottomLeft.x);
scaledRight = correctionScale * scaleMultiply * right/2.0f;
scaledUp = correctionScale * scaleMultiply * up/2.0f;
initialPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz - scaledRight - scaledUp, dpos.w)));
vs_screenSpaceDepth = initialPosition.w;
secondPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledRight - scaledUp, dpos.w)));
crossCorner = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledUp + scaledRight, dpos.w)));
thirdPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledUp - scaledRight, dpos.w)));
// Fade-out
// float maxVar = 2.0f * maxBillboardSize;
// float minVar = maxBillboardSize;
// ta = 1.0f - ( (var - minVar)/(maxVar - minVar) );
// if (ta == 0.0f)
// return;
}
else if (width < 2.0f * minBillboardSize) {
//return;
float maxVar = 2.0f * minBillboardSize;
float minVar = minBillboardSize;
ta = ( (var - minVar)/(maxVar - minVar) );
if (ta == 0.0f)
return;
}
// Build primitive
texCoord = corners[0];
gl_Position = initialPosition;
EmitVertex();
texCoord = corners[1];
gl_Position = secondPosition;
EmitVertex();
texCoord = corners[2];
gl_Position = crossCorner;
EmitVertex();
EndPrimitive(); // First Triangle
texCoord = corners[0];
gl_Position = initialPosition;
EmitVertex();
texCoord = corners[2];
gl_Position = crossCorner;
EmitVertex();
texCoord = corners[3];
gl_Position = thirdPosition;
EmitVertex();
EndPrimitive(); // Second Triangle
}
@@ -1,37 +0,0 @@
/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2018 *
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
* software and associated documentation files (the "Software"), to deal in the Software *
* without restriction, including without limitation the rights to use, copy, modify, *
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be included in all copies *
* or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#version __CONTEXT__
#include "PowerScaling/powerScaling_vs.hglsl"
in vec4 in_position;
in vec4 in_colormap;
out vec4 colorMap;
void main() {
colorMap = in_colormap;
gl_Position = vec4(in_position);
}
@@ -24,41 +24,46 @@
#include "fragment.glsl"
//in vec4 gs_colorMap;
in float gs_screenSpaceDepth;
in vec4 gs_colorMap;
in float vs_screenSpaceDepth;
in vec2 texCoord;
in float ta;
//uniform bool hasColorMap;
uniform float alphaValue;
uniform vec3 color;
uniform sampler2D spriteTexture;
uniform sampler2D polygonTexture;
uniform bool hasColorMap;
uniform bool hasPolygon;
uniform float fadeInValue;
Fragment getFragment() {
vec4 textureColor = texture(spriteTexture, texCoord);
vec4 fullColor = vec4(0.0);
//if (hasColorMap) {
// fullColor = vec4(gs_colorMap.rgb * textureColor.rgb, textureColor.a);
// }
//else {
fullColor = vec4(color.rgb * textureColor.rgb, textureColor.a);
// }
//fullColor.a *= alphaValue;
//if (fullColor.a == 0) {
// discard;
//}
//fullColor = vec4(textureColor.rgb, 1.0);
fullColor = vec4(1.0);
vec4 fullColor = vec4(1.0);
if (hasColorMap) {
fullColor = vec4(gs_colorMap.rgb * textureColor.rgb, gs_colorMap.a * textureColor.a * alphaValue);
} else if (hasPolygon) {
vec4 polygon = texture(polygonTexture, texCoord);
fullColor = vec4(color.rgb * textureColor.rgb + polygon.rgb, textureColor.a * alphaValue);
} else {
fullColor = vec4(color.rgb * textureColor.rgb, textureColor.a * alphaValue);
}
fullColor.a *= fadeInValue * ta;
if (fullColor.a == 0.f) {
discard;
}
Fragment frag;
frag.color = fullColor;
frag.depth = gs_screenSpaceDepth;
frag.gPosition = vec4(1e27, 1e27, 1e27, 1.0);
frag.color = fullColor;
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vec4(1e32, 1e32, 1e32, 1.0);
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
return frag;
}
+146 -52
View File
@@ -27,71 +27,165 @@
#include "PowerScaling/powerScalingMath.hglsl"
layout(points) in;
layout(triangle_strip, max_vertices = 4) out;
//layout(points, max_vertices = 1) out;
layout(triangle_strip, max_vertices = 6) out;
in vec4 orig_position[];
//in vec4 colorMap[];
in float vs_screenSpaceDepth[];
out vec2 texCoord;
out float billboardSize;
out float gs_screenSpaceDepth;
//out vec4 gs_colorMap;
uniform mat4 projection;
//uniform dmat4 transformMatrix;
uniform dmat4 modelViewProjectionTransform;
uniform float scaleFactor;
uniform float minBillboardSize;
uniform dvec3 up;
uniform dvec3 right;
uniform dvec3 cameraPosition;
uniform dvec3 cameraLookUp;
uniform dvec4 centerScreenInWorldPosition;
uniform int renderOption;
uniform vec2 screenSize;
uniform float maxBillboardSize;
uniform float minBillboardSize;
in vec4 colorMap[];
out vec4 gs_colorMap;
out vec2 texCoord;
out float vs_screenSpaceDepth;
out float ta;
const double PARSEC = 0.308567756e17LF;
const vec2 corners[4] = vec2[4](
vec2(0.0, 1.0),
vec2(0.0, 0.0),
vec2(1.0, 1.0),
vec2(1.0, 0.0)
vec2(0.0, 0.0),
vec2(1.0, 0.0),
vec2(1.0, 1.0),
vec2(0.0, 1.0)
);
void main() {
gs_screenSpaceDepth = vs_screenSpaceDepth[0];
//gs_colorMap = colorMap[0];
ta = 1.0f;
vec4 pos = gl_in[0].gl_Position;
gs_colorMap = colorMap[0];
double scaleMultiply = exp(scaleFactor/10);
dvec3 scaledRight = dvec3(0.0);
dvec3 scaledUp = dvec3(0.0);
// if ((orig_position[0].x == 0.0) &&
// (orig_position[0].y == 0.0) &&
// (orig_position[0].z == 0.0))
// {
// return;
// }
//float modifiedSpriteSize = exp((-30.623 - 0.5) * 1.0) * scaleFactor * 2000;
float modifiedSpriteSize =
exp((-30.623 - (-5.0)) * 0.462) * 1.0 * 2000;
vec4 projPos[4];
for (int i = 0; i < 4; ++i) {
vec4 p1 = gl_in[0].gl_Position;
p1.xy += vec2(modifiedSpriteSize * (corners[i] - vec2(0.5)));
projPos[i] = projection * p1;
if (renderOption == 0) {
scaledRight = scaleMultiply * right/2.0f;
scaledUp = scaleMultiply * up/2.0f;
} else if (renderOption == 1) {
dvec3 normal = normalize(cameraPosition - dvec3(pos.xyz));
dvec3 newRight = normalize(cross(cameraLookUp, normal));
dvec3 newUp = cross(normal, newRight);
scaledRight = scaleMultiply * newRight/2.0f;
scaledUp = scaleMultiply * newUp/2.0f;
} else if (renderOption == 2) {
dvec3 normal = normalize(centerScreenInWorldPosition.xyz - dvec3(pos.xyz));
dvec3 newRight = normalize(cross(cameraLookUp, normal));
dvec3 newUp = cross(normal, newRight);
scaledRight = scaleMultiply * newRight/2.0f;
scaledUp = scaleMultiply * newUp/2.0f;
}
// Calculate the positions of the lower left and upper right corners of the
// billboard in screen-space
vec2 ll = (((projPos[1].xy / projPos[1].w) + 1.0) / 2.0) * screenSize;
vec2 ur = (((projPos[2].xy / projPos[2].w) + 1.0) / 2.0) * screenSize;
double unit = PARSEC;
// The billboard is smaller than one pixel, we can discard it
float sizeInPixels = length(ll - ur);
//if (sizeInPixels < minBillboardSize) {
// return;
//}
for (int i = 0; i < 4; i++) {
gl_Position = projPos[i];
texCoord = corners[i];
billboardSize = sizeInPixels;
EmitVertex();
// Must be the same as the enum in RenderableBillboardsCloud.h
if (pos.w == 1.f) {
unit = 1E3;
} else if (pos.w == 2.f) {
unit = PARSEC;
} else if (pos.w == 3.f) {
unit = 1E3 * PARSEC;
} else if (pos.w == 4.f) {
unit = 1E6 * PARSEC;
} else if (pos.w == 5.f) {
unit = 1E9 * PARSEC;
} else if (pos.w == 6.f) {
unit = 306391534.73091 * PARSEC;
}
EndPrimitive();
//dvec4 dpos = transformMatrix * dvec4(dvec3(pos.xyz) * unit, 1.0);
dvec4 dpos = dvec4(dvec3(pos.xyz) * unit, 1.0);
// texCoord = corners[0];
vec4 initialPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz - scaledRight - scaledUp, dpos.w)));
vs_screenSpaceDepth = initialPosition.w;
// texCoord = corners[1];
vec4 secondPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledRight - scaledUp, dpos.w)));
//texCoord = corners[2];
vec4 crossCorner = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledUp + scaledRight, dpos.w)));
// texCoord = corners[3];
vec4 thirdPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledUp - scaledRight, dpos.w)));
// Testing size:
vec4 topRight = secondPosition/secondPosition.w;
topRight = ((topRight + vec4(1.0)) / vec4(2.0)) * vec4(screenSize.x, screenSize.y, 1.0, 1.0);
vec4 bottomLeft = initialPosition/initialPosition.w;
bottomLeft = ((bottomLeft + vec4(1.0)) / vec4(2.0)) * vec4(screenSize.x, screenSize.y, 1.0, 1.0);
float height = abs(topRight.y - bottomLeft.y);
float width = abs(topRight.x - bottomLeft.x);
float var = (height + width);
if ((height > maxBillboardSize) ||
(width > maxBillboardSize)) {
// Set maximum size as Carter's instructions
float correctionScale = height > maxBillboardSize ? maxBillboardSize / (topRight.y - bottomLeft.y) :
maxBillboardSize / (topRight.x - bottomLeft.x);
scaledRight = correctionScale * scaleMultiply * right/2.0f;
scaledUp = correctionScale * scaleMultiply * up/2.0f;
initialPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz - scaledRight - scaledUp, dpos.w)));
vs_screenSpaceDepth = initialPosition.w;
secondPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledRight - scaledUp, dpos.w)));
crossCorner = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledUp + scaledRight, dpos.w)));
thirdPosition = z_normalization(vec4(modelViewProjectionTransform *
dvec4(dpos.xyz + scaledUp - scaledRight, dpos.w)));
// Fade-out
// float maxVar = 2.0f * maxBillboardSize;
// float minVar = maxBillboardSize;
// ta = 1.0f - ( (var - minVar)/(maxVar - minVar) );
// if (ta == 0.0f)
// return;
}
else if (width < 2.0f * minBillboardSize) {
//return;
float maxVar = 2.0f * minBillboardSize;
float minVar = minBillboardSize;
ta = ( (var - minVar)/(maxVar - minVar) );
if (ta == 0.0f)
return;
}
// Build primitive
texCoord = corners[0];
gl_Position = initialPosition;
EmitVertex();
texCoord = corners[1];
gl_Position = secondPosition;
EmitVertex();
texCoord = corners[2];
gl_Position = crossCorner;
EmitVertex();
EndPrimitive(); // First Triangle
texCoord = corners[0];
gl_Position = initialPosition;
EmitVertex();
texCoord = corners[2];
gl_Position = crossCorner;
EmitVertex();
texCoord = corners[3];
gl_Position = thirdPosition;
EmitVertex();
EndPrimitive(); // Second Triangle
}
@@ -26,24 +26,12 @@
#include "PowerScaling/powerScaling_vs.hglsl"
in dvec4 in_position;
//in dvec4 in_colormap;
in vec4 in_position;
in vec4 in_colormap;
uniform dmat4 modelViewTransform;
uniform mat4 projection;
out float vs_screenSpaceDepth;
out vec4 orig_position;
//out vec4 colorMap;
out vec4 colorMap;
void main() {
orig_position = vec4(in_position);
//colorMap = vec4(in_colormap);
vec4 positionViewSpace = vec4(modelViewTransform * in_position);
vec4 positionScreenSpace = vec4(z_normalization(projection * positionViewSpace));
//vec4 positionScreenSpace = vec4(projection * positionViewSpace);
vs_screenSpaceDepth = positionScreenSpace.w;
gl_Position = positionViewSpace;
colorMap = in_colormap;
gl_Position = vec4(in_position);
}
@@ -30,7 +30,6 @@ in vec3 in_position;
uniform dmat4 modelViewTransform;
uniform dmat4 projectionTransform;
uniform float scaleFactor;
out float vs_screenSpaceDepth;
out vec4 vs_positionViewSpace;
@@ -56,8 +56,8 @@ Fragment getFragment() {
// }
//frag.color = texture(galaxyTexture, vs_st);
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vec4(1e27, 1e27, 1e27, 1.0);
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vec4(vs_screenSpaceDepth, vs_screenSpaceDepth, vs_screenSpaceDepth, 1.0);
frag.gNormal = vec4(0.0, 0.0, 0.0, 1.0);
return frag;