Add support for rotating envmap
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user