Add support for rotating envmap
This commit is contained in:
Binary file not shown.
@@ -3,7 +3,8 @@
|
||||
"action_rotate": "middle",
|
||||
"action_pan": "shift+middle",
|
||||
"action_zoom": "ctrl+middle",
|
||||
"rotate_light": "shift+middle",
|
||||
"rotate_light": "shift+right",
|
||||
"rotate_envmap": "ctrl+right",
|
||||
"set_clone_source": "alt",
|
||||
"stencil_transform": "ctrl",
|
||||
"stencil_hide": "z",
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
"action_pan": "alt+middle",
|
||||
"action_zoom": "alt+right",
|
||||
"rotate_light": "shift+middle",
|
||||
"rotate_envmap": "ctrl+middle",
|
||||
"set_clone_source": "alt",
|
||||
"stencil_transform": "ctrl",
|
||||
"stencil_hide": "z",
|
||||
|
||||
Binary file not shown.
@@ -377,11 +377,11 @@ void createBasis(vec3 normal, out vec3 tangent, out vec3 binormal) {
|
||||
#end
|
||||
|
||||
public static var str_envMapEquirect = "
|
||||
vec2 envMapEquirect(const vec3 normal) {
|
||||
vec2 envMapEquirect(const vec3 normal, const float angle) {
|
||||
const float PI = 3.1415926535;
|
||||
const float PI2 = PI * 2.0;
|
||||
float phi = acos(normal.z);
|
||||
float theta = atan(-normal.y, normal.x) + PI;
|
||||
float theta = atan(-normal.y, normal.x) + PI + angle;
|
||||
return vec2(theta / PI2, phi / PI);
|
||||
}
|
||||
";
|
||||
|
||||
@@ -12,7 +12,7 @@ struct Vertex {
|
||||
|
||||
struct RayGenConstantBuffer {
|
||||
float4 v0; // frame, strength, radius, offset
|
||||
float4 v1; // envstr
|
||||
float4 v1; // envstr, upaxis, envangle
|
||||
float4 v2;
|
||||
float4 v3;
|
||||
float4 v4;
|
||||
@@ -113,7 +113,7 @@ void closesthit(inout RayPayload payload, in BuiltInTriangleIntersectionAttribut
|
||||
|
||||
[shader("miss")]
|
||||
void miss(inout RayPayload payload) {
|
||||
float2 tex_coord = equirect(WorldRayDirection());
|
||||
float2 tex_coord = equirect(WorldRayDirection(), constant_buffer.v1.z);
|
||||
uint2 size;
|
||||
mytexture_env.GetDimensions(size.x, size.y);
|
||||
float3 texenv = mytexture_env.Load(uint3(tex_coord * size, 0)).rgb * constant_buffer.v1.x;
|
||||
|
||||
@@ -13,7 +13,7 @@ struct Vertex {
|
||||
struct RayGenConstantBuffer {
|
||||
float4 eye; // xyz, frame
|
||||
float4x4 inv_vp;
|
||||
float4 params; // envstr
|
||||
float4 params; // envstr, envangle
|
||||
};
|
||||
|
||||
struct RayPayload {
|
||||
@@ -216,7 +216,7 @@ void miss(inout RayPayload payload) {
|
||||
}
|
||||
#endif
|
||||
|
||||
float2 tex_coord = equirect(WorldRayDirection());
|
||||
float2 tex_coord = equirect(WorldRayDirection(), constant_buffer.params.y);
|
||||
uint2 size;
|
||||
mytexture_env.GetDimensions(size.x, size.y);
|
||||
float3 texenv = mytexture_env.Load(uint3(tex_coord * size, 0)).rgb * abs(constant_buffer.params.x);
|
||||
|
||||
@@ -29,11 +29,11 @@ void generate_camera_ray(float2 screen_pos, out float3 ray_origin, out float3 ra
|
||||
ray_dir = normalize(world.xyz - ray_origin);
|
||||
}
|
||||
|
||||
float2 equirect(float3 normal) {
|
||||
float2 equirect(float3 normal, float angle) {
|
||||
const float PI = 3.1415926535;
|
||||
const float PI2 = PI * 2.0;
|
||||
float phi = acos(normal.z);
|
||||
float theta = atan2(-normal.y, normal.x) + PI;
|
||||
float theta = atan2(-normal.y, normal.x) + PI + angle;
|
||||
return float2(theta / PI2, phi / PI);
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class RenderPathRaytrace {
|
||||
f32[19] = helpMat._33;
|
||||
f32[20] = Scene.active.world.probe.raw.strength;
|
||||
if (!Context.showEnvmap) f32[20] = -f32[20];
|
||||
// f32[21] = Context.showEnvmap ? 1.0 : 0.0;
|
||||
f32[21] = Context.envmapAngle;
|
||||
// var right = cam.rightWorld().normalize();
|
||||
// f32[21] = right.x;
|
||||
// f32[22] = right.y;
|
||||
@@ -190,6 +190,7 @@ class RenderPathRaytrace {
|
||||
f32[3] = Context.bakeAoOffset;
|
||||
f32[4] = Scene.active.world.probe.raw.strength;
|
||||
f32[5] = Context.bakeUpAxis;
|
||||
f32[6] = Context.envmapAngle;
|
||||
|
||||
var framebuffer = path.renderTargets.get("baketex2").image;
|
||||
Krom.raytraceDispatchRays(framebuffer.renderTarget_, f32.buffer);
|
||||
|
||||
@@ -214,7 +214,7 @@ void main() {
|
||||
#ifdef _Rad
|
||||
vec3 reflectionWorld = reflect(-v, n);
|
||||
float lod = getMipFromRoughness(roughness, envmapNumMipmaps);
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld), lod).rgb;
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld, 0.0), lod).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef _EnvLDR
|
||||
|
||||
@@ -218,7 +218,7 @@ void main() {
|
||||
#ifdef _Rad
|
||||
vec3 reflectionWorld = reflect(-v, n);
|
||||
float lod = getMipFromRoughness(roughness, envmapNumMipmaps);
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld), lod).rgb;
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld, 0.0), lod).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef _EnvLDR
|
||||
|
||||
@@ -79,7 +79,7 @@ void main() {
|
||||
float fresnel = 1.0 - max(dot(n2, v), 0.0);
|
||||
fresnel = pow(fresnel, 30.0) * 0.45;
|
||||
vec3 r = reflect(-v, n2);
|
||||
vec3 reflected = textureLod(senvmapRadiance, envMapEquirect(r), 0).rgb;
|
||||
vec3 reflected = textureLod(senvmapRadiance, envMapEquirect(r, 0.0), 0).rgb;
|
||||
vec3 refracted = textureLod(tex, tc, 0.0).rgb;
|
||||
fragColor.rgb = mix(refracted, reflected, fresnel * waterReflect);
|
||||
fragColor.rgb *= waterColor;
|
||||
|
||||
@@ -147,7 +147,7 @@ void main() {
|
||||
#ifndef _EnvSky // Prevent case when sky radiance is enabled
|
||||
#ifdef _EnvTex
|
||||
vec3 n = normalize(normal);
|
||||
fragColor.rgb = texture(envmap, envMapEquirect(n)).rgb * envmapStrength;
|
||||
fragColor.rgb = texture(envmap, envMapEquirect(n, 0.0)).rgb * envmapStrength;
|
||||
#ifdef _EnvLDR
|
||||
fragColor.rgb = pow(fragColor.rgb, vec3(2.2));
|
||||
#endif
|
||||
@@ -162,9 +162,6 @@ void main() {
|
||||
|
||||
#ifdef _EnvSky
|
||||
vec3 n = normalize(normal);
|
||||
float phi = acos(n.z);
|
||||
float theta = atan(-n.y, n.x) + PI;
|
||||
|
||||
float cos_theta = clamp(n.z, 0.0, 1.0);
|
||||
float cos_gamma = dot(n, hosekSunDirection);
|
||||
float gamma_val = acos(cos_gamma);
|
||||
|
||||
@@ -45,6 +45,7 @@ uniform vec3 eyeSnap;
|
||||
#endif
|
||||
|
||||
uniform float envmapStrength;
|
||||
uniform float envmapAngle;
|
||||
#ifdef _Irr
|
||||
uniform vec4 shirr[7];
|
||||
#endif
|
||||
@@ -216,7 +217,7 @@ void main() {
|
||||
#ifdef _Rad
|
||||
vec3 reflectionWorld = reflect(-v, n);
|
||||
float lod = getMipFromRoughness(roughness, envmapNumMipmaps);
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld), lod).rgb;
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld, envmapAngle), lod).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef _EnvLDR
|
||||
|
||||
@@ -46,6 +46,7 @@ uniform vec3 eyeSnap;
|
||||
#endif
|
||||
|
||||
uniform float envmapStrength;
|
||||
uniform float envmapAngle;
|
||||
#ifdef _Irr
|
||||
uniform vec4 shirr[7];
|
||||
#endif
|
||||
@@ -217,7 +218,7 @@ void main() {
|
||||
#ifdef _Rad
|
||||
vec3 reflectionWorld = reflect(-v, n);
|
||||
float lod = getMipFromRoughness(roughness, envmapNumMipmaps);
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld), lod).rgb;
|
||||
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld, envmapAngle), lod).rgb;
|
||||
#endif
|
||||
|
||||
#ifdef _EnvLDR
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#ifdef _EnvStr
|
||||
uniform float envmapStrength;
|
||||
#endif
|
||||
uniform float envmapAngle;
|
||||
|
||||
in vec3 normal;
|
||||
out vec4 fragColor;
|
||||
@@ -137,7 +138,7 @@ void main() {
|
||||
#ifndef _EnvSky // Prevent case when sky radiance is enabled
|
||||
#ifdef _EnvTex
|
||||
vec3 n = normalize(normal);
|
||||
fragColor.rgb = texture(envmap, envMapEquirect(n)).rgb * envmapStrength;
|
||||
fragColor.rgb = texture(envmap, envMapEquirect(n, envmapAngle)).rgb * envmapStrength;
|
||||
#ifdef _EnvLDR
|
||||
fragColor.rgb = pow(fragColor.rgb, vec3(2.2));
|
||||
#endif
|
||||
|
||||
@@ -10,11 +10,11 @@ float hash(const vec2 p) {
|
||||
return fract(sin(h) * 43758.5453123);
|
||||
}
|
||||
|
||||
vec2 envMapEquirect(const vec3 normal) {
|
||||
vec2 envMapEquirect(const vec3 normal, const float angle) {
|
||||
const float PI = 3.1415926535;
|
||||
const float PI2 = PI * 2.0;
|
||||
float phi = acos(normal.z);
|
||||
float theta = atan(-normal.y, normal.x) + PI;
|
||||
float theta = atan(-normal.y, normal.x) + PI + angle;
|
||||
return vec2(theta / PI2, phi / PI);
|
||||
}
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ class Context {
|
||||
public static var showEnvmapHandle = new Handle({selected: false});
|
||||
public static var showEnvmapBlur = false;
|
||||
public static var showEnvmapBlurHandle = new Handle({selected: false});
|
||||
public static var envmapAngle = 0.0;
|
||||
public static var drawWireframe = false;
|
||||
public static var wireframeHandle = new Handle({selected: false});
|
||||
public static var drawTexels = false;
|
||||
|
||||
@@ -349,10 +349,11 @@ class MakeMesh {
|
||||
frag.write('vec2 envBRDF = texture(senvmapBrdf, vec2(roughness, 1.0 - dotNV)).xy;');
|
||||
frag.add_uniform('sampler2D senvmapRadiance', '_envmapRadiance');
|
||||
frag.add_uniform('int envmapNumMipmaps', '_envmapNumMipmaps');
|
||||
frag.add_uniform('float envmapAngle', '_envmapAngle');
|
||||
frag.write('vec3 wreflect = reflect(-vVec, wn);');
|
||||
frag.write('float envlod = roughness * float(envmapNumMipmaps);');
|
||||
frag.add_function(MaterialFunctions.str_envMapEquirect);
|
||||
frag.write('vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(wreflect), envlod).rgb;');
|
||||
frag.write('vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(wreflect, envmapAngle), envlod).rgb;');
|
||||
|
||||
frag.add_uniform('vec3 lightArea0', '_lightArea0');
|
||||
frag.add_uniform('vec3 lightArea1', '_lightArea1');
|
||||
|
||||
@@ -77,6 +77,9 @@ class Uniforms {
|
||||
if (link == "_objectId") {
|
||||
return Project.paintObjects.indexOf(Context.paintObject);
|
||||
}
|
||||
if (link == "_envmapAngle") {
|
||||
return Context.envmapAngle;
|
||||
}
|
||||
#end
|
||||
#if arm_world
|
||||
if (link == "_voxelgiHalfExtentsUni") {
|
||||
|
||||
Reference in New Issue
Block a user