Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add water edge effect #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HPL2/resource/deferred_resources.h.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ RES(SamplerState, materialSampler, UPDATE_FREQ_NONE, s2, binding = 13);
RES(Tex2D(float4), dissolveMap, UPDATE_FREQ_NONE, t11, binding = 14);
RES(Tex2D(float4), refractionMap, UPDATE_FREQ_PER_FRAME, t12, binding = 15);
RES(Tex2D(float4), reflectionMap, UPDATE_FREQ_PER_FRAME, t13, binding = 16);
RES(Tex2D(float4), screenDepthMap, UPDATE_FREQ_PER_FRAME, t14, binding = 17);

PUSH_CONSTANT(materialRootConstant, b0)
{
Expand Down
19 changes: 15 additions & 4 deletions HPL2/resource/translucency_water.frag.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ PsOut PS_MAIN(PsIn In)
INIT_MAIN;
PsOut Out;
uint materialID = Get(uniformObjectBuffer)[Get(objectId)].materialID;
float4 screenDepth = SampleTex2D(Get(screenDepthMap), Get(nearestSampler), (In.Position.xy * Get(viewTexel)));

float waveAft = Get(afT) * Get(uniformMaterialBuffer)[materialID].waveSpeed;
float waveAmplitude = Get(uniformMaterialBuffer)[materialID].waveAmplitude * WAVE_AMPLITUDE_SCALE;
Expand Down Expand Up @@ -68,7 +69,9 @@ PsOut PS_MAIN(PsIn In)

///////////////////////////////
//Get the diffuse color
float4 surfaceColor = SampleTex2D(Get(diffuseMap), Get(materialSampler), vUv1);
float4 surfaceColor = SampleTex2D(Get(diffuseMap), Get(materialSampler), vUv1);



float4 vRefractionColor = float4(1,1,1,1);
float2 vDistortedScreenPos = float2(0.0,0.0);
Expand All @@ -77,9 +80,9 @@ PsOut PS_MAIN(PsIn In)
float fInvDist = min(1.0 / In.pos.z, 10.0);
vDistortedScreenPos = (In.Position.xy * refractionViewTexel) + (vFinalNormal.xy * Get(uniformMaterialBuffer)[materialID].refractionScale * fInvDist);
vRefractionColor = SampleTex2D(Get(refractionMap), Get(nearestSampler), vDistortedScreenPos);
if(vRefractionColor.a < 0.5) {
vRefractionColor = SampleTex2D(Get(refractionMap), Get(nearestSampler), In.Position.xy * refractionViewTexel);
}
//if(vRefractionColor.a < 0.5) {
// vRefractionColor = SampleTex2D(Get(refractionMap), Get(nearestSampler), In.Position.xy * refractionViewTexel);
//}
}


Expand Down Expand Up @@ -129,6 +132,14 @@ PsOut PS_MAIN(PsIn In)
Out.diffuse.rgb = (surfaceColor.xyz * vRefractionColor.xyz * fDiffuse + float3(fSpecular, fSpecular, fSpecular)) * (1.0-fFogAmount) + Get(worldFogColor).xyz*fFogAmount;
}

float waterDepth = clamp(0, 1, screenDepth.x - In.Position.z);
if(waterDepth < .00001 ) {
float leading = (waterDepth / .00001) + 0.1;
//surfaceColor.rgb += (leading * float3(1.0,1.0,1.0));
Out.diffuse.rgb = ((1.0 - leading) * Out.diffuse.rgb) + (float3(1.0,1.0,1.0) * leading);
//Out.diffuse.rgb = ((1.0 - leading) * Out.diffuse.rgb) + (leading * float3(1.0,1.0,1.0));
}

Out.diffuse.w = 1.0;
RETURN(Out);
}
4 changes: 3 additions & 1 deletion HPL2/sources/graphics/RendererDeferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2634,9 +2634,11 @@ namespace hpl {
});

{
std::array<DescriptorData, 1> params = {};
std::array<DescriptorData, 2> params = {};
params[0].pName = "refractionMap";
params[0].ppTextures = &currentGBuffer.m_refractionImage.m_handle;
params[1].pName = "screenDepthMap";
params[1].ppTextures = &currentGBuffer.m_depthBuffer.m_handle->pTexture;
updateDescriptorSet(frame.m_renderer->Rend(), mainFrameIndex, m_materialSet.m_frameSet[frame.m_frameIndex].m_handle, params.size(), params.data());
}

Expand Down