New, smoother texture for flashers/sparks for better blending and anti-aliasing.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@2597 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2009-09-25 15:38:52 +00:00
parent c2acf1729a
commit a88b0d8107
4 changed files with 299 additions and 5 deletions

View File

@ -46,7 +46,9 @@ MA 02110-1301, USA.
- (void) setColor:(OOColor *)color alpha:(GLfloat)alpha;
/* For subclasses that don't want the default blur texture.
NOTE: such subclasses must deal with the OOGraphicsResetManager.
NOTE: such subclasses must deal with the OOGraphicsResetManager. Also,
OOLightParticleEntity assumes the texture is twice as big as the nominal
size of the particle (with a black border for anti-aliasing purposes).
*/
- (OOTexture *) texture;

View File

@ -142,7 +142,6 @@ static OOTexture *sBlobTexture = nil;
OOGL(glEnable(GL_TEXTURE_2D));
GLfloat distanceAttenuation = zero_distance / no_draw_distance;
distanceAttenuation *= distanceAttenuation;
distanceAttenuation = 1.0 - distanceAttenuation;
GLfloat components[4] = { _colorComponents[0], _colorComponents[1], _colorComponents[2], _colorComponents[3] * distanceAttenuation };
OOGL(glColor4fv(components));
@ -154,8 +153,13 @@ static OOTexture *sBlobTexture = nil;
OOViewID viewDir = [UNIVERSE viewDirection];
if (viewDir != VIEW_GUI_DISPLAY) GLMultOOMatrix([[PlayerEntity sharedPlayer] drawRotationMatrix]);
GLfloat xx = 0.5 * _size.width;
GLfloat yy = 0.5 * _size.height;
/* NOTE: these previously halved the size because they're half-size
offsets, but since we use a texture with a border for anti-aliasing
purposes, that scaling is no longer desired.
-- Ahruman 2009-09-25
*/
GLfloat xx = _size.width;
GLfloat yy = _size.height;
OOGLBEGIN(GL_QUADS);
switch (viewDir)
@ -266,7 +270,11 @@ static OOTexture *sBlobTexture = nil;
{
if (sBlobTexture == nil)
{
sBlobTexture = [[OOTexture textureWithName:@"blur256.png" inFolder:@"Textures"] retain];
sBlobTexture = [[OOTexture textureWithName:@"oolite-particle-blur.png"
inFolder:@"Textures"
options:kOOTextureMinFilterMipMap | kOOTextureMagFilterLinear | kOOTextureAlphaMask
anisotropy:kOOTextureDefaultAnisotropy / 2.0
lodBias:0.0] retain];
[[OOGraphicsResetManager sharedManager] registerClient:(id<OOGraphicsResetClient>)[OOLightParticleEntity class]];
}
}

View File

@ -0,0 +1,76 @@
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <stdint.h>
#include <time.h>
#define SIZE 512 // Side dimension
#define RADIUS 150
#define NOISE_FACTOR 0.01
static inline off_t Coord(int x, int y)
{
assert(x < SIZE && y < SIZE);
return y * SIZE + x;
}
static inline float Distance(float x1, float y1, float x2, float y2)
{
float dx = x2 - x1;
float dy = y2 - y1;
return sqrtf(dx * dx + dy * dy);
}
static inline float OOClamp_0_1_f(float value)
{
return fmaxf(0.0f, fminf(value, 1.0f));
}
// Random in -1..1
static inline float Random(void)
{
float rval = (float)rand() / (float)RAND_MAX;
return rval * 2.0f - 1.0f;
}
int main (int argc, const char * argv[])
{
uint8_t *buffer;
srand(time(NULL));
buffer = malloc(SIZE * SIZE);
if (buffer == NULL) return EXIT_FAILURE;
int x, y;
for (y = 0; y < SIZE; ++y)
{
for (x = 0; x < SIZE; ++x)
{
float r = 1.0 - Distance(x, y, SIZE / 2.0f - 0.5f, SIZE / 2.0f - 0.5f) / (float)RADIUS;
r = OOClamp_0_1_f(r * 1.0f - NOISE_FACTOR / 2.0f);
// x^2 (3-2x), same as GLSL smoothstep() interpolation.
float v = r * r * (3.0f - 2.0f * r);
// mix in some noise, scaled by intensity.
float noise = Random() * NOISE_FACTOR;
v *= 1.0 + noise;
buffer[Coord(x, y)] = 255 * OOClamp_0_1_f(v);
}
}
FILE *result = fopen("oolite-particle-blur.raw", "wb");
if (result == NULL) return EXIT_FAILURE;
fwrite(buffer, SIZE, SIZE, result);
fclose(result);
return 0;
}

View File

@ -0,0 +1,208 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objects = {
/* Begin PBXBuildFile section */
8DD76F9A0486AA7600D96B5E /* blurmapgen.c in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* blurmapgen.c */; settings = {ATTRIBUTES = (); }; };
8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
8DD76F9E0486AA7600D96B5E /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 8;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
08FB7796FE84155DC02AAC07 /* blurmapgen.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = blurmapgen.c; sourceTree = "<group>"; };
08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
32A70AAB03705E1F00C91783 /* blurmapgen_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = blurmapgen_Prefix.pch; sourceTree = "<group>"; };
8DD76FA10486AA7600D96B5E /* blurmapgen */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = blurmapgen; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
8DD76F9B0486AA7600D96B5E /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
08FB7794FE84155DC02AAC07 /* blurmapgen */ = {
isa = PBXGroup;
children = (
08FB7795FE84155DC02AAC07 /* Source */,
08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */,
1AB674ADFE9D54B511CA2CBB /* Products */,
);
name = blurmapgen;
sourceTree = "<group>";
};
08FB7795FE84155DC02AAC07 /* Source */ = {
isa = PBXGroup;
children = (
32A70AAB03705E1F00C91783 /* blurmapgen_Prefix.pch */,
08FB7796FE84155DC02AAC07 /* blurmapgen.c */,
);
name = Source;
sourceTree = "<group>";
};
08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = {
isa = PBXGroup;
children = (
08FB779EFE84155DC02AAC07 /* Foundation.framework */,
);
name = "External Frameworks and Libraries";
sourceTree = "<group>";
};
1AB674ADFE9D54B511CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
8DD76FA10486AA7600D96B5E /* blurmapgen */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
8DD76F960486AA7600D96B5E /* blurmapgen */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "blurmapgen" */;
buildPhases = (
8DD76F990486AA7600D96B5E /* Sources */,
8DD76F9B0486AA7600D96B5E /* Frameworks */,
8DD76F9E0486AA7600D96B5E /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = blurmapgen;
productInstallPath = "$(HOME)/bin";
productName = blurmapgen;
productReference = 8DD76FA10486AA7600D96B5E /* blurmapgen */;
productType = "com.apple.product-type.tool";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "blurmapgen" */;
compatibilityVersion = "Xcode 3.1";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* blurmapgen */;
projectDirPath = "";
projectRoot = "";
targets = (
8DD76F960486AA7600D96B5E /* blurmapgen */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
8DD76F990486AA7600D96B5E /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8DD76F9A0486AA7600D96B5E /* blurmapgen.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
1DEB927508733DD40010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
INSTALL_PATH = /usr/local/bin;
PRODUCT_NAME = blurmapgen;
SDKROOT = "";
};
name = Debug;
};
1DEB927608733DD40010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = blurmapgen_Prefix.pch;
INSTALL_PATH = /usr/local/bin;
PRODUCT_NAME = blurmapgen;
};
name = Release;
};
1DEB927908733DD40010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
};
name = Debug;
};
1DEB927A08733DD40010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "blurmapgen" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1DEB927508733DD40010E9CD /* Debug */,
1DEB927608733DD40010E9CD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "blurmapgen" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1DEB927908733DD40010E9CD /* Debug */,
1DEB927A08733DD40010E9CD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
}