From be460bce83be7856f03ad38f31d058a52de08a5d Mon Sep 17 00:00:00 2001 From: Emmanuel Benoit Date: Tue, 3 Oct 2017 10:06:26 +0200 Subject: [PATCH] Raymarcher data updated --- shaders/map.glsl | 29 +++++++++++++++++++++-------- shaders/raymarcher.glsl | 30 ++++++++++++++++++------------ 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/shaders/map.glsl b/shaders/map.glsl index 321fd5b..92dd8bd 100644 --- a/shaders/map.glsl +++ b/shaders/map.glsl @@ -2,20 +2,31 @@ #define USE_MAP_MATERIAL T_BPMaterial BPMaterials[1] = { - { vec3( 1 , 1 , 0 ) , vec3( 1 ) , 4 , .3 } + { vec3( 1 , 1 , 0 ) * .1 , vec3( .1 ) , 4 , .1 } +}; + +T_PBRMaterialOld PBRMaterialsOld[1] = { + { + // Albedo / specular colors + vec3( 1 , 1 , 0 ) , vec3( 1 , 1 , .4 ) * .1 , + // Roughness , anisotropy , subsurface , metallic + .8 , .8 , .1 , .9 + } }; T_PBRMaterial PBRMaterials[1] = { { - // Albedo / specular colors - vec3( 1 , 1 , 0 ) , vec3( 1 , 1 , .4 ) , - // Roughness , anisotropy , subsurface , metallic - .1 , 0 , 0 , .75 + // Albedo color + vec3( 1 , 1 , .4 ) , + // Roughness , metallic , subsurface , anisotropy + .3 , .1 , 0 , .0 , + // Specular strength / tint% + 1 , 1 } }; vec3 Glow[1] = { - vec3( 5. , .1 , 4. ) + vec3( 0 , 0 , 0 ) }; void mapMaterial( @@ -26,16 +37,18 @@ void mapMaterial( { if ( matIndex == 0 ) { type = 0; + glowIndex = -1; } else { type = 1; + glowIndex = 0; } tIndex = 0; - glowIndex = -1; } vec2 map( vec3 pos ) { + pos = pos - vec3( 0 , 0 , 0 ); vec3 q = pos; - q.xy = mod( q.xy + 4. , 8. ) - 4.; + //q.xy = mod( q.xy + 4. , 8. ) - 4.; return vec2( length( q ) - 1.8 , step( 0. , 1.9 - length( pos.xy ) ) ); } diff --git a/shaders/raymarcher.glsl b/shaders/raymarcher.glsl index 2823d55..6fd1ead 100644 --- a/shaders/raymarcher.glsl +++ b/shaders/raymarcher.glsl @@ -1,6 +1,6 @@ vec3 getNormal( vec3 pos ) { - vec2 v = vec2( .01 , 0 ); + vec2 v = vec2( .0005 , 0 ); return normalize( vec3( map( pos + v.xyy ).x - map( pos - v.xyy ).x , map( pos + v.yxy ).x - map( pos - v.xyx ).x , @@ -47,20 +47,21 @@ void main( ) if ( r.y >= 0. ) { const int midx = int( r.y ); const vec3 normal = getNormal( hitPos ); + const vec3 lightDir = normalize( -u_LightDir ); #if defined( USE_BP ) // Blinn-Phong only bc = BP_Shade( BPMaterials[ midx ] , - rayDir , normal , -u_LightDir ); + rayDir , normal , lightDir ); #else #if defined( USE_PBR ) // PBR only - T_PBRMaterial material = PBRMaterials[ midx ]; - T_PBRPrecomputed precomputed = PBR_Precompute( + T_PBRMaterialOld material = PBRMaterialsOld[ midx ]; + T_PBRPrecomputedOld precomputed = PBR_PrecomputeOld( material , rayDir , normal ); - bc = PBR_Shade( material , precomputed , - rayDir , normal , -u_LightDir ); + bc = PBR_ShadeOld( material , precomputed , + rayDir , normal , lightDir ); #else #if defined( USE_MAP_MATERIAL ) @@ -69,16 +70,21 @@ void main( ) mapMaterial( midx , mtype , mtidx , glowidx ); if ( mtype == 0 ) { bc = BP_Shade( BPMaterials[ mtidx ] , - rayDir , normal , -u_LightDir ); + rayDir , normal , lightDir ); } else { - T_PBRMaterial material = PBRMaterials[ mtidx ]; - T_PBRPrecomputed precomputed = PBR_Precompute( +#if 0 + T_PBRMaterialOld material = PBRMaterialsOld[ mtidx ]; + T_PBRPrecomputedOld precomputed = PBR_PrecomputeOld( material , rayDir , normal ); - bc = PBR_Shade( material , precomputed , - rayDir , normal , -u_LightDir ); + bc = PBR_ShadeOld( material , precomputed , + rayDir , normal , lightDir ); +#else + bc = PBR_Shade( PBRMaterials[ mtidx ] , + -rayDir , normal , lightDir ); +#endif } #if defined( USE_GLOW ) - if ( glowidx > 0 ) { + if ( glowidx >= 0 ) { bc += Glow[ glowidx ]; } #endif