Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GL_INVALID_OPERATION #423

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Engine/BuiltInShaders/UniformDefines/U_AtmophericScattering.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
#define IRRADIANCE_TEXTURE_WIDTH 64
#define IRRADIANCE_TEXTURE_HEIGHT 16

#define ATM_TRANSMITTANCE_SLOT 15
#define ATM_SINGLE_RAYLEIGH_SCATTERING_SLOT 14
#define ATM_SINGLE_MIE_SCATTERING_SLOT 13
#define ATM_MULTIPLE_SCATTERING_SLOT 12
#define ATM_SCATTERING_DENSITY 11
#define ATM_IRRADIANCE_SLOT 10
#define ATM_SCATTERING_SLOT 9
#define ATM_TRANSMITTANCE_SLOT 7
#define ATM_SINGLE_RAYLEIGH_SCATTERING_SLOT 6
#define ATM_SINGLE_MIE_SCATTERING_SLOT 5
#define ATM_MULTIPLE_SCATTERING_SLOT 4
#define ATM_SCATTERING_DENSITY 3
#define ATM_IRRADIANCE_SLOT 2
#define ATM_SCATTERING_SLOT 1
T-rvw marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions Engine/BuiltInShaders/common/Envirnoment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@ vec3 GetATM(Material material, vec3 worldPos) {
vec3 cameraPos = GetCamera().position / vec3_splat(100.0 * 100.0);
vec3 worldPosOnEarth = worldPos / vec3_splat(100.0 * 100.0);
// The coordinate system's origin of atmospheric scattering is the planet center.
cameraPos += vec3(0.0, ATMOSPHERE.bottom_radius + u_HeightOffsetAndshadowLength.x, 0.0);
worldPosOnEarth += vec3(0.0, ATMOSPHERE.bottom_radius + u_HeightOffsetAndshadowLength.x, 0.0);
cameraPos += vec3(0.0, GetAtmosphere().bottom_radius + u_HeightOffsetAndshadowLength.x, 0.0);
worldPosOnEarth += vec3(0.0, GetAtmosphere().bottom_radius + u_HeightOffsetAndshadowLength.x, 0.0);

// Irradiance from Sun and Sky.
vec3 irradiance = vec3_splat(0.0);
vec3 sunIrradiance = GetSunAndSkyIrradiance(ATMOSPHERE, worldPosOnEarth, material.normal, sunDir, irradiance);
vec3 sunIrradiance = GetSunAndSkyIrradiance(GetAtmosphere(), worldPosOnEarth, material.normal, sunDir, irradiance);
irradiance += sunIrradiance;

vec3 radianceToCamera = material.albedo * vec3_splat(CD_INV_PI) * irradiance;

// Aerial perspective.
vec3 transmittance;
// TODO : Need a shadow volume algorithm to get shadow_length parameter.
vec3 skyRadianceToPoint = GetSkyRadianceToPoint(ATMOSPHERE, cameraPos, worldPosOnEarth, u_HeightOffsetAndshadowLength.y, sunDir, transmittance);
vec3 skyRadianceToPoint = GetSkyRadianceToPoint(GetAtmosphere(), cameraPos, worldPosOnEarth, u_HeightOffsetAndshadowLength.y, sunDir, transmittance);
radianceToCamera = radianceToCamera * transmittance + skyRadianceToPoint;

envColor = radianceToCamera;
Expand Down
61 changes: 42 additions & 19 deletions Engine/BuiltInShaders/common/atm_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,48 @@
#define TEMPLATE_ARGUMENT(x)
#define assert(x)

// ------------------------------ Parameters ------------------------------ //

// TODO : add function to generate these parameters.
static const AtmosphereParameters ATMOSPHERE = {
vec3(10.000000, 10.000000, 10.000000),
0.004675,
6360.000000,
6420.000000,
{{0.000000, 0.000000, 0.000000, 0.000000, 0.000000},
{0.000000, 1.000000, -0.125000, 0.000000, 0.000000}},
vec3(0.005802, 0.013558, 0.033100),
{{0.000000, 0.000000, 0.000000, 0.000000, 0.000000},
{0.000000, 1.000000, -0.833333, 0.000000, 0.000000}},
vec3(0.003996, 0.003996, 0.003996),
vec3(0.004440, 0.004440, 0.004440),
0.900000,
{{25.000000, 0.000000, 0.000000, 0.066667, -0.666667},
{0.000000, 0.000000, 0.000000, -0.066667, 2.666667}},
vec3(0.000650, 0.001881, 0.000085),
vec3(0.100000, 0.100000, 0.100000),
-0.207912};

AtmosphereParameters GetAtmosphere() {
DensityProfileLayer densityProfileLayer0 = {0.000000, 0.000000, 0.000000, 0.000000, 0.000000};
DensityProfileLayer densityProfileLayer1 = {0.000000, 1.000000, -0.125000, 0.000000, 0.000000};
DensityProfile densityProfile1;
densityProfile1.layers[0] = densityProfileLayer0;
densityProfile1.layers[1] = densityProfileLayer1;

DensityProfileLayer densityProfileLayer2 = {0.000000, 0.000000, 0.000000, 0.000000, 0.000000};
DensityProfileLayer densityProfileLayer3 = {0.000000, 1.000000, -0.833333, 0.000000, 0.00000};
DensityProfile densityProfile2;
densityProfile2.layers[0] = densityProfileLayer2;
densityProfile2.layers[1] = densityProfileLayer3;

DensityProfileLayer densityProfileLayer4 = {25.000000, 0.000000, 0.000000, 0.066667, -0.666667};
DensityProfileLayer densityProfileLayer5 = {0.000000, 0.000000, 0.000000, -0.066667, 2.666667};
DensityProfile densityProfile3;
densityProfile3.layers[0] = densityProfileLayer4;
densityProfile3.layers[1] = densityProfileLayer5;

AtmosphereParameters atmosphere = {
vec3(10.000000, 10.000000, 10.000000),
0.004675,
6360.000000,
6420.000000,
densityProfile1,
vec3(0.005802, 0.013558, 0.033100),
densityProfile2,
vec3(0.003996, 0.003996, 0.003996),
vec3(0.004440, 0.004440, 0.004440),
0.900000,
densityProfile3,
vec3(0.000650, 0.001881, 0.000085),
vec3(0.100000, 0.100000, 0.100000),
-0.207912};

return atmosphere;
}
Comment on lines +21 to +57
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it static.



// ------------------------------ Textures ------------------------------ //

Expand Down Expand Up @@ -569,7 +592,7 @@ void GetRMuSFromIrradianceTextureUv(IN(AtmosphereParameters) atmosphere, IN(vec2
mu_s = ClampCosine(2.0 * x_mu_s - 1.0);
}

static const vec2 IRRADIANCE_TEXTURE_SIZE = vec2(IRRADIANCE_TEXTURE_WIDTH, IRRADIANCE_TEXTURE_HEIGHT);
CONST(vec2) IRRADIANCE_TEXTURE_SIZE = vec2(IRRADIANCE_TEXTURE_WIDTH, IRRADIANCE_TEXTURE_HEIGHT);

// Direct Irradiance -> Texture
IrradianceSpectrum ComputeDirectIrradianceTexture(IN(AtmosphereParameters) atmosphere, IN(vec2) frag_coord) {
Expand Down
9 changes: 5 additions & 4 deletions Engine/BuiltInShaders/shaders/cs_ComputeDirectIrradiance.sc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ IMAGE2D_WR(s_irradiance, rgba32f, 1);
NUM_THREADS(8, 8, 1)
void main()
{
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec2 uv = gl_GlobalInvocationID.xy;
ivec2 iuv = ivec2(uv);

vec3 delta_irradiance = ComputeDirectIrradianceTexture(ATMOSPHERE, uv);
vec3 delta_irradiance = ComputeDirectIrradianceTexture(GetAtmosphere(), uv);
vec3 irradiance = vec3_splat(0.0);

imageStore(s_delta_irradiance, uv, vec4(delta_irradiance.xyz, 1.0));
imageStore(s_irradiance, uv, vec4(irradiance.xyz, 1.0));
imageStore(s_delta_irradiance, iuv, vec4(delta_irradiance.xyz, 1.0));
imageStore(s_irradiance, iuv, vec4(irradiance.xyz, 1.0));
}
15 changes: 8 additions & 7 deletions Engine/BuiltInShaders/shaders/cs_ComputeIndirectIrradiance.sc
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@
uniform vec4 u_numScatteringOrders;

IMAGE2D_WR(s_delta_irradiance, rgba32f, 0);
IMAGE2D_WR(s_irradiance, rgba32f, 1);
IMAGE2D_RW(s_irradiance, rgba32f, 1);

NUM_THREADS(8, 8, 1)
void main()
{
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
int scatteringOrder = u_numScatteringOrders.x;
vec2 uv = gl_GlobalInvocationID.xy;
ivec2 iuv = ivec2(uv);
int scatteringOrder = int(u_numScatteringOrders.x);

vec3 deltaIrradiance = ComputeIndirectIrradianceTexture(ATMOSPHERE, uv, scatteringOrder);
vec3 deltaIrradiance = ComputeIndirectIrradianceTexture(GetAtmosphere(), uv, scatteringOrder);

vec3 lastIrradiance = imageLoad(s_irradiance, uv);
vec3 lastIrradiance = imageLoad(s_irradiance, iuv).xyz;

imageStore(s_delta_irradiance, uv, vec4(deltaIrradiance, 1.0));
imageStore(s_irradiance, uv, vec4(lastIrradiance + deltaIrradiance, 1.0));
imageStore(s_delta_irradiance, iuv, vec4(deltaIrradiance, 1.0));
imageStore(s_irradiance, iuv, vec4(lastIrradiance + deltaIrradiance, 1.0));
}
11 changes: 6 additions & 5 deletions Engine/BuiltInShaders/shaders/cs_ComputeMultipleScattering.sc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ IMAGE3D_RW(s_scattering, rgba32f, 1);
NUM_THREADS(8, 8, 8)
void main()
{
ivec3 uvw = ivec3(gl_GlobalInvocationID.xyz);
vec3 uvw = gl_GlobalInvocationID.xyz;
ivec3 iuvw = ivec3(uvw);

float nu;
vec3 delta_multiple_scattering = ComputeMultipleScatteringTexture(ATMOSPHERE, uvw, nu);
vec3 delta_multiple_scattering = ComputeMultipleScatteringTexture(GetAtmosphere(), uvw, nu);
vec3 scattering = delta_multiple_scattering / RayleighPhaseFunction(nu);

vec4 lastScattering = imageLoad(s_scattering, uvw).xyzw;
vec4 lastScattering = imageLoad(s_scattering, iuvw).xyzw;

imageStore(s_delta_multiple_scattering, uvw, vec4(delta_multiple_scattering, 1.0));
imageStore(s_scattering, uvw, lastScattering + vec4(scattering, 0.0));
imageStore(s_delta_multiple_scattering, iuvw, vec4(delta_multiple_scattering, 1.0));
imageStore(s_scattering, iuvw, lastScattering + vec4(scattering, 0.0));
}
9 changes: 5 additions & 4 deletions Engine/BuiltInShaders/shaders/cs_ComputeScatteringDensity.sc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ IMAGE3D_WR(s_scattering_density, rgba32f, 0);
NUM_THREADS(8, 8, 8)
void main()
{
ivec3 uvw = ivec3(gl_GlobalInvocationID.xyz);
int scatteringOrder = u_numScatteringOrders.x;
vec3 uvw = gl_GlobalInvocationID.xyz;
ivec3 iuvw = ivec3(uvw);
int scatteringOrder = int(u_numScatteringOrders.x);

vec3 density = ComputeScatteringDensityTexture(ATMOSPHERE, uvw, scatteringOrder);
vec3 density = ComputeScatteringDensityTexture(GetAtmosphere(), uvw, scatteringOrder);

imageStore(s_scattering_density, uvw, vec4(density, 1.0));
imageStore(s_scattering_density, iuvw, vec4(density, 1.0));
}
11 changes: 6 additions & 5 deletions Engine/BuiltInShaders/shaders/cs_ComputeSingleScattering.sc
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ IMAGE3D_WR(s_scattering, rgba32f, 2);
NUM_THREADS(8, 8, 8)
void main()
{
ivec3 uvw = ivec3(gl_GlobalInvocationID.xyz);
vec3 uvw = gl_GlobalInvocationID.xyz;
ivec3 iuvw = ivec3(uvw);

vec3 delta_rayleigh = vec3_splat(0.0);
vec3 delta_mie = vec3_splat(0.0);

ComputeSingleScatteringTexture(ATMOSPHERE, uvw, delta_rayleigh, delta_mie);
ComputeSingleScatteringTexture(GetAtmosphere(), uvw, delta_rayleigh, delta_mie);

imageStore(s_delta_rayleigh_scattering, uvw, vec4(delta_rayleigh.xyz, 1.0));
imageStore(s_delta_mie_scattering, uvw, vec4(delta_mie.xyz, 1.0));
imageStore(s_scattering, uvw, vec4(delta_rayleigh.xyz, delta_mie.x));
imageStore(s_delta_rayleigh_scattering, iuvw, vec4(delta_rayleigh.xyz, 1.0));
imageStore(s_delta_mie_scattering, iuvw, vec4(delta_mie.xyz, 1.0));
imageStore(s_scattering, iuvw, vec4(delta_rayleigh.xyz, delta_mie.x));
}
7 changes: 4 additions & 3 deletions Engine/BuiltInShaders/shaders/cs_ComputeTransmittance.sc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ IMAGE2D_WR(s_transmittance, rgba32f, 0);
NUM_THREADS(8, 8, 1)
void main()
{
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec2 uv = gl_GlobalInvocationID.xy;
ivec2 iuv = ivec2(uv);

vec3 transmittance = ComputeTransmittanceToTopAtmosphereBoundaryTexture(ATMOSPHERE, uv);
vec3 transmittance = ComputeTransmittanceToTopAtmosphereBoundaryTexture(GetAtmosphere(), uv);

imageStore(s_transmittance, uv, vec4(transmittance.xyz, 1.0));
imageStore(s_transmittance, iuv, vec4(transmittance.xyz, 1.0));
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ void main()
{
// Tramsform unit from cm to km.
vec3 cameraPos = GetCamera().position / vec3_splat(100.0 * 100.0);
vec3 rayStart = cameraPos + vec3(0.0, ATMOSPHERE.bottom_radius + u_HeightOffset.x , 0.0);
vec3 rayStart = cameraPos + vec3(0.0, GetAtmosphere().bottom_radius + u_HeightOffset.x , 0.0);
vec3 rayDir = normalize(v_worldPos.xyz);
vec3 sunDir = -normalize(u_LightDir.xyz);

vec3 trans;
// TODO : Need a shadow volume algorithm to get shadow_length parameter to compute god ray.
vec3 scattering = GetSkyRadiance(ATMOSPHERE, rayStart, rayDir, 0.0, sunDir, trans);
vec3 scattering = GetSkyRadiance(GetAtmosphere(), rayStart, rayDir, 0.0, sunDir, trans);

gl_FragColor = vec4(scattering, 1.0);
}
16 changes: 9 additions & 7 deletions Engine/Source/Editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,14 +467,14 @@ void EditorApp::InitEngineRenderers()
pSceneRenderer->SetSceneWorld(m_pSceneWorld.get());
AddEngineRenderer(cd::MoveTemp(pSceneRenderer));

auto pBlendShapeRenderer = std::make_unique<engine::BlendShapeRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
pBlendShapeRenderer->SetSceneWorld(m_pSceneWorld.get());
AddEngineRenderer(cd::MoveTemp(pBlendShapeRenderer));
// auto pBlendShapeRenderer = std::make_unique<engine::BlendShapeRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
// pBlendShapeRenderer->SetSceneWorld(m_pSceneWorld.get());
// AddEngineRenderer(cd::MoveTemp(pBlendShapeRenderer));

auto pTerrainRenderer = std::make_unique<engine::TerrainRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
m_pTerrainRenderer = pTerrainRenderer.get();
pTerrainRenderer->SetSceneWorld(m_pSceneWorld.get());
AddEngineRenderer(cd::MoveTemp(pTerrainRenderer));
// auto pTerrainRenderer = std::make_unique<engine::TerrainRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
// m_pTerrainRenderer = pTerrainRenderer.get();
// pTerrainRenderer->SetSceneWorld(m_pSceneWorld.get());
// AddEngineRenderer(cd::MoveTemp(pTerrainRenderer));

auto pSkeletonRenderer = std::make_unique<engine::SkeletonRenderer>(m_pRenderContext->CreateView(), pSceneRenderTarget);
pSkeletonRenderer->SetSceneWorld(m_pSceneWorld.get());
Expand Down Expand Up @@ -546,6 +546,8 @@ void EditorApp::EngineRenderersWarmup()

bool EditorApp::IsAtmosphericScatteringEnable() const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this function if all fixed.

{
return true;

engine::GraphicsBackend backend = engine::Path::GetGraphicsBackend();

return engine::GraphicsBackend::Vulkan != backend
Expand Down
2 changes: 1 addition & 1 deletion Engine/Source/Editor/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main()
pEngine->Init({ .pTitle = "CatDogEditor", .pIconFilePath = "editor_icon.png",
.width = 1280, .height = 720, .useFullScreen = false,
.language = Language::ChineseSimplied,
.backend = GraphicsBackend::Direct3D11, .compileAllShaders = false });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert.

.backend = GraphicsBackend::OpenGL, .compileAllShaders = false });

pEngine->Run();

Expand Down