Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 505fc29
  • /
  • glsl
  • /
  • sphere.frag
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:e71ff058cc8a47e0c9298c9f7070c43b987047ac
directory badge
swh:1:dir:0906aec91d57b1165889895671be426ffdbe1398

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
sphere.frag
#version 330

layout(location=0) out vec4 result;
layout(location=1) out int id;

in fData
{
	vec4 toPixel;
	vec4 cam;
	vec4 color;
	float radius;
} frag;

uniform mat4 p;
uniform bool constantColor;
uniform vec4 color;
uniform bool shaded;

void main(void)
{
	vec3 v = frag.toPixel.xyz - frag.cam.xyz;
	vec3 e = frag.cam.xyz;
	float ev = dot(e, v);
	float vv = dot(v, v);
	float ee = dot(e, e);
	float rr = frag.radius * frag.radius;

	float radicand = ev * ev - vv * (ee - rr);
	if(radicand < 0)
		discard;
	
	float rt = sqrt(radicand);
	

	float lambda = max(0, (-ev - rt) / vv);
	float lambda2 = (-ev + rt) / vv;
	if(lambda2 < lambda)
		discard;

	vec3 hit = lambda * v;
	vec3 normal = (frag.cam.xyz + hit) / frag.radius;
	
	vec4 proj = p * vec4(hit, 1);
	gl_FragDepth = ((gl_DepthRange.diff * proj.z / proj.w) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;

	vec4 myColor = (constantColor ? color : frag.color);

	if(shaded)
	{
		vec3 vNormalized = -normalize(v);
		float nDotL = dot(vNormalized, normal);
		vec3 c = myColor.rgb * nDotL + vec3(0.5, 0.5, 0.5) * pow(nDotL, 120);	
		result = vec4(c, myColor.a);
	}
	else
		result = myColor;	

	id = gl_PrimitiveID;
}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API