mirror of
https://github.com/w23/xash3d-fwgs
synced 2024-12-14 04:59:58 +01:00
vk: remove old dynamic beam segs code
This commit is contained in:
parent
4409e57a8d
commit
406a5f9d4b
@ -174,249 +174,6 @@ static void TriBrightness( float brightness ) {
|
||||
TriColor4f( brightness, brightness, brightness, 1.f );
|
||||
}
|
||||
|
||||
#if 0 // TODO possible optimization for tracking per-beam blases
|
||||
static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments, int flags, const vec4_t color, int texture, int render_mode )
|
||||
{
|
||||
int noiseIndex, noiseStep;
|
||||
int i, total_segs, segs_drawn;
|
||||
float div, length, fraction, factor;
|
||||
float flMaxWidth, vLast, vStep, brightness;
|
||||
vec3_t perp1, vLastNormal = {0};
|
||||
beamseg_t curSeg = {0};
|
||||
int total_vertices = 0;
|
||||
int total_indices = 0;
|
||||
r_geometry_buffer_lock_t buffer;
|
||||
vk_vertex_t *dst_vtx;
|
||||
uint16_t *dst_idx;
|
||||
|
||||
if( segments < 2 ) return;
|
||||
|
||||
length = VectorLength( delta );
|
||||
flMaxWidth = width * 0.5f;
|
||||
div = 1.0f / ( segments - 1 );
|
||||
|
||||
if( length * div < flMaxWidth * 1.414f )
|
||||
{
|
||||
// here, we have too many segments; we could get overlap... so lets have less segments
|
||||
segments = (int)( length / ( flMaxWidth * 1.414f )) + 1.0f;
|
||||
if( segments < 2 ) segments = 2;
|
||||
}
|
||||
|
||||
if( segments > NOISE_DIVISIONS )
|
||||
segments = NOISE_DIVISIONS;
|
||||
|
||||
div = 1.0f / (segments - 1);
|
||||
length *= 0.01f;
|
||||
vStep = length * div; // Texture length texels per space pixel
|
||||
|
||||
// Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture)
|
||||
vLast = fmod( freq * speed, 1 );
|
||||
|
||||
if( flags & FBEAM_SINENOISE )
|
||||
{
|
||||
if( segments < 16 )
|
||||
{
|
||||
segments = 16;
|
||||
div = 1.0f / ( segments - 1 );
|
||||
}
|
||||
scale *= 100.0f;
|
||||
length = segments * 0.1f;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale *= length * 2.0f;
|
||||
}
|
||||
|
||||
// Iterator to resample noise waveform (it needs to be generated in powers of 2)
|
||||
noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f );
|
||||
brightness = 1.0f;
|
||||
noiseIndex = 0;
|
||||
|
||||
if( FBitSet( flags, FBEAM_SHADEIN ))
|
||||
brightness = 0;
|
||||
|
||||
// Choose two vectors that are perpendicular to the beam
|
||||
R_BeamComputePerpendicular( delta, perp1 );
|
||||
|
||||
total_segs = segments;
|
||||
segs_drawn = 0;
|
||||
|
||||
total_vertices = (total_segs - 1) * 2 + 2;
|
||||
total_indices = (total_vertices - 2) * 3; // STRIP unrolled into LIST (TODO get rid of this)
|
||||
ASSERT(total_vertices < UINT16_MAX );
|
||||
|
||||
if (!R_GeometryBufferAllocOnceAndLock( &buffer, total_vertices, total_indices)) {
|
||||
gEngine.Con_Printf(S_ERROR "Cannot allocate geometry for beam\n");
|
||||
return;
|
||||
}
|
||||
|
||||
dst_vtx = buffer.vertices.ptr;
|
||||
dst_idx = buffer.indices.ptr;
|
||||
|
||||
// specify all the segments.
|
||||
for( i = 0; i < segments; i++ )
|
||||
{
|
||||
beamseg_t nextSeg;
|
||||
vec3_t vPoint1, vPoint2;
|
||||
|
||||
ASSERT( noiseIndex < ( NOISE_DIVISIONS << 16 ));
|
||||
|
||||
fraction = i * div;
|
||||
|
||||
VectorMA( source, fraction, delta, nextSeg.pos );
|
||||
|
||||
// distort using noise
|
||||
if( scale != 0 )
|
||||
{
|
||||
factor = rgNoise[noiseIndex>>16] * scale;
|
||||
|
||||
if( FBitSet( flags, FBEAM_SINENOISE ))
|
||||
{
|
||||
float s, c;
|
||||
|
||||
SinCos( fraction * M_PI_F * length + freq, &s, &c );
|
||||
VectorMA( nextSeg.pos, (factor * s), g_camera.vup, nextSeg.pos );
|
||||
|
||||
// rotate the noise along the perpendicluar axis a bit to keep the bolt from looking diagonal
|
||||
VectorMA( nextSeg.pos, (factor * c), g_camera.vright, nextSeg.pos );
|
||||
}
|
||||
else
|
||||
{
|
||||
VectorMA( nextSeg.pos, factor, perp1, nextSeg.pos );
|
||||
}
|
||||
}
|
||||
|
||||
// specify the next segment.
|
||||
nextSeg.width = width * 2.0f;
|
||||
nextSeg.texcoord = vLast;
|
||||
|
||||
if( segs_drawn > 0 )
|
||||
{
|
||||
// Get a vector that is perpendicular to us and perpendicular to the beam.
|
||||
// This is used to fatten the beam.
|
||||
vec3_t vNormal, vAveNormal;
|
||||
|
||||
R_BeamComputeNormal( curSeg.pos, nextSeg.pos, vNormal );
|
||||
|
||||
if( segs_drawn > 1 )
|
||||
{
|
||||
// Average this with the previous normal
|
||||
VectorAdd( vNormal, vLastNormal, vAveNormal );
|
||||
VectorScale( vAveNormal, 0.5f, vAveNormal );
|
||||
VectorNormalizeFast( vAveNormal );
|
||||
}
|
||||
else
|
||||
{
|
||||
VectorCopy( vNormal, vAveNormal );
|
||||
}
|
||||
|
||||
VectorCopy( vNormal, vLastNormal );
|
||||
|
||||
// draw regular segment
|
||||
VectorMA( curSeg.pos, ( curSeg.width * 0.5f ), vAveNormal, vPoint1 );
|
||||
VectorMA( curSeg.pos, (-curSeg.width * 0.5f ), vAveNormal, vPoint2 );
|
||||
|
||||
dst_vtx->lm_tc[0] = dst_vtx->lm_tc[1] = 0.f;
|
||||
dst_vtx->gl_tc[0] = 0.0f;
|
||||
dst_vtx->gl_tc[1] = curSeg.texcoord;
|
||||
applyBrightness( brightness, dst_vtx->color );
|
||||
VectorCopy( vPoint1, dst_vtx->pos );
|
||||
VectorCopy( vAveNormal, dst_vtx->normal );
|
||||
++dst_vtx;
|
||||
|
||||
dst_vtx->lm_tc[0] = dst_vtx->lm_tc[1] = 0.f;
|
||||
dst_vtx->gl_tc[0] = 1.0f;
|
||||
dst_vtx->gl_tc[1] = curSeg.texcoord;
|
||||
applyBrightness( brightness, dst_vtx->color );
|
||||
VectorCopy( vPoint2, dst_vtx->pos );
|
||||
VectorCopy( vAveNormal, dst_vtx->normal );
|
||||
++dst_vtx;
|
||||
}
|
||||
|
||||
curSeg = nextSeg;
|
||||
segs_drawn++;
|
||||
|
||||
if( FBitSet( flags, FBEAM_SHADEIN ) && FBitSet( flags, FBEAM_SHADEOUT ))
|
||||
{
|
||||
if( fraction < 0.5f ) brightness = fraction;
|
||||
else brightness = ( 1.0f - fraction );
|
||||
}
|
||||
else if( FBitSet( flags, FBEAM_SHADEIN ))
|
||||
{
|
||||
brightness = fraction;
|
||||
}
|
||||
else if( FBitSet( flags, FBEAM_SHADEOUT ))
|
||||
{
|
||||
brightness = 1.0f - fraction;
|
||||
}
|
||||
|
||||
if( segs_drawn == total_segs )
|
||||
{
|
||||
// draw the last segment
|
||||
VectorMA( curSeg.pos, ( curSeg.width * 0.5f ), vLastNormal, vPoint1 );
|
||||
VectorMA( curSeg.pos, (-curSeg.width * 0.5f ), vLastNormal, vPoint2 );
|
||||
|
||||
dst_vtx->lm_tc[0] = dst_vtx->lm_tc[1] = 0.f;
|
||||
dst_vtx->gl_tc[0] = 0.0f;
|
||||
dst_vtx->gl_tc[1] = curSeg.texcoord;
|
||||
applyBrightness( brightness, dst_vtx->color );
|
||||
VectorCopy( vPoint1, dst_vtx->pos );
|
||||
VectorCopy( vLastNormal, dst_vtx->normal );
|
||||
++dst_vtx;
|
||||
|
||||
dst_vtx->lm_tc[0] = dst_vtx->lm_tc[1] = 0.f;
|
||||
dst_vtx->gl_tc[0] = 1.0f;
|
||||
dst_vtx->gl_tc[1] = curSeg.texcoord;
|
||||
applyBrightness( brightness, dst_vtx->color );
|
||||
VectorCopy( vPoint2, dst_vtx->pos );
|
||||
VectorCopy( vLastNormal, dst_vtx->normal );
|
||||
++dst_vtx;
|
||||
}
|
||||
|
||||
vLast += vStep; // Advance texture scroll (v axis only)
|
||||
noiseIndex += noiseStep;
|
||||
}
|
||||
|
||||
for (int i = 2; i < total_vertices; ++i) {
|
||||
if( i & 1 )
|
||||
{
|
||||
// draw triangle [n-1 n-2 n]
|
||||
dst_idx[(i-2)*3+0] = i - 1;
|
||||
dst_idx[(i-2)*3+1] = i - 2;
|
||||
dst_idx[(i-2)*3+2] = i;
|
||||
}
|
||||
else
|
||||
{
|
||||
// draw triangle [n-2 n-1 n]
|
||||
dst_idx[(i-2)*3+0] = i - 2;
|
||||
dst_idx[(i-2)*3+1] = i - 1;
|
||||
dst_idx[(i-2)*3+2] = i;
|
||||
}
|
||||
}
|
||||
|
||||
R_GeometryBufferUnlock( &buffer );
|
||||
|
||||
{
|
||||
const vk_render_geometry_t geometry = {
|
||||
.texture = texture,
|
||||
.material = kXVkMaterialRegular,
|
||||
|
||||
.max_vertex = total_vertices,
|
||||
.vertex_offset = buffer.vertices.unit_offset,
|
||||
|
||||
.element_count = total_indices,
|
||||
.index_offset = buffer.indices.unit_offset,
|
||||
|
||||
.emissive = { color[0], color[1], color[2] },
|
||||
};
|
||||
|
||||
vk_render_type_e render_type = render_mode == kRenderNormal ? kVkRenderTypeSolid : kVkRenderType_A_1_R;
|
||||
VK_RenderModelDynamicBegin( render_type, color, m_matrix4x4_identity, "beam" /* TODO its name */ );
|
||||
VK_RenderModelDynamicAddGeometry( &geometry );
|
||||
VK_RenderModelDynamicCommit();
|
||||
}
|
||||
}
|
||||
#else
|
||||
static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments, int flags, const vec4_t color )
|
||||
{
|
||||
int noiseIndex, noiseStep;
|
||||
@ -595,7 +352,6 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f
|
||||
|
||||
TriEndEx(color, "beam segs");
|
||||
}
|
||||
#endif
|
||||
|
||||
static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments, const vec4_t color )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user