set up distortion for rain
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#define TRANSPARENT // uses transparent light lists
|
||||
#define LIGHTING_SCATTER
|
||||
#include "globals.hlsli"
|
||||
#include "emittedparticleHF.hlsli"
|
||||
#include "ShaderInterop_EmittedParticle.h"
|
||||
@@ -19,6 +20,9 @@ float4 main(VertextoPixel input) : SV_TARGET
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
float2 ScreenCoord = input.pos.xy * GetCamera().internal_resolution_rcp; // use pixel center!
|
||||
uint2 pixel = input.pos.xy; // no longer pixel center!
|
||||
|
||||
write_mipmap_feedback(EmitterGetGeometry().materialIndex, ddx_coarse(input.tex.xyxy), ddy_coarse(input.tex.xyxy));
|
||||
|
||||
@@ -38,8 +42,6 @@ float4 main(VertextoPixel input) : SV_TARGET
|
||||
color = lerp(color, color2, input.frameBlend);
|
||||
}
|
||||
}
|
||||
|
||||
uint2 pixel = input.pos.xy; // no longer pixel center!
|
||||
|
||||
float4 inputColor;
|
||||
inputColor.r = ((input.color >> 0) & 0xFF) / 255.0f;
|
||||
@@ -49,10 +51,29 @@ float4 main(VertextoPixel input) : SV_TARGET
|
||||
|
||||
float opacity = color.a * inputColor.a;
|
||||
|
||||
float3 normal = 0;
|
||||
#ifndef EMITTEDPARTICLE_DISTORTION // the "distortion" shader is just using normal map as the color map and uses it for signed blending, this normal logic won't be used for that
|
||||
[branch]
|
||||
if (material.textures[NORMALMAP].IsValid())
|
||||
{
|
||||
normal = material.textures[NORMALMAP].Sample(sampler_linear_clamp, input.tex.xyxy).rgb;
|
||||
|
||||
[branch]
|
||||
if (xEmitterOptions & EMITTER_OPTION_BIT_FRAME_BLENDING_ENABLED)
|
||||
{
|
||||
float3 normal2 = material.textures[NORMALMAP].Sample(sampler_linear_clamp, input.tex.zwzw).rgb;
|
||||
normal = lerp(normal, normal2, input.frameBlend);
|
||||
}
|
||||
|
||||
normal -= 0.5;
|
||||
normal *= material.normalMapStrength;
|
||||
normal *= opacity;
|
||||
}
|
||||
#endif // EMITTEDPARTICLE_DISTORTION
|
||||
|
||||
[branch]
|
||||
if (GetCamera().texture_lineardepth_index >= 0)
|
||||
{
|
||||
float2 ScreenCoord = input.pos.xy * GetCamera().internal_resolution_rcp; // use pixel center!
|
||||
float4 depthScene = texture_lineardepth.GatherRed(sampler_linear_clamp, ScreenCoord) * GetCamera().z_far;
|
||||
float depthFragment = input.pos.w;
|
||||
opacity *= saturate(1.0 / input.size * (max(max(depthScene.x, depthScene.y), max(depthScene.z, depthScene.w)) - depthFragment));
|
||||
@@ -77,6 +98,7 @@ float4 main(VertextoPixel input) : SV_TARGET
|
||||
N.x = -cos(PI * input.unrotated_uv.x);
|
||||
N.y = cos(PI * input.unrotated_uv.y);
|
||||
N.z = -sin(PI * length(input.unrotated_uv));
|
||||
N.xz += normal.rg;
|
||||
N = mul((float3x3)GetCamera().inverse_view, N);
|
||||
N = normalize(N);
|
||||
|
||||
@@ -96,11 +118,13 @@ float4 main(VertextoPixel input) : SV_TARGET
|
||||
surface.pixel = pixel;
|
||||
surface.sss = material.subsurfaceScattering;
|
||||
surface.sss_inv = material.subsurfaceScattering_inv;
|
||||
surface.extinction = 0;
|
||||
surface.update();
|
||||
|
||||
TiledLighting(surface, lighting, GetFlatTileIndex(pixel));
|
||||
|
||||
color.rgb *= lighting.direct.diffuse + lighting.indirect.diffuse;
|
||||
color.rgb += lighting.indirect.specular;
|
||||
|
||||
//color.rgb = float3(unrotated_uv, 0);
|
||||
//color.rgb = float3(input.tex, 0);
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
#define DISABLE_SOFT_SHADOWMAP
|
||||
#endif // CARTOON
|
||||
|
||||
#ifdef WATER
|
||||
#define LIGHTING_SCATTER
|
||||
#endif // WATER
|
||||
|
||||
struct LightingPart
|
||||
{
|
||||
float3 diffuse;
|
||||
@@ -120,11 +124,12 @@ inline void light_directional(in ShaderEntity light, in Surface surface, inout L
|
||||
lighting.direct.diffuse = mad(light_color, BRDF_GetDiffuse(surface, surface_to_light), lighting.direct.diffuse);
|
||||
lighting.direct.specular = mad(light_color, BRDF_GetSpecular(surface, surface_to_light), lighting.direct.specular);
|
||||
|
||||
#ifdef WATER
|
||||
// Water extinction scattering:
|
||||
#ifdef LIGHTING_SCATTER
|
||||
const float scattering = ComputeScattering(saturate(dot(L, -surface.V)));
|
||||
lighting.direct.specular += scattering * light_color * (1 - surface.extinction) * (1 - sqr(1 - saturate(1 - surface.N.y)));
|
||||
#else
|
||||
lighting.indirect.specular += scattering * light_color * (1 - surface.extinction) * (1 - sqr(1 - saturate(1 - surface.N.y)));
|
||||
#endif // LIGHTING_SCATTER
|
||||
|
||||
#ifndef WATER
|
||||
// On non-water surfaces there can be procedural caustic if it's under ocean:
|
||||
const ShaderOcean ocean = GetWeather().ocean;
|
||||
if (ocean.texture_displacementmap >= 0)
|
||||
@@ -249,13 +254,12 @@ inline void light_point(in ShaderEntity light, in Surface surface, inout Lightin
|
||||
}
|
||||
#endif // DISABLE_AREA_LIGHTS
|
||||
|
||||
lighting.direct.specular = mad(light_color, BRDF_GetSpecular(surface, surface_to_light), lighting.direct.specular);
|
||||
lighting.indirect.specular = mad(light_color, BRDF_GetSpecular(surface, surface_to_light), lighting.direct.specular);
|
||||
|
||||
#ifdef WATER
|
||||
// Water extinction scattering:
|
||||
#ifdef LIGHTING_SCATTER
|
||||
const float scattering = ComputeScattering(saturate(dot(L, -surface.V)));
|
||||
lighting.direct.specular += scattering * light_color * (1 - surface.extinction) * (1 - sqr(1 - saturate(1 - surface.N.y)));
|
||||
#endif // WATER
|
||||
#endif // LIGHTING_SCATTER
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -339,11 +343,10 @@ inline void light_spot(in ShaderEntity light, in Surface surface, inout Lighting
|
||||
|
||||
lighting.direct.specular = mad(light_color, BRDF_GetSpecular(surface, surface_to_light), lighting.direct.specular);
|
||||
|
||||
#ifdef WATER
|
||||
// Water extinction scattering:
|
||||
#ifdef LIGHTING_SCATTER
|
||||
const float scattering = ComputeScattering(saturate(dot(L, -surface.V)));
|
||||
lighting.direct.specular += scattering * light_color * (1 - surface.extinction) * (1 - sqr(1 - saturate(1 - surface.N.y)));
|
||||
#endif // WATER
|
||||
lighting.indirect.specular += scattering * light_color * (1 - surface.extinction) * (1 - sqr(1 - saturate(1 - surface.N.y)));
|
||||
#endif // LIGHTING_SCATTER
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ void main(uint DTid : SV_DispatchThreadID)
|
||||
shadow /= 9.0;
|
||||
}
|
||||
|
||||
current = lerp(current, smoothstep(0, 1.4, sqrt(shadow)), GetDeltaTime() * 0.5);
|
||||
current = lerp(current, smoothstep(0, 1.4, sqrt(shadow)), saturate(GetDeltaTime() * 0.5));
|
||||
}
|
||||
|
||||
wetmap[DTid] = current;
|
||||
|
||||
@@ -807,7 +807,7 @@ namespace wi
|
||||
}
|
||||
|
||||
|
||||
void EmittedParticleSystem::Draw(const MaterialComponent& material, CommandList cmd) const
|
||||
void EmittedParticleSystem::Draw(const MaterialComponent& material, CommandList cmd, const PARTICLESHADERTYPE* shadertype_override) const
|
||||
{
|
||||
GraphicsDevice* device = wi::graphics::GetDevice();
|
||||
device->EventBegin("EmittedParticle", cmd);
|
||||
@@ -819,7 +819,7 @@ namespace wi
|
||||
else
|
||||
{
|
||||
const wi::enums::BLENDMODE blendMode = material.GetBlendMode();
|
||||
device->BindPipelineState(&PSO[blendMode][shaderType], cmd);
|
||||
device->BindPipelineState(&PSO[blendMode][shadertype_override == nullptr ? shaderType : *shadertype_override], cmd);
|
||||
|
||||
device->BindShadingRate(material.shadingRate, cmd);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace wi
|
||||
|
||||
// Must have a transform and material component, but mesh is optional
|
||||
void UpdateGPU(uint32_t instanceIndex, const wi::scene::MeshComponent* mesh, wi::graphics::CommandList cmd) const;
|
||||
void Draw(const wi::scene::MaterialComponent& material, wi::graphics::CommandList cmd) const;
|
||||
void Draw(const wi::scene::MaterialComponent& material, wi::graphics::CommandList cmd, const PARTICLESHADERTYPE* shadertype_override = nullptr) const;
|
||||
|
||||
void CreateRaytracingRenderData();
|
||||
|
||||
|
||||
@@ -5125,8 +5125,15 @@ void DrawSoftParticles(
|
||||
}
|
||||
}
|
||||
|
||||
if (!distortion && vis.scene->weather.rain_amount > 0)
|
||||
if (distortion && vis.scene->weather.rain_amount > 0)
|
||||
{
|
||||
// Draw with distortion shader override:
|
||||
EmittedParticleSystem::PARTICLESHADERTYPE shader = EmittedParticleSystem::PARTICLESHADERTYPE::SOFT_DISTORTION;
|
||||
vis.scene->rainEmitter.Draw(vis.scene->rainMaterial, cmd, &shader);
|
||||
}
|
||||
else if (!distortion && vis.scene->weather.rain_amount > 0)
|
||||
{
|
||||
// Draw normally
|
||||
vis.scene->rainEmitter.Draw(vis.scene->rainMaterial, cmd);
|
||||
}
|
||||
|
||||
|
||||
@@ -4818,7 +4818,7 @@ namespace wi::scene
|
||||
{
|
||||
Texture gradientTex = wi::texturehelper::CreateGradientTexture(
|
||||
wi::texturehelper::GradientType::Circular,
|
||||
32, 32,
|
||||
64, 64,
|
||||
XMFLOAT2(0.5f, 0.5f), XMFLOAT2(0.5f, 0),
|
||||
wi::texturehelper::GradientFlags::Smoothstep | wi::texturehelper::GradientFlags::Inverse
|
||||
);
|
||||
@@ -4831,7 +4831,21 @@ namespace wi::scene
|
||||
wi::renderer::AddDeferredBlockCompression(gradientTex, gradientTexBC);
|
||||
rainMaterial.textures[MaterialComponent::BASECOLORMAP].resource.SetTexture(gradientTexBC);
|
||||
}
|
||||
rainMaterial.shadingRate = ShadingRate::RATE_4X4;
|
||||
if (!rainMaterial.textures[MaterialComponent::NORMALMAP].resource.IsValid())
|
||||
{
|
||||
Texture gradientTex = wi::texturehelper::CreateLensDistortionNormalMap(
|
||||
32, 32
|
||||
);
|
||||
Texture gradientTexBC;
|
||||
TextureDesc desc = gradientTex.GetDesc();
|
||||
desc.format = Format::BC5_UNORM;
|
||||
desc.swizzle = { wi::graphics::ComponentSwizzle::R,wi::graphics::ComponentSwizzle::G,wi::graphics::ComponentSwizzle::ONE,wi::graphics::ComponentSwizzle::ONE };
|
||||
bool success = device->CreateTexture(&desc, nullptr, &gradientTexBC);
|
||||
assert(success);
|
||||
wi::renderer::AddDeferredBlockCompression(gradientTex, gradientTexBC);
|
||||
rainMaterial.textures[MaterialComponent::NORMALMAP].resource.SetTexture(gradientTexBC);
|
||||
}
|
||||
//rainMaterial.shadingRate = ShadingRate::RATE_4X4;
|
||||
TransformComponent transform;
|
||||
transform.scale_local = XMFLOAT3(30, 30, 30);
|
||||
transform.translation_local.x = camera.Eye.x + camera.At.x * 10;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace wi::version
|
||||
// minor features, major updates, breaking compatibility changes
|
||||
const int minor = 71;
|
||||
// minor bug fixes, alterations, refactors, updates
|
||||
const int revision = 511;
|
||||
const int revision = 512;
|
||||
|
||||
const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user