#define SCENE_DATA_FLAGS_USE_AMBIENT_LIGHT (1 << 0)
#define SCENE_DATA_FLAGS_USE_AMBIENT_CUBEMAP (1 << 1)
#define SCENE_DATA_FLAGS_USE_REFLECTION_CUBEMAP (1 << 2)
#define SCENE_DATA_FLAGS_USE_ROUGHNESS_LIMITER (1 << 3)
#define SCENE_DATA_FLAGS_USE_FOG (1 << 4)
#define SCENE_DATA_FLAGS_USE_UV2_MATERIAL (1 << 5)
#define SCENE_DATA_FLAGS_USE_PANCAKE_SHADOWS (1 << 6)
#define SCENE_DATA_FLAGS_IN_SHADOW_PASS (1 << 7)
#define MAX_VIEWS 2

#define GODOT_VERSION_MAJOR 4
#define GODOT_VERSION_MINOR 5

#ifndef MSAA_ENABLED
	#define MSAA_ENABLED 0
#endif

#if (!MSAA_ENABLED)
	#define Sampler2DMSAA                              sampler2D
	#define Image2DMSAA                                image2D
	#define textureSizeMSAA(sampler_)                  textureSize(sampler_, 0)
	#define textureSamplesMSAA(sampler_)               (1)
	#define texelFetchMSAA(sampler_, P_, sample_)      texelFetch(sampler_, P_, 0)
	#define imageStoreMSAA(image_, P_, sample_, data_) imageStore(image_, P_, data_)
#else
	#define Sampler2DMSAA                              sampler2DMS
	#define Image2DMSAA                                image2DMS
	#define textureSizeMSAA(sampler_)                  textureSize(sampler_)
	#define textureSamplesMSAA(sampler_)               textureSamples(sampler_)
	#define texelFetchMSAA(sampler_, P_, sample_)      texelFetch(sampler_, P_, sample_)
	#define imageStoreMSAA(image_, P_, sample_, data_) imageStore(image_, P_, sample_, data_)
#endif // !MSAA_ENABLED


struct SceneData {
	#if (GODOT_VERSION_MAJOR == 4) && (GODOT_VERSION_MINOR == 4)

		// godot version 4.4
		highp mat4 projection_matrix;
		highp mat4 inv_projection_matrix;
		highp mat4 inv_view_matrix;
		highp mat4 view_matrix;

		// only used for multiview
		highp mat4 projection_matrix_view[MAX_VIEWS];
		highp mat4 inv_projection_matrix_view[MAX_VIEWS];
		highp vec4 eye_offset[MAX_VIEWS];

		// Used for billboards to cast correct shadows.
		highp mat4 main_cam_inv_view_matrix;

		highp vec2 viewport_size;
		highp vec2 screen_pixel_size;

		// Use vec4s because std140 doesn't play nice with vec2s, z and w are wasted.
		highp vec4 directional_penumbra_shadow_kernel[32];
		highp vec4 directional_soft_shadow_kernel[32];
		highp vec4 penumbra_shadow_kernel[32];
		highp vec4 soft_shadow_kernel[32];

		mediump mat3 radiance_inverse_xform;

		mediump vec4 ambient_light_color_energy;

		mediump float ambient_color_sky_mix;
		bool use_ambient_light;
		bool use_ambient_cubemap;
		bool use_reflection_cubemap;

		highp vec2 shadow_atlas_pixel_size;
		highp vec2 directional_shadow_pixel_size;

		uint directional_light_count;
		mediump float dual_paraboloid_side;
		highp float z_far;
		highp float z_near;

		bool roughness_limiter_enabled;
		mediump float roughness_limiter_amount;
		mediump float roughness_limiter_limit;
		mediump float opaque_prepass_threshold;

		bool fog_enabled;
		uint fog_mode;
		highp float fog_density;
		highp float fog_height;

		highp float fog_height_density;
		highp float fog_depth_curve;
		highp float fog_depth_begin;
		highp float taa_frame_count;

		mediump vec3 fog_light_color;
		highp float fog_depth_end;

		mediump float fog_sun_scatter;
		mediump float fog_aerial_perspective;
		highp float time;
		mediump float reflection_multiplier; // one normally, zero when rendering reflections

		vec2 taa_jitter;
		bool material_uv2_mode;
		float emissive_exposure_normalization;

		float IBL_exposure_normalization;
		bool pancake_shadows;
		uint camera_visible_layers;
		float pass_alpha_multiplier;

	#elif (GODOT_VERSION_MAJOR == 4) && (GODOT_VERSION_MINOR == 5)
		/* 4.5 definition */
		mat4 projection_matrix;
		mat4 inv_projection_matrix;
		mat4 inv_view_matrix;
		mat4 view_matrix;

		// only used for multiview
		mat4 projection_matrix_view[MAX_VIEWS];
		mat4 inv_projection_matrix_view[MAX_VIEWS];
		vec4 eye_offset[MAX_VIEWS];

		// Used for billboards to cast correct shadows.
		mat4 main_cam_inv_view_matrix;

		vec2 viewport_size;
		vec2 screen_pixel_size;

		// Use vec4s because std140 doesn't play nice with vec2s, z and w are wasted.
		vec4 directional_penumbra_shadow_kernel[32];
		vec4 directional_soft_shadow_kernel[32];
		vec4 penumbra_shadow_kernel[32];
		vec4 soft_shadow_kernel[32];

		vec2 shadow_atlas_pixel_size;
		vec2 directional_shadow_pixel_size;

		uint directional_light_count;
		float dual_paraboloid_side;
		float z_far;
		float z_near;

		float roughness_limiter_amount;
		float roughness_limiter_limit;
		float opaque_prepass_threshold;
		uint flags;

		mat3 radiance_inverse_xform;

		vec4 ambient_light_color_energy;

		float ambient_color_sky_mix;
		float fog_density;
		float fog_height;
		float fog_height_density;

		float fog_depth_curve;
		float fog_depth_begin;
		float fog_depth_end;
		float fog_sun_scatter;

		vec3 fog_light_color;
		float fog_aerial_perspective;

		float time;
		float taa_frame_count;
		vec2 taa_jitter;

		float emissive_exposure_normalization;
		float IBL_exposure_normalization;
		uint camera_visible_layers;
		float pass_alpha_multiplier;
	#else
		/* 4.6 definition */
		mat4 projection_matrix;
		mat4 inv_projection_matrix;
		mat3x4 inv_view_matrix;
		mat3x4 view_matrix;

		//#ifdef USE_DOUBLE_PRECISION  --- ADD LATER IF YOU WANT DOUBLE PRECISION
		//	vec4 inv_view_precision;
		//#endif

		// only used for multiview
		mat4 projection_matrix_view[MAX_VIEWS];
		mat4 inv_projection_matrix_view[MAX_VIEWS];
		vec4 eye_offset[MAX_VIEWS];

		// Used for billboards to cast correct shadows.
		mat4 main_cam_inv_view_matrix;

		vec2 viewport_size;
		vec2 screen_pixel_size;

		// Use vec4s because std140 doesn't play nice with vec2s, z and w are wasted.
		vec4 directional_penumbra_shadow_kernel[32];
		vec4 directional_soft_shadow_kernel[32];
		vec4 penumbra_shadow_kernel[32];
		vec4 soft_shadow_kernel[32];

		vec2 shadow_atlas_pixel_size;
		vec2 directional_shadow_pixel_size;

		float radiance_pixel_size;
		float radiance_border_size;
		vec2 reflection_atlas_border_size;

		uint directional_light_count;
		float dual_paraboloid_side;
		float z_far;
		float z_near;

		float roughness_limiter_amount;
		float roughness_limiter_limit;
		float opaque_prepass_threshold;
		uint flags;

		mat3 radiance_inverse_xform;

		vec4 ambient_light_color_energy;

		float ambient_color_sky_mix;
		float fog_density;
		float fog_height;
		float fog_height_density;

		float fog_depth_curve;
		float fog_depth_begin;
		float fog_depth_end;
		float fog_sun_scatter;

		vec3 fog_light_color;
		float fog_aerial_perspective;

		float time;
		float taa_frame_count;
		vec2 taa_jitter;

		float emissive_exposure_normalization;
		float IBL_exposure_normalization;
		uint camera_visible_layers;
		float pass_alpha_multiplier;
	#endif
};

struct GenericData{
	vec3 extralargenoiseposition;
	float extralargenoisescale;

	vec3 largenoiseposition;
	float cloud_lighting_sharpness;

	vec3 mediumnoiseposition;
	float lighting_step_distance;

	vec3 smallnoiseposition;
	float atmospheric_density;

	vec4 ambientLightColor;
	vec4 ambientGroundLightColor;
	vec4 ambientfogdistancecolor;
	
	float small_noise_scale;
	float min_step_distance;
	float max_step_distance;
	float lod_bias;

	float cloud_sharpness;
	float directionalLightsCount;
	float powderStrength;
	float anisotropy;

	float cloud_floor;
	float cloud_ceiling;
	float max_step_count;
	float max_lighting_step_count;

	float filterIndex;
	float blurPower;
	float blurQuality;
	float curlPower;

	vec2 WindDirection;
	float fogEffectGround;
	float samplePointsCount;

	float pointLightsCount;
	float pointEffectorCount;
	float windSweptRange;
	float windSweptPower;
    
    vec2 raster_size;
	float large_noise_scale;
	float medium_noise_scale;

	float time;
	float cloud_coverage;
	float cloud_density;
	float small_noise_strength;

	float cloud_lighting_power;
	float accumilation_decay;
	float isAccumulationA;
    float resolutionscale;
};

struct DirectionalLight {
	vec4 direction; //w = shadow sample count
	vec4 color; //a = intensity
};

struct PointLight {
	vec4 position; //w = radius
	vec4 color; //a = intensity
};

struct PointEffector {
	vec3 position; //w = radius
	float radius;

	float power;
	float attenuation;
	vec2 reserved;
};