Skip to content

Commit

Permalink
fixes wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cryham committed Jun 9, 2024
1 parent e19a747 commit 52545b6
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 51 deletions.
28 changes: 16 additions & 12 deletions data/Compositors/SR3.compositor
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ abstract compositor_node SR3_RenderAbs
// visibility_mask 0x000011FF // set later RV_MaskGameAll
// visibility_mask 0x00000001 // set later RV_MaskGameAll
visibility_mask 0x000011FD // set later RV_MaskGameAll
//! set later at end in all : SR3_RenderAbs

// rq_last 110 // glass,par etc
rq_last 209

Expand Down Expand Up @@ -422,11 +424,11 @@ abstract compositor_node SR3_RenderAbs

// ?
// expose demo_dynamic_cubemap
// identifier 22201
identifier 22201
// identifier 25001

visibility_mask 0x01000000
// visibility_mask 0x00000002
// visibility_mask 0x01000000
visibility_mask 0x00000002
rq_first 210
rq_last 211

Expand Down Expand Up @@ -640,34 +642,36 @@ compositor_node_shadow SR3_Shadows
// [Main Nodes] for all Max_Players, vis mask same as RV_Hud3D[..]
//------------------------------------------------------------------------------------
compositor_node SR3_Render0 : SR3_RenderAbs
{ target rt_renderwindow
{ pass clear { }
pass render_scene { visibility_mask 0x000011FF }
} }
{
}
// { target rt_renderwindow
// { pass clear { }
// pass render_scene { visibility_mask 0x000011FD }
// } }
compositor_node SR3_Render1 : SR3_RenderAbs
{ target rt_renderwindow
{ pass clear { }
pass render_scene { visibility_mask 0x000101FF }
pass render_scene { visibility_mask 0x000101FD }
} }
compositor_node SR3_Render2 : SR3_RenderAbs
{ target rt_renderwindow
{ pass clear { }
pass render_scene { visibility_mask 0x000201FF }
pass render_scene { visibility_mask 0x000201FD }
} }
compositor_node SR3_Render3 : SR3_RenderAbs
{ target rt_renderwindow
{ pass clear { }
pass render_scene { visibility_mask 0x000401FF }
pass render_scene { visibility_mask 0x000401FD }
} }
compositor_node SR3_Render4 : SR3_RenderAbs
{ target rt_renderwindow
{ pass clear { }
pass render_scene { visibility_mask 0x000801FF }
pass render_scene { visibility_mask 0x000801FD }
} }
compositor_node SR3_Render5 : SR3_RenderAbs
{ target rt_renderwindow
{ pass clear { }
pass render_scene { visibility_mask 0x001001FF }
pass render_scene { visibility_mask 0x001001FD }
} }

// [Workspaces] 0 also for ed 🏗️
Expand Down
4 changes: 4 additions & 0 deletions data/Hlms/Pbs/Any/Main/500.Structs_piece_vs_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,12 @@ struct Material
@property( hlms_fog )
// fog.xyz = colour
INTERPOLANT( midf3 fog, @counter(texcoord) );
@end

@property( !hlms_shadowcaster )
INTERPOLANT( float worldH, @counter(texcoord) ); //**
@end

@else
@property( alpha_test )
@foreach( hlms_uv_count, n )
Expand Down
4 changes: 2 additions & 2 deletions data/Hlms/Pbs/Any/Main/800.VertexShader_piece_vs.any
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@
outVs.zwDepth.xy = outVs_Position.zw;
@end

@property( hlms_fog )
outVs.worldH = worldPos.y;
@property( !hlms_shadowcaster )
outVs.worldH = worldPos.y; //**
@end

@property( hlms_global_clip_planes )
Expand Down
83 changes: 76 additions & 7 deletions data/Hlms/Pbs/Any/Refractions_piece_ps.any
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,53 @@
@end

@piece( applyRefractions )
@property( !hlms_shadowcaster )
@property( !fresnel_scalar )
midf refractF0 = pixelData.F0;
@else
midf refractF0 = max( pixelData.F0.x, pixelData.F0.y, pixelData.F0.z );
// midf refractF0 = max( pixelData.F0.x, pixelData.F0.y, pixelData.F0.z ); //-
midf refractF0 = max( pixelData.F0.y, pixelData.F0.z );
@end

// refractNormal must be in view space, and we ignore .z component
midf2 refractNormal2d = OGRE_refract( pixelData.viewDir, pixelData.normal,
refractF0, pixelData.NdotV ).xy;
float2 refractUv = screenPosUv.xy + float2( refractNormal2d.xy ) *
float2( material.refractionStrength,
material.refractionStrength * passBuf.aspectRatio ) /
( (-inPs.pos.z + 1.0) * (-inPs.pos.z + 1.0) );
material.refractionStrength * passBuf.aspectRatio )
// new
// / 10.0; // const strong
// / (10.0 + -inPs.pos.z * 0.5); // soft
// / (10.0 + -inPs.pos.z * 0.2) * 2.0; // soft
// / (1.0 + -inPs.pos.z * 0.2); // ok
// / (1.0 + max(12.0, -inPs.pos.z * 0.2)); // ok
// / (1.0 + max(5.0, -inPs.pos.z * 0.1)); // no-
// org
// / ( (-inPs.pos.z + 1.0) * (-inPs.pos.z + 1.0) ); // org - none far, bad near
// / ( (-inPs.pos.z + 1.0 ) ); // bad close
// / ( -inPs.pos.z * 0.5 + 2.0); // strong- near, no far
// good
// / ( max(21.0, -inPs.pos.z) * 0.5 + 2.0); // * big near, no far
// / ( max(31.0, -inPs.pos.z) * 0.5 + 2.0); // + ok near, no far
// / ( max(121.0, -inPs.pos.z) * 0.2 + 2.0); // ~ soft near, good far
/ ( max(21.0, -inPs.pos.z) * 0.2 + 2.0) * 0.5; // - tiny strong near and far
// old meh
// / ( min(-72.0, max(-21.0, -inPs.pos.z)) * 0.2 + 1.0); // ~ soft near, ok far
// / ( min(-71.0, max(-1.0, -inPs.pos.z)) * 1.0 + 1.0); // ~ soft near, ok far
// / ( min(-21.0, max(-11.0, -inPs.pos.z)) * 0.7 + 1.0); // *- tiny strong
// / ( min(-41.0, max(-2.0, -inPs.pos.z)) * 0.7 + 1.0); // ^ nice near, strong far
refractUv.y += 0.07; // try fix top mess`-
float2 refractUvOrg = refractUv;

midf3 refractionCol = OGRE_SampleLevelF16( refractionMap, refractionMapSampler, refractUv, 0 ).xyz;
midf refractionDepth = OGRE_SampleLevelF16( depthTextureNoMsaa, refractionMapSampler, refractUv, 0 ).x;
// midf3 orgCol = refractionCol;

// We may need to fallback to regular transparency if we're sampling to close to the edges
// We may need to fallback to regular transparency if we're sampling too close to the edges
// or the object being refracted is in front of us.
midf3 fallbackRefractionCol = OGRE_Load2DF16( refractionMap, iFragCoord.xy, 0 ).xyz;

refractUv = saturate( abs( screenPosUv.xy * 2.0 - 1.0 ) * 10.0 - 9.0 );
refractUv = saturate( abs( screenPosUv.xy * 2.0 - 1.0 ) * 10.0 - 9.0 ); // org blend
// refractUv = saturate( abs( screenPosUv.xy * 2.0 - 1.0 ) * 20.0 - 18.0 );
midf fallbackRefrW = midf_c( max( refractUv.x, refractUv.y ) );
fallbackRefrW = fallbackRefrW * fallbackRefrW;

Expand All @@ -53,13 +78,57 @@

refractionCol = lerp( refractionCol, fallbackRefractionCol, fallbackRefrW );


// refractionCol.x *= 0.4f; // colorize cyan-blue
// refractionCol.y *= 0.9f;

// depth ------
midf depthValue = OGRE_SampleLevelF16( depthTextureNoMsaa, refractionMapSampler, screenPosUv.xy, 0 ).x;
// midf4 ndc = midf4( screenPosUv.xy * 2.0 - 1.0, depthValue, 1.0 ); // normal
midf4 ndc = midf4( refractUvOrg.xy * 2.0 - 1.0, depthValue, 1.0 ); // refracted ?
midf4 tmp = mul( ndc, inverse( passBuf.viewProj ) ); // worldViewProj-
midf3 pos = tmp.xyz / tmp.w;

midf depth = inPs.worldH - pos.y;
// depth = min(40, max(0, depth)); // max depth
// depth = min(20, max(0, depth)); // max depth
// depth = 0.1 + min(40, max(0, 6.0 + 20.0 * depth * 0.6)); // max depth
depth = min(40, max(0, 6.0 + 10.0 * depth * 0.6)); // max depth

// midf3 deepFade = 1.1 * midf3(0.034, 0.022, 0.01); // fade blue dark
midf3 deepFade = 1.1 * midf3(0.04, 0.02, 0.01); // fade blue cyan
// midf3 deepFade = 1.0 * midf3(0.08, 0.02, 0.01); // fade cyan green

// depth = midf_c( exp2( depth * 0.06 ) ); // amount
// depth = min(1.0, max(0.0, depth)); // max depth
// midf3 deepFade = 8.0 * midf3(0.1, 0.02, 0.01); // fade

// midf3 deepClr = midf3(0.2, 0.33, 0.4); // deepest color
// refractionCol.x = max(deepClr.x, refractionCol.x - depth * deepFade.x);
// refractionCol.y = max(deepClr.y, refractionCol.y - depth * deepFade.y);
// refractionCol.z = max(deepClr.z, refractionCol.z - depth * deepFade.z);
refractionCol.x *= 1.0 - depth * deepFade.x;
refractionCol.y *= 1.0 - depth * deepFade.y;
refractionCol.z *= 1.0 - depth * deepFade.z;
// pixelData.diffuse.w = max(0.0, 1.0 - depth * 0.1); // fade alpha..


@property( use_texture_alpha )
midf refractionAlpha = midf_c( material.F0.w ) * pixelData.diffuse.w;
@else
midf refractionAlpha = midf_c( material.F0.w );
@end

finalColour += refractionCol.xyz * (_h( 1.0 ) - refractionAlpha);
@end
// diffuseCol.w = 0.1; //? alpha border..
// material.F0.w = 0.1;

// finalColour = orgCol.xyz;
// finalColour += orgCol.xyz * (_h( 1.0 ) - refractionAlpha);

// finalColour = midf3( inPs.worldH * 0.001, inPs.worldH * 0.002, 0.01 * inPs.worldH);
// finalColour = midf3( inPs.worldH * 10.1, inPs.worldH * 8.1, 9.1 * inPs.worldH);
// finalColour = midf3( depthValue * 300.0, depthValue * 1000.0, 20.0 * inPs.worldH);

@end
@end
53 changes: 26 additions & 27 deletions data/materials/Pbs/all.material.json
Original file line number Diff line number Diff line change
Expand Up @@ -17480,19 +17480,19 @@

"Water_blue" :
{
"macroblock" : "Macroblock_0",
"blendblock" : "Blendblock_2",
"shadow_const_bias" : 0.01,
"workflow" : "specular_ogre",
"fluid" : true,
"refraction_strength" : 0.7,
"transparency" :
{
"value" : 0.9061272,
"mode" : "Transparent",
"value" : 0.1061272,
"mode" : "Refractive",
"use_alpha_from_textures" : true
},
"diffuse" :
{
"value" : [0.026094079, 0.13737679, 0.15755145],
"value" : [0.026094079, 0.013737679, 0.015755145],
"background" : [1, 1, 1, 1],
"sampler" : "Sampler_10"
},
Expand Down Expand Up @@ -17993,6 +17993,7 @@
"WaterBlue":
{
"shadow_const_bias" : 0.01,
"fluid" : true,
"workflow" : "specular_ogre",
"transparency" :
{
Expand All @@ -18004,12 +18005,12 @@
{
"value" : [0.026, 0.037, 0.057],
"background" : [1, 1, 1, 1],
"sampler" : "wrap"
"sampler" : "Sampler_10"
},
"specular" :
{
"value" : [0.5, 0.55, 0.59],
"sampler" : "wrap"
"sampler" : "Sampler_10"
},
"fresnel" :
{
Expand All @@ -18020,59 +18021,57 @@
{
"value" : 0.5,
"texture" : "mntn_black_n.jpg",
"sampler" : "wrap"
"sampler" : "Sampler_10"
},
"roughness" :
{
"value" : 0.25,
"sampler" : "wrap"
"sampler" : "Sampler_10"
},

"detail_diffuse0" :
{
"value" : 1,
"offset" : [0.15, 0.1],
"scale" : [0.3, 0.15],
"sampler" : "wrap"
"sampler" : "Sampler_10"
},
"detail_diffuse1" :
{
"value" : 1,
"offset" : [0.3, 0.3],
"sampler" : "wrap"
"sampler" : "Sampler_10"
},
"detail_diffuse2" :
{
"value" : 1,
"offset" : [1, 0.15],
"scale" : [25, 1.5],
"sampler" : "wrap"
"sampler" : "Sampler_10"
},
"detail_diffuse3" :
{
"value" : 1,
"offset" : [6, 0.4],
"sampler" : "wrap"
"sampler" : "Sampler_10"
}
},

"Water_cyan" :
{
"macroblock" : "Macroblock_2",
"blendblock" : "Blendblock_2",
"shadow_const_bias" : 0.01,
"workflow" : "specular_ogre",
"fluid" : true,
"refraction_strength" : 0.9,
"refraction_strength" : 0.8,
"transparency" :
{
"value" : 0.8061712,
"value" : 0.28,
"mode" : "Refractive",
"use_alpha_from_textures" : true
},
"diffuse" :
{
"value" : [0.065268785, 0.24099025, 0.17886916],
"value" : [0.065268785, 0.024099025, 0.017886916],
"background" : [1, 1, 1, 1],
"sampler" : "Sampler_10"
},
Expand Down Expand Up @@ -18187,19 +18186,19 @@

"Water_green" :
{
"macroblock" : "Macroblock_0",
"blendblock" : "Blendblock_2",
"shadow_const_bias" : 0.01,
"workflow" : "specular_ogre",
"fluid" : true,
"refraction_strength" : 0.9,
"transparency" :
{
"value" : 0.862882,
"mode" : "Transparent",
"value" : 0.1962882,
"mode" : "Refractive",
"use_alpha_from_textures" : true
},
"diffuse" :
{
"value" : [0.06246403, 0.11814534, 0.024061374],
"value" : [0.006246403, 0.011814534, 0.0024061374],
"background" : [1, 1, 1, 1],
"sampler" : "Sampler_10"
},
Expand Down Expand Up @@ -18839,14 +18838,14 @@

"Water_shore" :
{
"macroblock" : "Macroblock_0",
"blendblock" : "Blendblock_2",
"shadow_const_bias" : 0.01,
"workflow" : "specular_ogre",
"fluid" : true,
"refraction_strength" : 0.9,
"transparency" :
{
"value" : 0.76,
"mode" : "Transparent",
"value" : 0.1962882,
"mode" : "Refractive",
"use_alpha_from_textures" : true
},
"diffuse" :
Expand Down
7 changes: 4 additions & 3 deletions src/common/FluidsReflect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,11 @@ void FluidsReflect::CreateFluids()
Hlms *hlms = app->mRoot->getHlmsManager()->getHlms( HLMS_PBS );
HlmsPbs *pbs = static_cast<HlmsPbs *>( hlms );
// pbs->setPlanarReflections( mPlanarReflect );
auto* db = (HlmsPbsDatablock*)pbs->getDatablock("WaterBlue");//"Water_cyan");
auto* db = (HlmsPbsDatablock*)pbs->getDatablock("WaterBlue");
// auto* db = (HlmsPbsDatablock*)pbs->getDatablock("Water_cyan");

// db->setTransparency( 0.82f, Ogre::HlmsPbsDatablock::Refractive );
db->setFresnel( Ogre::Vector3( 0.2f ), false );
db->setFresnel( Ogre::Vector3( 0.9f ), false );
// db->setFresnel( Ogre::Vector3( 0.1f, 0.4f, 0.9f ), true ); // crash, shader F0?
db->setRefractionStrength( 0.9f ); // par+ not in json-

Expand All @@ -260,7 +261,7 @@ void FluidsReflect::CreateFluids()
// waterItem->setVisibilityFlags( 2 );
#endif
// [0] above [1] below
for (int n=0; n < 2; ++n)
for (int n=0; n < 1; ++n) // 2 // todo refract wirefr bad
{
item[n] = mgr->createItem( mesh, dyn );
item[n]->setDatablock( sMtr );
Expand Down

0 comments on commit 52545b6

Please sign in to comment.