Shader fixes

This commit is contained in:
Lubos Lenco 2018-01-07 20:01:43 +01:00
parent 67f5bf0c6a
commit cea57c33ea
10 changed files with 51 additions and 45 deletions

View file

@ -26,10 +26,10 @@ uniform vec2 lightPlane;
in vec4 wvpposition;
out vec4 fragColor;
const float tScat = 0.04;
const float tScat = 0.08;
const float tAbs = 0.0;
const float tExt = tScat + tAbs;
const float stepLen = 1.0 / 20.0;
const float stepLen = 1.0 / volumSteps;
const float lighting = 0.4;
// float lighting(vec3 p) {
@ -67,8 +67,8 @@ void main() {
vec2 texCoord = screenPosition * 0.5 + 0.5;
// texCoord += vec2(0.5 / screenSize); // Half pixel offset
// float pixelRayMarchNoise = texture(snoise, texCoord).r * 2.0 - 1.0;
// pixelRayMarchNoise *= 0.2;
float pixelRayMarchNoise = texture(snoise, texCoord).r * 2.0 - 1.0;
pixelRayMarchNoise *= 0.2;
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
vec3 worldPos = getPos2(invVP, depth, texCoord);
@ -87,7 +87,7 @@ void main() {
float curOpticalDepth = exp(-tExt * stepLenWorld);
float scatteredLightAmount = 0.0;
curPos += stepLenWorld * viewVecNorm;// * pixelRayMarchNoise;
curPos += stepLenWorld * viewVecNorm * pixelRayMarchNoise;
for (float l = stepLen; l < 0.99999; l += stepLen) { // Do not do the first and last steps
rayStep(curPos, curOpticalDepth, scatteredLightAmount, stepLenWorld, viewVecNorm);

View file

@ -44,8 +44,7 @@
},
{
"name": "snoise",
"link": "_noise8",
"ifdef": ["_Disabled"]
"link": "_noise8"
},
{
"name": "lightPlane",

View file

@ -10,7 +10,7 @@ uniform sampler2D gbufferD;
//!uniform sampler2D shadowMap;
//!uniform samplerCube shadowMapCube;
#endif
// uniform sampler2D snoise;
uniform sampler2D snoise;
uniform mat4 LWVP;
uniform float shadowsBias;
@ -30,7 +30,7 @@ out vec4 fragColor;
const float tScat = 0.08;
const float tAbs = 0.0;
const float tExt = tScat + tAbs;
const float stepLen = 1.0 / 20.0;
const float stepLen = 1.0 / volumSteps;
const float lighting = 0.4;
// float lighting(vec3 p) {
@ -62,6 +62,9 @@ void rayStep(inout vec3 curPos, inout float curOpticalDepth, inout float scatter
void main() {
float pixelRayMarchNoise = texture(snoise, texCoord).r * 2.0 - 1.0;
pixelRayMarchNoise *= 0.2;
float depth = texture(gbufferD, texCoord).r * 2.0 - 1.0;
vec3 worldPos = getPos(eye, eyeLook, viewRay, depth, cameraProj);
@ -79,7 +82,7 @@ void main() {
float curOpticalDepth = exp(-tExt * stepLenWorld);
float scatteredLightAmount = 0.0;
curPos += stepLenWorld * viewVecNorm;
curPos += stepLenWorld * viewVecNorm * pixelRayMarchNoise;
for (float l = stepLen; l < 0.99999; l += stepLen) { // Do not do the first and last steps
rayStep(curPos, curOpticalDepth, scatteredLightAmount, stepLenWorld, viewVecNorm);

View file

@ -34,8 +34,7 @@
},
{
"name": "snoise",
"link": "_noise8",
"ifdef": ["_Disabled"]
"link": "_noise8"
},
{
"name": "lightPlane",

View file

@ -26,7 +26,7 @@
uniform float time;
// uniform vec3 eye;
const float difference = cloudsUpper - cloudsLower;
const float steps = 45.0;
const float steps = 25.0;
#endif
#ifdef _EnvTex
uniform sampler2D envmap;
@ -95,7 +95,7 @@ vec2 traceCloud(vec3 pos, vec3 dir) {
vec3 add = dir * ((end - beg) / steps);
vec2 shadeSum = vec2(0.0);
for (int i = 0; i < 45; i++) {
for (int i = 0; i < steps; i++) {
shadeSum = doCloudTrace(add, shadeSum);
if (shadeSum.y >= 1.0) return shadeSum;
}

View file

@ -24,7 +24,7 @@ class RenderPathCreator {
#if (rp_renderer == "Forward")
static function init() {
#if kha_webgl
#if (rp_shadowmap && kha_webgl)
initEmpty();
#end
@ -142,8 +142,8 @@ class RenderPathCreator {
t.height = 0;
t.displayp = getDisplayp();
t.format = "R8";
// var ss = getSuperSampling();
t.scale = 0.5;
var ss = getSuperSampling();
if (ss != 1) t.scale = ss;
path.createRenderTarget(t);
}
{
@ -153,8 +153,8 @@ class RenderPathCreator {
t.height = 0;
t.displayp = getDisplayp();
t.format = "R8";
// var ss = getSuperSampling();
t.scale = 0.5;
var ss = getSuperSampling();
if (ss != 1) t.scale = ss;
path.createRenderTarget(t);
}
}
@ -470,7 +470,7 @@ class RenderPathCreator {
#if (rp_renderer == "Deferred")
static function init() {
#if kha_webgl
#if (rp_shadowmap && kha_webgl)
initEmpty();
#end
@ -1386,7 +1386,7 @@ class RenderPathCreator {
return target;
}
#if kha_webgl
#if (rp_shadowmap && kha_webgl)
static function initEmpty() {
// Bind empty when requested target is not found
var tempty = new RenderTargetRaw();

View file

@ -158,30 +158,7 @@ def make_base(con_mesh, parse_opacity):
write_material_attribs_post(con_mesh, frag)
if not is_displacement and not vattr_written:
billboard = mat_state.material.arm_billboard
particle = mat_state.material.arm_particle
wrd = bpy.data.worlds['Arm']
# Particles
if particle != 'off':
if particle == 'gpu':
make_particle.write(vert, particle_info=cycles.particle_info)
# Billboards
if billboard == 'spherical':
vert.add_uniform('mat4 WV', '_worldViewMatrix')
vert.add_uniform('mat4 P', '_projectionMatrix')
vert.write('gl_Position = P * (WV * vec4(0.0, 0.0, spos.z, 1.0) + vec4(spos.x, spos.y, 0.0, 0.0));')
else:
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix')
vert.write('gl_Position = WVP * spos;')
else:
# Billboards
if billboard == 'spherical':
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrixSphere')
elif billboard == 'cylindrical':
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrixCylinder')
else: # off
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix')
vert.write('gl_Position = WVP * spos;')
write_vertpos(vert)
if con_mesh.is_elem('tex'):
vert.add_out('vec2 texCoord')
@ -243,6 +220,31 @@ def make_base(con_mesh, parse_opacity):
tese.write('wposition += wnormal * disp * 0.2;')
tese.write('gl_Position = VP * vec4(wposition, 1.0);')
def write_vertpos(vert):
billboard = mat_state.material.arm_billboard
particle = mat_state.material.arm_particle
# Particles
if particle != 'off':
if particle == 'gpu':
make_particle.write(vert, particle_info=cycles.particle_info)
# Billboards
if billboard == 'spherical':
vert.add_uniform('mat4 WV', '_worldViewMatrix')
vert.add_uniform('mat4 P', '_projectionMatrix')
vert.write('gl_Position = P * (WV * vec4(0.0, 0.0, spos.z, 1.0) + vec4(spos.x, spos.y, 0.0, 0.0));')
else:
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix')
vert.write('gl_Position = WVP * spos;')
else:
# Billboards
if billboard == 'spherical':
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrixSphere')
elif billboard == 'cylindrical':
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrixCylinder')
else: # off
vert.add_uniform('mat4 WVP', '_worldViewProjectionMatrix')
vert.write('gl_Position = WVP * spos;')
def write_norpos(con_mesh, vert, declare=False, write_nor=True):
prep = ''
if declare:

View file

@ -298,6 +298,7 @@ def init_properties():
bpy.types.World.arm_ssr_jitter = bpy.props.FloatProperty(name="Jitter", default=0.6, update=assets.invalidate_shader_cache)
bpy.types.World.arm_volumetric_light_air_turbidity = bpy.props.FloatProperty(name="Air Turbidity", default=1.0, update=assets.invalidate_shader_cache)
bpy.types.World.arm_volumetric_light_air_color = bpy.props.FloatVectorProperty(name="Air Color", size=3, default=[1.0, 1.0, 1.0], subtype='COLOR', min=0, max=1, update=assets.invalidate_shader_cache)
bpy.types.World.arm_volumetric_light_steps = bpy.props.IntProperty(name="Steps", default=20, min=0, update=assets.invalidate_shader_cache)
bpy.types.World.arm_shadowmap_split = bpy.props.FloatProperty(name="Cascade Split", description="Split factor for cascaded shadow maps, higher factor favors detail on close surfaces", default=0.8, update=assets.invalidate_shader_cache)
bpy.types.World.arm_autoexposure_strength = bpy.props.FloatProperty(name="Auto Exposure Strength", default=0.7, update=assets.invalidate_shader_cache)
bpy.types.World.arm_ssrs_ray_step = bpy.props.FloatProperty(name="Ray Step", default=0.01, update=assets.invalidate_shader_cache)

View file

@ -1128,6 +1128,7 @@ class ArmRenderPropsPanel(bpy.types.Panel):
layout.label('Volumetric Light')
layout.prop(wrd, 'arm_volumetric_light_air_turbidity')
layout.prop(wrd, 'arm_volumetric_light_air_color')
layout.prop(wrd, 'arm_volumetric_light_steps')
layout.label('Compositor')
layout.prop(wrd, 'arm_letterbox')

View file

@ -462,6 +462,7 @@ const float penumbraDistance = """ + str(rpdat.arm_soft_shadows_distance) + """;
f.write(
"""const float volumAirTurbidity = """ + str(round(wrd.arm_volumetric_light_air_turbidity * 100) / 100) + """;
const vec3 volumAirColor = vec3(""" + str(round(wrd.arm_volumetric_light_air_color[0] * 100) / 100) + """, """ + str(round(wrd.arm_volumetric_light_air_color[1] * 100) / 100) + """, """ + str(round(wrd.arm_volumetric_light_air_color[2] * 100) / 100) + """);
const int volumSteps = """ + str(wrd.arm_volumetric_light_steps) + """;
""")
if rpdat.rp_autoexposure: