// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Planet::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); for (int i = 0; i < NUM_COLORS; i++) { // pblock->GetValue(i+PB_COL1, t, col[i], texValidity); pblock->GetValue(i+planet_color1, t, col[i], texValidity); col[i].ClampMinMax(); } // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(planet_size, t, size, texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); // pblock->GetValue(PB_ISLAND, t, island, texValidity); pblock->GetValue(planet_island, t, island, texValidity); ClampFloat(island, MIN_ISLAND, MAX_ISLAND); // pblock->GetValue(PB_PERCENT, t, percent, texValidity); pblock->GetValue(planet_percent, t, percent, texValidity); ClampFloat(percent, MIN_PERCENT, MAX_PERCENT); land = percent/100.0f; // pblock->GetValue(PB_SEED, t, seed, texValidity); pblock->GetValue(planet_seed, t, seed, texValidity); ClampInt(seed, (int) MIN_SEED, (int) MAX_SEED); pblock->GetValue(planet_blend, t, blend, texValidity); } ivalid &= texValidity; }
// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Stucco::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); // pblock->GetValue(PB_COL1, t, col[0], texValidity); pblock->GetValue(stucco_color1, t, col[0], texValidity); col[0].ClampMinMax(); // pblock->GetValue(PB_COL2, t, col[1], texValidity); pblock->GetValue(stucco_color2, t, col[1], texValidity); col[1].ClampMinMax(); // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(stucco_size, t, size, texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); // pblock->GetValue(PB_THRESH, t, thresh, texValidity); pblock->GetValue(stucco_threshold, t, thresh, texValidity); ClampFloat(thresh, MIN_THRESH, MAX_THRESH); // pblock->GetValue(PB_THICK, t, thick, texValidity); pblock->GetValue(stucco_thickness, t, thick, texValidity); pblock->GetValue(stucco_mapon1, t, mapOn[0], texValidity); pblock->GetValue(stucco_mapon2, t, mapOn[1], texValidity); ClampFloat(thick, MIN_THICK, MAX_THICK); for (int i = 0; i < NUM_SUB_TEXMAPS; i++) { if (subTex[i]) subTex[i]->Update(t, texValidity); } } ivalid &= texValidity; }
// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Splat::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); // pblock->GetValue(PB_COL1, t, col[0], texValidity); pblock->GetValue(splat_color1, t, col[0], texValidity); col[0].ClampMinMax(); // pblock->GetValue(PB_COL2, t, col[1], texValidity); pblock->GetValue(splat_color2, t, col[1], texValidity); col[1].ClampMinMax(); // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(splat_size, t, size, texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); // pblock->GetValue(PB_THRESH, t, thresh, texValidity); pblock->GetValue(splat_threshold, t, thresh, texValidity); ClampFloat(thresh, MIN_THRESH, MAX_THRESH); // pblock->GetValue(PB_ITER, t, iter, texValidity); pblock->GetValue(splat_iteration, t, iter, texValidity); pblock->GetValue(splat_mapon1, t, mapOn[0], texValidity); pblock->GetValue(splat_mapon2, t, mapOn[1], texValidity); ClampInt(iter, (int) MIN_ITER, (int) MAX_ITER); for (int i = 0; i < NUM_SUB_TEXMAPS; i++) { if (subTex[i]) subTex[i]->Update(t, texValidity); } } ivalid &= texValidity; }
// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Speckle::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); // pblock->GetValue(PB_COL1, t, col[0], texValidity); pblock->GetValue(speckle_color1, t, col[0], texValidity); col[0].ClampMinMax(); // pblock->GetValue(PB_COL2, t, col[1], texValidity); pblock->GetValue(speckle_color2, t, col[1], texValidity); col[1].ClampMinMax(); // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(speckle_size, t, size, texValidity); pblock->GetValue(speckle_mapon1, t, mapOn[0], texValidity); pblock->GetValue(speckle_mapon2, t, mapOn[1], texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); NotifyDependents(FOREVER, PART_TEXMAP, REFMSG_DISPLAY_MATERIAL_CHANGE); } if (!mapValid.InInterval(t)) { mapValid.SetInfinite(); for (int i = 0; i < NUM_SUB_TEXMAPS; i++) { if (subTex[i]) subTex[i]->Update(t, mapValid); } } ivalid &= texValidity; ivalid &= mapValid; }
// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Water::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); // pblock->GetValue(PB_COL1, t, col[0], texValidity); pblock->GetValue(water_color1, t, col[0], texValidity); col[0].ClampMinMax(); // pblock->GetValue(PB_COL2, t, col[1], texValidity); pblock->GetValue(water_color2, t, col[1], texValidity); col[1].ClampMinMax(); // pblock->GetValue(PB_NUM, t, count, texValidity); pblock->GetValue(water_num, t, count, texValidity); ClampInt(count, (int) MIN_NUM, (int) MAX_NUM); // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(water_size, t, size, texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); // pblock->GetValue(PB_LEN_MIN, t, minperiod, texValidity); pblock->GetValue(water_len_min, t, minperiod, texValidity); ClampFloat(minperiod, MIN_LEN_MIN, MAX_LEN_MIN); // > 6/11/02 - 2:42pm --MQM-- typo, was MIN_LEN_MIN, MAX_LEN_MAX // pblock->GetValue(PB_LEN_MAX, t, maxperiod, texValidity); pblock->GetValue(water_len_max, t, maxperiod, texValidity); ClampFloat(maxperiod, MIN_LEN_MAX, MAX_LEN_MAX); // pblock->GetValue(PB_AMP, t, amp, texValidity); pblock->GetValue(water_amp, t, amp, texValidity); ClampFloat(amp, MIN_AMP, MAX_AMP); // pblock->GetValue(PB_PHASE, t, phase, texValidity); // pblock->GetValue(PB_TYPE, t, type, texValidity); pblock->GetValue(water_phase, t, phase, texValidity); pblock->GetValue(water_type, t, type, texValidity); for (int i = 0; i < NUM_SUB_TEXMAPS; i++) { if (subTex[i]) subTex[i]->Update(t, texValidity); // pblock->GetValue(PB_SEED, t, randSeed, texValidity); pblock->GetValue(water_seed, t, randSeed, texValidity); pblock->GetValue(water_mapon1, t, mapOn[0], texValidity); pblock->GetValue(water_mapon2, t, mapOn[1], texValidity); ReInit(); } } ivalid &= texValidity; }
// blending using source luminance hkvVec4 VISION_FASTCALL BlittingHelpers::CombineSrcLuminance(const hkvVec4& srcColor, const hkvVec4& dstColor, const hkvVec4& auxColor) { float a0 = ClampFloat((srcColor.r+srcColor.g+srcColor.b) * (1.f/3.f) * auxColor.a,0,1); float a1 = 1.f-a0; return hkvVec4( dstColor.x*a1+srcColor.x*auxColor.x*a0, dstColor.y*a1+srcColor.y*auxColor.y*a0, dstColor.z*a1+srcColor.z*auxColor.z*a0, dstColor.w*a1+srcColor.w*auxColor.w*a0); }
// alpha blending hkvVec4 VISION_FASTCALL BlittingHelpers::CombineSrcAlpha(const hkvVec4& srcColor, const hkvVec4& dstColor, const hkvVec4& auxColor) { float a0 = ClampFloat(srcColor.a * auxColor.a,0,1); float a1 = 1.f-a0; return hkvVec4( dstColor.x*a1+srcColor.x*auxColor.x*a0, dstColor.y*a1+srcColor.y*auxColor.y*a0, dstColor.z*a1+srcColor.z*auxColor.z*a0, dstColor.w*a1+srcColor.w*auxColor.w*a0); }
bool CBspPortal::Build( char *def, unsigned int pointCnt, bool bInverse ){ char *c = def; unsigned int n; point_count = pointCnt; if ( point_count < 3 ) { return false; } point = new CBspPoint[point_count]; for ( n = 0; n < point_count; n++ ) { for (; *c != 0 && *c != '('; c++ ) ; if ( *c == 0 ) { return false; } c++; int x; if ( bInverse ) { x = point_count - n - 1; } else{ x = n; } sscanf( c, "%f %f %f", &point[x].p[0], &point[x].p[1], &point[x].p[2] ); ClampFloat( &point[x].p[0] ); ClampFloat( &point[x].p[1] ); ClampFloat( &point[x].p[2] ); } return true; }
// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Smoke::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); // pblock->GetValue(PB_COL1, t, col[0], texValidity); pblock->GetValue(smoke_color1, t, col[0], texValidity); col[0].ClampMinMax(); // pblock->GetValue(PB_COL2, t, col[1], texValidity); pblock->GetValue(smoke_color2, t, col[1], texValidity); col[1].ClampMinMax(); // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(smoke_size, t, size, texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); // pblock->GetValue(PB_EXP, t, power, texValidity); pblock->GetValue(smoke_exponent, t, power, texValidity); ClampFloat(power, MIN_EXP, MAX_EXP); // pblock->GetValue(PB_PHASE, t, phase, texValidity); // pblock->GetValue(PB_ITER, t, iter, texValidity); pblock->GetValue(smoke_phase, t, phase, texValidity); pblock->GetValue(smoke_iteration, t, iter, texValidity); ClampInt(iter, (int) MIN_ITER, (int) MAX_ITER); pblock->GetValue(smoke_mapon1, t, mapOn[0], texValidity); pblock->GetValue(smoke_mapon2, t, mapOn[1], texValidity); NotifyDependents(FOREVER, PART_TEXMAP, REFMSG_DISPLAY_MATERIAL_CHANGE); } if (!mapValid.InInterval(t)) { mapValid.SetInfinite(); for (int i = 0; i < NUM_SUB_TEXMAPS; i++) { if (subTex[i]) subTex[i]->Update(t, mapValid); } } ivalid &= texValidity; ivalid &= mapValid; }
int SoundSetChannelDistanceFloat(int channel, float distance) { if(Mix_Playing(channel)) { distance = ClampFloat(distance, 0.0, 1.0); int dist; dist = (int)(255 * distance); //printf("Set distance to %d\n", dist); if(Mix_SetDistance(channel, dist)) return 1; else return 0; //TODO: error checking? } else return 0; }
// This method is called before rendering begins to allow the plug-in // to evaluate anything prior to the render so it can store this information. void Speckle::Update(TimeValue t, Interval& ivalid) { if (!texValidity.InInterval(t)) { texValidity.SetInfinite(); xyzGen->Update(t, texValidity); // pblock->GetValue(PB_COL1, t, col[0], texValidity); pblock->GetValue(speckle_color1, t, col[0], texValidity); col[0].ClampMinMax(); // pblock->GetValue(PB_COL2, t, col[1], texValidity); pblock->GetValue(speckle_color2, t, col[1], texValidity); col[1].ClampMinMax(); // pblock->GetValue(PB_SIZE, t, size, texValidity); pblock->GetValue(speckle_size, t, size, texValidity); pblock->GetValue(speckle_mapon1, t, mapOn[0], texValidity); pblock->GetValue(speckle_mapon2, t, mapOn[1], texValidity); ClampFloat(size, MIN_SIZE, MAX_SIZE); for (int i = 0; i < NUM_SUB_TEXMAPS; i++) { if (subTex[i]) subTex[i]->Update(t, texValidity); } } ivalid &= texValidity; }
/****************************************************************************** special effects ******************************************************************************/ int SoundPanChannelFloat(int channel, float panning) { if(Mix_Playing(channel)) { int left, right, offset; panning = ClampFloat(panning, -1.0, 1.0); offset = (int)(panning * 127); if (panning > 0) { right = 127 + offset; left = 127 - offset; } else if (panning < 0) { offset = -offset; left = 127 + offset; right = 127 - offset; } else { left = 127; right = 127; } //printf("Left: %d, Right: %d\n", left, right); if(Mix_SetPanning(channel, left, right)) return 1; else return 0; //TODO: error checking? } else return 0; }
//----------------------------------------------------------------------------- // Write a float RGBA image to a (BGRA) BMP //----------------------------------------------------------------------------- bool SaveImageAsBMP (cl_mem in_buffer, int width, int height, const char* fileName) { bool success = false; FILE* stream = NULL; printf("Save Image: %s \n", fileName); stream = fopen( fileName, "wb" ); if( NULL == stream ) { goto ErrExit; } cl_uint imageSize = 0; clGetMemObjectInfo(in_buffer, CL_MEM_SIZE, sizeof(imageSize), &imageSize, 0); cl_float* ptr = (cl_float*)clEnqueueMapBuffer(CLU_DEFAULT_Q, in_buffer, CL_TRUE, CL_MAP_READ, 0, imageSize, 0, NULL, NULL, NULL); if (0 == ptr) { goto ErrExit; } BITMAPFILEHEADER fileHeader; BITMAPINFOHEADER infoHeader; int alignSize = width * 4; alignSize ^= 0x03; alignSize ++; alignSize &= 0x03; int rowLength = width * 4 + alignSize; fileHeader.bfReserved1 = 0x0000; fileHeader.bfReserved2 = 0x0000; infoHeader.biSize = sizeof(BITMAPINFOHEADER); infoHeader.biWidth = width; infoHeader.biHeight = height; infoHeader.biPlanes = 1; infoHeader.biBitCount = 32; infoHeader.biCompression = BI_RGB; infoHeader.biSizeImage = rowLength * height; infoHeader.biXPelsPerMeter = 0; infoHeader.biYPelsPerMeter = 0; infoHeader.biClrUsed = 0; // max available infoHeader.biClrImportant = 0; fileHeader.bfType = 0x4D42; fileHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + rowLength * height; fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER); if(sizeof(BITMAPFILEHEADER) != fwrite( &fileHeader, 1, sizeof(BITMAPFILEHEADER), stream)) { // can't write BITMAPFILEHEADER goto ErrExit; } if(sizeof(BITMAPINFOHEADER) != fwrite( &infoHeader, 1, sizeof(BITMAPINFOHEADER), stream)) { // can't write BITMAPINFOHEADER goto ErrExit; } unsigned char buffer[4] = {0}; for (int y=0; y<height; y++) { for (int x=0; x<width; x++) { int index = (height-1-y)*width+x; float* p = &ptr[index*4]; // Ensure that no value is greater than 255.0 unsigned char bytes[4] = // RGBA float -> BGRA byte { ClampFloat(p[2]), ClampFloat(p[1]), ClampFloat(p[0]), ClampFloat(p[3]) }; if( 4 != fwrite(bytes, 1, 4, stream)) { goto ErrExit; } } fwrite( buffer, 1, alignSize, stream ); } success = true; ErrExit: fclose(stream); clEnqueueUnmapMemObject(CLU_DEFAULT_Q, in_buffer, ptr, 0, 0, 0); return success; }