95 lines
2 KiB
GLSL
95 lines
2 KiB
GLSL
#version 450 core
|
|
//! type fragment
|
|
|
|
//! include chunks/raymarcher.glsl
|
|
//! include lib/shading-pbr.glsl
|
|
//! include lib/shading-blinnphong.glsl
|
|
//! include lib/fog.glsl
|
|
|
|
|
|
T_BPMaterial BPMaterials[1] = {
|
|
{ vec3( 1 , 1 , .4 ) * .1 , vec3( 1 , 1 , .4 ) , 40 , .1 }
|
|
};
|
|
|
|
T_PBRMaterial PBRMaterials[1] = {
|
|
{
|
|
// Albedo color
|
|
vec3( 1 , 1 , 1 ) ,
|
|
// Roughness , metallic , subsurface , anisotropy
|
|
.5 , .5 , 0 , 0 ,
|
|
// Specular strength / tint%
|
|
.5 , .5
|
|
}
|
|
};
|
|
|
|
vec3 Glow[1] = {
|
|
vec3( .95 , .8 , 1 ) * 5
|
|
};
|
|
|
|
void mapMaterial(
|
|
in int matIndex ,
|
|
out int type ,
|
|
out int tIndex ,
|
|
out int glowIndex )
|
|
{
|
|
if ( matIndex == 0 ) {
|
|
glowIndex = -1;
|
|
} else {
|
|
//type = 1;
|
|
glowIndex = 0;
|
|
}
|
|
type = 1;
|
|
tIndex = 0;
|
|
}
|
|
|
|
vec2 RM_Map( vec3 pos )
|
|
{
|
|
pos = pos - vec3( 0 , 0 , 0 );
|
|
vec3 q = pos;
|
|
q.xy = mod( q.xy + 4. , 8. ) - 4.;
|
|
return vec2( length( q ) - 1.8 , step( 0. , 1.9 - length( pos.xy ) ) );
|
|
}
|
|
|
|
|
|
void main( )
|
|
{
|
|
vec2 uv = ( gl_FragCoord.xy / u_Resolution ) * 2 - 1;
|
|
vec3 camDir = normalize( u_LookAt - u_CamPos );
|
|
vec3 side = normalize( cross( u_CamUp , camDir ) );
|
|
vec3 up = normalize( cross( camDir , side ) );
|
|
vec3 rayDir = normalize( camDir * u_NearPlane
|
|
+ uv.x * side * u_Resolution.x / u_Resolution.y
|
|
+ uv.y * up );
|
|
|
|
vec3 r = RM_Advanced( u_CamPos , rayDir ,
|
|
int( u_Render.x ) , u_Render.y ,
|
|
u_Render.z , .001 , u_Render.w );
|
|
vec3 hitPos = u_CamPos + rayDir * r.x;
|
|
const vec3 background = vec3( .005 );
|
|
|
|
vec3 bc = background;
|
|
if ( r.y >= 0. ) {
|
|
const int midx = int( r.y );
|
|
const vec3 normal = RM_GetNormal( hitPos );
|
|
const vec3 lightDir = normalize( -u_LightDir );
|
|
|
|
// Remap materials through mapMaterials
|
|
int mtype , mtidx , glowidx;
|
|
mapMaterial( midx , mtype , mtidx , glowidx );
|
|
if ( mtype == 0 ) {
|
|
bc = BP_Shade( BPMaterials[ mtidx ] ,
|
|
-rayDir , normal , lightDir );
|
|
} else {
|
|
bc = PBR_Shade( PBRMaterials[ mtidx ] ,
|
|
-rayDir , normal , lightDir );
|
|
}
|
|
|
|
if ( glowidx >= 0 ) {
|
|
bc += Glow[ glowidx ];
|
|
}
|
|
bc = FOG_Apply( bc , r.x , u_FogAttenuation , background );
|
|
}
|
|
|
|
o_Color = bc;
|
|
o_Z = r.x;
|
|
}
|