Files
OpenSpace/shaders/PowerScaling/powerScaling_vs.hglsl
T
Alexander Bock 43851899c7 Cleanup of more copyright headers
Add debug groups and object names to the OpenGL objects in the framebuffer renderer
2020-02-13 14:59:13 +01:00

73 lines
3.5 KiB
Plaintext

/*****************************************************************************************
* *
* OpenSpace *
* *
* Copyright (c) 2014-2020 *
* *
* 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. *
****************************************************************************************/
#ifndef POWERSCALING_VS_H_HGLSL
#define POWERSCALING_VS_H_HGLSL
uniform vec4 campos;
uniform mat4 camrot;
uniform vec2 scaling;
uniform vec4 objpos;
#include "powerScalingMath.hglsl"
vec4 psc_to_meter(vec4 v1, vec2 v2) {
float factor = v2.x * pow(k,v2.y + v1.w);
return vec4(v1.xyz * factor, 1.0);
}
vec4 psc_scaling(vec4 v1, vec2 v2) {
float ds = v2.y - v1.w;
if(ds >= 0) {
return vec4(v1.xyz * v2.x * pow(k,v1.w), v2.y);
} else {
return vec4(v1.xyz * v2.x * pow(k,v2.y), v1.w);
}
}
// vertexPosition is returned as the transformed vertex in OS Camera Rig Space in PSC
vec4 pscTransform(inout vec4 vertexPosition, mat4 modelTransform) {
vec3 local_vertex_pos = mat3(modelTransform) * vertexPosition.xyz;
// PSC addition; local vertex position and the object power scaled world position
vertexPosition = psc_addition(vec4(local_vertex_pos,vertexPosition.w),objpos);
// PSC addition; rotated and viewscaled vertex and the cameras negative position
vertexPosition = psc_addition(vertexPosition,vec4(-campos.xyz,campos.w));
// rotate the camera
vertexPosition.xyz = mat3(camrot) * vertexPosition.xyz;
vec4 tmp = vertexPosition;
vertexPosition = psc_scaling(vertexPosition, scaling);
// project using the rescaled coordinates,
tmp = psc_to_meter(tmp, scaling);
// Return the vertex tranformed to OS Camera Rig Space
// in meters.
return tmp;
}
#endif