mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 09:15:29 +01:00 
			
		
		
		
	Pass light sources in blue channel of vertex color instead of decoded light for all special drawtypes.
Plus some style fixes and optimizations.
This commit is contained in:
		@@ -220,7 +220,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
				top_is_same_liquid = true;
 | 
			
		||||
 | 
			
		||||
			u16 l = getInteriorLight(n, 0, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
 | 
			
		||||
 | 
			
		||||
			/*
 | 
			
		||||
				Generate sides
 | 
			
		||||
@@ -383,7 +383,6 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
			// it at what it emits, for an increased effect
 | 
			
		||||
			u8 light_source = nodedef->get(n).light_source;
 | 
			
		||||
			if(light_source != 0){
 | 
			
		||||
				//l = decode_light(undiminish_light(light_source));
 | 
			
		||||
				l = decode_light(light_source);
 | 
			
		||||
				l = l | (l<<8);
 | 
			
		||||
			}
 | 
			
		||||
@@ -393,7 +392,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
			// Otherwise use the light of this node (the liquid)
 | 
			
		||||
			else
 | 
			
		||||
				l = getInteriorLight(n, 0, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(f.alpha, l, f.light_source);
 | 
			
		||||
			
 | 
			
		||||
			u8 range = rangelim(nodedef->get(c_flowing).liquid_range, 1, 8);
 | 
			
		||||
 | 
			
		||||
@@ -697,7 +696,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
			TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
 | 
			
		||||
 | 
			
		||||
			u16 l = getInteriorLight(n, 1, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, f.light_source);
 | 
			
		||||
 | 
			
		||||
			for(u32 j=0; j<6; j++)
 | 
			
		||||
			{
 | 
			
		||||
@@ -780,7 +779,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
			param2  = param2 & 63;
 | 
			
		||||
			
 | 
			
		||||
			u16 l = getInteriorLight(n, 1, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, f.light_source);
 | 
			
		||||
			v3f pos = intToFloat(p, BS);
 | 
			
		||||
			static const float a = BS / 2;
 | 
			
		||||
			static const float g = a - 0.003;
 | 
			
		||||
@@ -985,7 +984,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
					v3s16(0,0,0), data);
 | 
			
		||||
 | 
			
		||||
			u16 l = getInteriorLight(n, 1, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, f.light_source);
 | 
			
		||||
 | 
			
		||||
			v3f pos = intToFloat(p, BS);
 | 
			
		||||
			aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
 | 
			
		||||
@@ -1018,7 +1017,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
			tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
 | 
			
		||||
 | 
			
		||||
			u16 l = getInteriorLight(n, 1, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, f.light_source);
 | 
			
		||||
 | 
			
		||||
			float s = BS/2*f.visual_scale;
 | 
			
		||||
			// Wall at X+ of node
 | 
			
		||||
@@ -1059,7 +1058,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
			tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
 | 
			
		||||
 | 
			
		||||
			u16 l = getInteriorLight(n, 0, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, f.light_source);
 | 
			
		||||
				
 | 
			
		||||
			float d = (float)BS/16;
 | 
			
		||||
			float s = BS/2*f.visual_scale;
 | 
			
		||||
@@ -1102,7 +1101,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
			tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
 | 
			
		||||
			
 | 
			
		||||
			u16 l = getInteriorLight(n, 1, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, f.light_source);
 | 
			
		||||
 | 
			
		||||
			float s = BS/2*f.visual_scale;
 | 
			
		||||
 | 
			
		||||
@@ -1149,7 +1148,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
			tile_rot.rotation = 1;
 | 
			
		||||
 | 
			
		||||
			u16 l = getInteriorLight(n, 1, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, f.light_source);
 | 
			
		||||
 | 
			
		||||
			const f32 post_rad=(f32)BS/8;
 | 
			
		||||
			const f32 bar_rad=(f32)BS/16;
 | 
			
		||||
@@ -1398,7 +1397,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
			tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
 | 
			
		||||
 | 
			
		||||
			u16 l = getInteriorLight(n, 0, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, f.light_source);
 | 
			
		||||
 | 
			
		||||
			float d = (float)BS/64;
 | 
			
		||||
			
 | 
			
		||||
@@ -1436,8 +1435,8 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
 | 
			
		||||
			};
 | 
			
		||||
			TileSpec tiles[6];
 | 
			
		||||
			
 | 
			
		||||
			u16 l = getInteriorLight(n, 0, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
 | 
			
		||||
			u16 l = getInteriorLight(n, 1, nodedef);
 | 
			
		||||
			video::SColor c = MapBlock_LightColor(255, l, f.light_source);
 | 
			
		||||
 | 
			
		||||
			v3f pos = intToFloat(p, BS);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -193,10 +193,7 @@ static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2,
 | 
			
		||||
	// Boost light level for light sources
 | 
			
		||||
	u8 light_source = MYMAX(ndef->get(n).light_source,
 | 
			
		||||
			ndef->get(n2).light_source);
 | 
			
		||||
	//if(light_source >= light)
 | 
			
		||||
		//return decode_light(undiminish_light(light_source));
 | 
			
		||||
	if(light_source > light)
 | 
			
		||||
		//return decode_light(light_source);
 | 
			
		||||
		light = light_source;
 | 
			
		||||
 | 
			
		||||
	return decode_light(light);
 | 
			
		||||
@@ -272,16 +269,12 @@ static u8 getSmoothLight(enum LightBank bank, v3s16 p, MeshMakeData *data)
 | 
			
		||||
 | 
			
		||||
	if(ambient_occlusion > 4)
 | 
			
		||||
	{
 | 
			
		||||
		//ambient_occlusion -= 4;
 | 
			
		||||
		//light = (float)light / ((float)ambient_occlusion * 0.5 + 1.0);
 | 
			
		||||
		float light_amount = (8 - ambient_occlusion) / 4.0;
 | 
			
		||||
		float light_f = (float)light / 255.0;
 | 
			
		||||
		light_f = pow(light_f, 2.2f); // gamma -> linear space
 | 
			
		||||
		light_f = light_f * light_amount;
 | 
			
		||||
		light_f = pow(light_f, 1.0f/2.2f); // linear -> gamma space
 | 
			
		||||
		if(light_f > 1.0)
 | 
			
		||||
			light_f = 1.0;
 | 
			
		||||
		light = 255.0 * light_f + 0.5;
 | 
			
		||||
		//calculate table index for gamma space multiplier
 | 
			
		||||
		ambient_occlusion -= 5;
 | 
			
		||||
		//table of precalculated gamma space multiply factors
 | 
			
		||||
		//light^2.2 * factor (0.75, 0.5, 0.25, 0.0), so table holds factor ^ (1 / 2.2)
 | 
			
		||||
		const float light_amount[4] = {0.877424315, 0.729740053, 0.532520545, 0.0};
 | 
			
		||||
		light = core::clamp(core::round32(light*light_amount[ambient_occlusion]), 0, 255);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return light;
 | 
			
		||||
@@ -914,21 +907,18 @@ static void updateFastFaceRow(
 | 
			
		||||
				// Floating point conversion of the position vector
 | 
			
		||||
				v3f pf(p_corrected.X, p_corrected.Y, p_corrected.Z);
 | 
			
		||||
				// Center point of face (kind of)
 | 
			
		||||
				v3f sp = pf - ((f32)continuous_tiles_count / 2. - 0.5) * translate_dir_f;
 | 
			
		||||
				v3f sp = pf - ((f32)continuous_tiles_count / 2.0 - 0.5) * translate_dir_f;
 | 
			
		||||
				if(continuous_tiles_count != 1)
 | 
			
		||||
					sp += translate_dir_f;
 | 
			
		||||
				v3f scale(1,1,1);
 | 
			
		||||
 | 
			
		||||
				if(translate_dir.X != 0)
 | 
			
		||||
				{
 | 
			
		||||
				if(translate_dir.X != 0) {
 | 
			
		||||
					scale.X = continuous_tiles_count;
 | 
			
		||||
				}
 | 
			
		||||
				if(translate_dir.Y != 0)
 | 
			
		||||
				{
 | 
			
		||||
				if(translate_dir.Y != 0) {
 | 
			
		||||
					scale.Y = continuous_tiles_count;
 | 
			
		||||
				}
 | 
			
		||||
				if(translate_dir.Z != 0)
 | 
			
		||||
				{
 | 
			
		||||
				if(translate_dir.Z != 0) {
 | 
			
		||||
					scale.Z = continuous_tiles_count;
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@@ -937,7 +927,7 @@ static void updateFastFaceRow(
 | 
			
		||||
						dest);
 | 
			
		||||
 | 
			
		||||
				g_profiler->avg("Meshgen: faces drawn by tiling", 0);
 | 
			
		||||
				for(int i=1; i<continuous_tiles_count; i++){
 | 
			
		||||
				for(int i = 1; i < continuous_tiles_count; i++){
 | 
			
		||||
					g_profiler->avg("Meshgen: faces drawn by tiling", 1);
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
@@ -965,8 +955,8 @@ static void updateAllFastFaceRows(MeshMakeData *data,
 | 
			
		||||
	/*
 | 
			
		||||
		Go through every y,z and get top(y+) faces in rows of x+
 | 
			
		||||
	*/
 | 
			
		||||
	for(s16 y=0; y<MAP_BLOCKSIZE; y++){
 | 
			
		||||
		for(s16 z=0; z<MAP_BLOCKSIZE; z++){
 | 
			
		||||
	for(s16 y = 0; y < MAP_BLOCKSIZE; y++) {
 | 
			
		||||
		for(s16 z = 0; z < MAP_BLOCKSIZE; z++) {
 | 
			
		||||
			updateFastFaceRow(data,
 | 
			
		||||
					v3s16(0,y,z),
 | 
			
		||||
					v3s16(1,0,0), //dir
 | 
			
		||||
@@ -980,8 +970,8 @@ static void updateAllFastFaceRows(MeshMakeData *data,
 | 
			
		||||
	/*
 | 
			
		||||
		Go through every x,y and get right(x+) faces in rows of z+
 | 
			
		||||
	*/
 | 
			
		||||
	for(s16 x=0; x<MAP_BLOCKSIZE; x++){
 | 
			
		||||
		for(s16 y=0; y<MAP_BLOCKSIZE; y++){
 | 
			
		||||
	for(s16 x = 0; x < MAP_BLOCKSIZE; x++) {
 | 
			
		||||
		for(s16 y = 0; y < MAP_BLOCKSIZE; y++) {
 | 
			
		||||
			updateFastFaceRow(data,
 | 
			
		||||
					v3s16(x,y,0),
 | 
			
		||||
					v3s16(0,0,1), //dir
 | 
			
		||||
@@ -995,8 +985,8 @@ static void updateAllFastFaceRows(MeshMakeData *data,
 | 
			
		||||
	/*
 | 
			
		||||
		Go through every y,z and get back(z+) faces in rows of x+
 | 
			
		||||
	*/
 | 
			
		||||
	for(s16 z=0; z<MAP_BLOCKSIZE; z++){
 | 
			
		||||
		for(s16 y=0; y<MAP_BLOCKSIZE; y++){
 | 
			
		||||
	for(s16 z = 0; z < MAP_BLOCKSIZE; z++) {
 | 
			
		||||
		for(s16 y = 0; y < MAP_BLOCKSIZE; y++) {
 | 
			
		||||
			updateFastFaceRow(data,
 | 
			
		||||
					v3s16(0,y,z),
 | 
			
		||||
					v3s16(1,0,0), //dir
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user