Translucency support for brute shader

This commit is contained in:
luboslenco
2020-09-10 16:35:13 +02:00
parent b769b0f612
commit 6b13f17c93
4 changed files with 34 additions and 1 deletions
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,11 @@
// #define _EMISSION
// #define _SUBSURFACE
// #define _RENDER
// #define _ROULETTE
// #define _TRANSPARENCY
// #define _TRANSLUCENCY
#include "std/rand.hlsl"
#include "std/attrib.hlsl"
#include "std/math.hlsl"
@@ -36,7 +44,11 @@ Texture2D<float4> mytexture_scramble : register(t8);
Texture2D<float4> mytexture_rank : register(t9);
static const int SAMPLES = 64;
#ifdef _TRANSLUCENCY
static const int DEPTH = 6;
#else
static const int DEPTH = 3; // Opaque hits
#endif
static uint seed = 0;
#ifdef _TRANSPARENCY
static const int DEPTH_TRANSPARENT = 16; // Transparent hits
@@ -182,10 +194,23 @@ void closesthit(inout RayPayload payload, in BuiltInTriangleIntersectionAttribut
texpaint1.g = -texpaint1.g;
n = mul(texpaint1.rgb, float3x3(tangent, binormal, n));
float3 diffuseDir = cos_weighted_hemisphere_direction(n, payload.color.a, seed, constant_buffer.eye.w, mytexture_sobol, mytexture_scramble, mytexture_rank);
float f = rand(DispatchRaysIndex().x, DispatchRaysIndex().y, payload.color.a, seed, constant_buffer.eye.w, mytexture_sobol, mytexture_scramble, mytexture_rank);
#ifdef _TRANSLUCENCY
float3 diffuseDir = texpaint0.a < f ?
cos_weighted_hemisphere_direction(WorldRayDirection(), payload.color.a, seed, constant_buffer.eye.w, mytexture_sobol, mytexture_scramble, mytexture_rank) :
cos_weighted_hemisphere_direction(n, payload.color.a, seed, constant_buffer.eye.w, mytexture_sobol, mytexture_scramble, mytexture_rank);
#else
float3 diffuseDir = cos_weighted_hemisphere_direction(n, payload.color.a, seed, constant_buffer.eye.w, mytexture_sobol, mytexture_scramble, mytexture_rank);
#endif
if (f < 0.5) {
#ifdef _TRANSLUCENCY
float3 specularDir = texpaint0.a < f * 2 ? WorldRayDirection() : reflect(WorldRayDirection(), n);
#else
float3 specularDir = reflect(WorldRayDirection(), n);
#endif
payload.ray_dir = lerp(specularDir, diffuseDir, texpaint2.g * texpaint2.g);
float3 v = normalize(constant_buffer.eye.xyz - hit_world_position());
float dotNV = max(dot(n, v), 0.0);
+8
View File
@@ -215,7 +215,11 @@ class MakePaint {
frag.write('vec3 nortan = $nortan;');
frag.write('float height = $height;');
frag.write('float mat_opacity = $opac;');
#if (kha_direct3d12 || kha_vulkan)
frag.write('float opacity = 1.0;');
#else
frag.write('float opacity = mat_opacity;');
#end
if (Context.layer.fill_layer == null) {
frag.write('opacity *= brushOpacity;');
}
@@ -387,7 +391,11 @@ class MakePaint {
frag.add_uniform('sampler2D texpaint_pack_undo', '_texpaint_pack_undo');
frag.write('vec4 sample_nor_undo = textureLod(texpaint_nor_undo, sample_tc, 0.0);');
frag.write('vec4 sample_pack_undo = textureLod(texpaint_pack_undo, sample_tc, 0.0);');
#if (kha_direct3d12 || kha_vulkan)
frag.write('fragColor[0] = vec4(' + MakeMaterial.blendMode(frag, Context.brushBlending, 'sample_undo.rgb', 'basecol', 'str') + ', mat_opacity);');
#else
frag.write('fragColor[0] = vec4(' + MakeMaterial.blendMode(frag, Context.brushBlending, 'sample_undo.rgb', 'basecol', 'str') + ', max(str, sample_undo.a));');
#end
frag.write('fragColor[1] = vec4(mix(sample_nor_undo.rgb, nortan, str), matid);');
if (Context.material.paintHeight && MakeMaterial.heightUsed) {
frag.write('fragColor[2] = mix(sample_pack_undo, vec4(occlusion, roughness, metallic, height), str);');