本文整理汇总了C#中UnityEngine.MaterialPropertyBlock.SetVector方法的典型用法代码示例。如果您正苦于以下问题:C# MaterialPropertyBlock.SetVector方法的具体用法?C# MaterialPropertyBlock.SetVector怎么用?C# MaterialPropertyBlock.SetVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.MaterialPropertyBlock
的用法示例。
在下文中一共展示了MaterialPropertyBlock.SetVector方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
void Update()
{
if (_needsReset) ResetResources();
// Call the kernels.
UpdateKernelShader();
Graphics.Blit(null, _positionBuffer, _kernelMaterial, 0);
Graphics.Blit(null, _rotationBuffer, _kernelMaterial, 1);
Graphics.Blit(null, _scaleBuffer, _kernelMaterial, 2);
// Make a material property block for the following drawcalls.
var props = new MaterialPropertyBlock();
props.AddTexture("_PositionTex", _positionBuffer);
props.AddTexture("_RotationTex", _rotationBuffer);
props.AddTexture("_ScaleTex", _scaleBuffer);
props.SetVector("_ColumnRow", new Vector2(_columns, _rows));
props.SetVector("_UVOffset", UVOffset);
// Temporary variables.
var mesh = _bulkMesh.mesh;
var position = transform.position;
var rotation = transform.rotation;
var material = _material ? _material : _defaultMaterial;
var uv = new Vector2(0.5f / _positionBuffer.width, 0);
position += transform.right * XOffset;
position += transform.up * YOffset;
// Draw mesh segments.
for (var i = 0; i < _positionBuffer.height; i++)
{
uv.y = (0.5f + i) / _positionBuffer.height;
props.AddVector("_BufferOffset", uv);
Graphics.DrawMesh(
mesh, position, rotation,
material, 0, null, 0, props,
_castShadows, _receiveShadows);
}
}
示例2: Update
void Update()
{
if (_subdivided != _subdivision) RebuildMesh();
var noiseDir = new Vector3(0.1f, 0.3f, -0.5f).normalized;
_noiseOffset += noiseDir * (Time.deltaTime * _noiseSpeed);
var radius = 1.0f + Reaktion.Perlin.Noise(Time.time, 23.5f) * _scaleAnimation;
var props = new MaterialPropertyBlock();
props.SetVector("_NoiseOffset", _noiseOffset);
props.SetFloat("_NoiseFrequency", _noiseFrequency);
props.SetFloat("_NoiseAmplitude", _noiseAmplitude);
props.SetFloat("_Opacity", _opacity);
props.SetFloat("_Radius", radius);
Graphics.DrawMesh(
_mesh, transform.localToWorldMatrix,
_material, 0, null, 0, props,
_shadowCastingMode, _receiveShadows);
}
示例3: Update
void Update()
{
if (_needsReset) ResetResources();
if (Application.isPlaying)
{
// Execute the kernel shaders.
SwapBuffers();
UpdateKernelShader();
_kernelMaterial.SetTexture("_PositionTex", _positionBuffer1);
_kernelMaterial.SetTexture("_VelocityTex", _velocityBuffer1);
Graphics.Blit(null, _velocityBuffer2, _kernelMaterial, 3);
_kernelMaterial.SetTexture("_VelocityTex", _velocityBuffer2);
Graphics.Blit(null, _positionBuffer2, _kernelMaterial, 2);
}
else
{
// Reset and execute the kernel shaders repeatedly.
Graphics.Blit(null, _positionBuffer2, _kernelMaterial, 0);
Graphics.Blit(null, _velocityBuffer2, _kernelMaterial, 1);
for (var i = 0; i < 32; i++) {
SwapBuffers();
UpdateKernelShader(i);
_kernelMaterial.SetTexture("_PositionTex", _positionBuffer1);
_kernelMaterial.SetTexture("_VelocityTex", _velocityBuffer1);
Graphics.Blit(null, _velocityBuffer2, _kernelMaterial, 3);
_kernelMaterial.SetTexture("_VelocityTex", _velocityBuffer2);
Graphics.Blit(null, _positionBuffer2, _kernelMaterial, 2);
}
}
// Draw lines.
UpdateLineShader();
var matrix = transform.localToWorldMatrix;
var stride = LinesPerDraw;
var total = TotalLineCount;
var props = new MaterialPropertyBlock();
var uv = new Vector2(0.5f / _historyLength, 0);
for (var i = 0; i < total; i += stride)
{
uv.y = (0.5f + i) / total;
props.SetVector("_BufferOffset", uv);
Graphics.DrawMesh(_mesh, matrix, _lineMaterial, 0, null, 0, props);
}
}
示例4: LateUpdate
void LateUpdate()
{
if (_needsReset) ResetResources();
// Call the kernels.
UpdateKernelShader();
Graphics.Blit(null, _positionBuffer, _kernelMaterial, 0);
Graphics.Blit(_positionBuffer, _normalBuffer1, _kernelMaterial, 1);
Graphics.Blit(_positionBuffer, _normalBuffer2, _kernelMaterial, 2);
// Update the line material.
_lineMaterial.SetColor("_Color", _lineColor);
// Make a material property block for the following drawcalls.
var props1 = new MaterialPropertyBlock();
var props2 = new MaterialPropertyBlock();
props1.SetTexture("_PositionBuffer", _positionBuffer);
props2.SetTexture("_PositionBuffer", _positionBuffer);
props1.SetTexture("_NormalBuffer", _normalBuffer1);
props2.SetTexture("_NormalBuffer", _normalBuffer2);
var mapOffs = new Vector3(0, 0, VOffset);
props1.SetVector("_MapOffset", mapOffs);
props2.SetVector("_MapOffset", mapOffs);
props1.SetFloat("_UseBuffer", 1);
props2.SetFloat("_UseBuffer", 1);
// Temporary variables.
var mesh = _bulkMesh.mesh;
var position = transform.position;
var rotation = transform.rotation;
var uv = new Vector2(0.5f / _positionBuffer.width, 0);
position += transform.forward * ZOffset;
// Draw mesh segments.
for (var i = 0; i < _totalStacks; i += _stacksPerSegment)
{
uv.y = (0.5f + i) / _positionBuffer.height;
props1.SetVector("_BufferOffset", uv);
props2.SetVector("_BufferOffset", uv);
if (_material)
{
// 1st half
Graphics.DrawMesh(
mesh, position, rotation,
_material, 0, null, 0, props1,
_castShadows, _receiveShadows);
// 2nd half
Graphics.DrawMesh(
mesh, position, rotation,
_material, 0, null, 1, props2,
_castShadows, _receiveShadows);
}
// lines
if (_lineColor.a > 0.0f)
Graphics.DrawMesh(
mesh, position, rotation,
_lineMaterial, 0, null, 2,
props1, false, false);
}
}
示例5: SetPropertyBlock
public void SetPropertyBlock(MaterialPropertyBlock block,
Transform modelTransform)
{
// model local space to world space matrix
var l2w = modelTransform.localToWorldMatrix;
// world space to effector local space matrix
var w2e = transform.worldToLocalMatrix;
// effector local space to normalized effector space matrix
var es = _effectorSize;
var invs = new Vector3(1.0f / es.x, 1.0f / es.y, 1.0f / es.z);
var e2n = Matrix4x4.Scale(invs);
block.SetMatrix("_Effector", e2n * w2e * l2w);
block.SetVector("_Steepness", new Vector3(
_transitionSteepness,
_emissionTransitionSteepness,
_scaleTransitionSteepness
));
block.SetColor("_InitialEmission", _initialEmission);
block.SetFloat("_InitialScale", _initialScale);
if (_effectType == EffectType.Destruction)
SetDestructionProps(block, modelTransform);
else
SetDisintegrationProps(block);
}
示例6: Update
void Update()
{
if (_needsReset)
{
ResetResources();
ResetState();
_needsReset = false;
}
if (Application.isPlaying)
{
float deltaTime;
int steps;
if (_fixTimeStep)
{
// fixed time step
deltaTime = 1.0f / _stepsPerSecond;
steps = Mathf.RoundToInt(Time.deltaTime * _stepsPerSecond);
}
else
{
// variable time step
deltaTime = Time.smoothDeltaTime;
steps = 1;
}
// time steps
for (var i = 0; i < steps; i++)
StepKernel(deltaTime);
}
else
{
ResetState();
// warming up
for (var i = 0; i < 32; i++)
StepKernel(0.1f);
}
// drawing lines
UpdateLineShader();
var matrix = transform.localToWorldMatrix;
var stride = LinesPerDraw;
var total = TotalLineCount;
var props = new MaterialPropertyBlock();
var uv = new Vector2(0.5f / _historyLength, 0);
for (var i = 0; i < total; i += stride)
{
uv.y = (0.5f + i) / total;
props.SetVector("_BufferOffset", uv);
// front face
props.SetFloat("_Flip", 1);
Graphics.DrawMesh(
_mesh, matrix, _lineMaterial, gameObject.layer,
null, 0, props, _castShadows, _receiveShadows
);
// back face
props.SetFloat("_Flip", -1);
Graphics.DrawMesh(
_mesh, matrix, _lineMaterial, gameObject.layer,
null, 0, props, _castShadows, _receiveShadows
);
}
}
示例7: SetDestructionProps
void SetDestructionProps(MaterialPropertyBlock block,
Transform modelTransform)
{
var mv = transform.TransformDirection(_motionVector);
mv = modelTransform.InverseTransformDirection(mv);
block.SetVector("_MotionVector", new Vector4(
mv.x, mv.y, mv.z, mv.magnitude
));
block.SetVector("_MotionParams", new Vector4(
_directionSpread,
_speedRandomness,
_turbulenceFrequency,
_turbulenceAmplitude
));
block.SetVector("_RotationParams", new Vector2(
_rotationAngle * Mathf.Deg2Rad,
_rotationRandomness
));
}
示例8: SetDisintegrationProps
void SetDisintegrationProps(MaterialPropertyBlock block)
{
block.SetVector("_PNoise", new Vector3(
_positionNoiseAmplitude,
_positionNoiseFrequency,
_positionNoiseSpeed
));
block.SetVector("_RNoise", new Vector3(
_rotationNoiseAmplitude,
_rotationNoiseFrequency,
_rotationNoiseSpeed
));
}
示例9: ApplyToBlock
private void ApplyToBlock(ref MaterialPropertyBlock block, ShaderIDs bids) {
#if USE_PROPERTY_BLOCKS
#if UNITY_5 && !UNITY_5_0 && !UNITY_5_1 && !UNITY_5_2
block.SetVector(bids.exposureIBL, exposures);
block.SetVector(bids.exposureLM, exposuresLM);
block.SetMatrix(bids.skyMatrix, skyMatrix);
block.SetMatrix(bids.invSkyMatrix, invMatrix);
block.SetVector(bids.skyMin, skyMin);
block.SetVector(bids.skyMax, skyMax);
if(specularCube) block.SetTexture(bids.specCubeIBL, specularCube);
else block.SetTexture(bids.specCubeIBL, blackCube);
block.SetVector(bids.SH[0], SH.cBuffer[0]);
block.SetVector(bids.SH[1], SH.cBuffer[1]);
block.SetVector(bids.SH[2], SH.cBuffer[2]);
block.SetVector(bids.SH[3], SH.cBuffer[3]);
block.SetVector(bids.SH[4], SH.cBuffer[4]);
block.SetVector(bids.SH[5], SH.cBuffer[5]);
block.SetVector(bids.SH[6], SH.cBuffer[6]);
block.SetVector(bids.SH[7], SH.cBuffer[7]);
block.SetVector(bids.SH[8], SH.cBuffer[8]);
#else
block.AddVector(bids.exposureIBL, exposures);
block.AddVector(bids.exposureLM, exposuresLM);
block.AddMatrix(bids.skyMatrix, skyMatrix);
block.AddMatrix(bids.invSkyMatrix, invMatrix);
block.AddVector(bids.skyMin, skyMin);
block.AddVector(bids.skyMax, skyMax);
if(specularCube) block.AddTexture(bids.specCubeIBL, specularCube);
else block.AddTexture(bids.specCubeIBL, blackCube);
block.AddVector(bids.SH[0], SH.cBuffer[0]);
block.AddVector(bids.SH[1], SH.cBuffer[1]);
block.AddVector(bids.SH[2], SH.cBuffer[2]);
block.AddVector(bids.SH[3], SH.cBuffer[3]);
block.AddVector(bids.SH[4], SH.cBuffer[4]);
block.AddVector(bids.SH[5], SH.cBuffer[5]);
block.AddVector(bids.SH[6], SH.cBuffer[6]);
block.AddVector(bids.SH[7], SH.cBuffer[7]);
block.AddVector(bids.SH[8], SH.cBuffer[8]);
#endif
#endif
}
示例10: Update
void Update()
{
if (_needsReset) ResetResources();
if (Application.isPlaying)
{
UpdateKernelShader();
SwapBuffersAndInvokeKernels();
}
else
{
InitializeAndPrewarmBuffers();
}
// Make a material property block for the following drawcalls.
var props = new MaterialPropertyBlock();
props.SetTexture("_PositionBuffer", _positionBuffer2);
props.SetTexture("_RotationBuffer", _rotationBuffer2);
props.SetFloat("_ScaleMin", _scale * (1 - _scaleRandomness));
props.SetFloat("_ScaleMax", _scale);
props.SetFloat("_RandomSeed", _randomSeed);
// Temporary variables
var mesh = _bulkMesh.mesh;
var position = transform.position;
var rotation = transform.rotation;
var material = _material ? _material : _defaultMaterial;
var uv = new Vector2(0.5f / _positionBuffer2.width, 0);
// Draw a bulk mesh repeatedly.
for (var i = 0; i < _positionBuffer2.height; i++)
{
uv.y = (0.5f + i) / _positionBuffer2.height;
props.SetVector("_BufferOffset", uv);
Graphics.DrawMesh(
mesh, position, rotation,
material, 0, null, 0, props,
_castShadows, _receiveShadows);
}
}
示例11: Update
void Update()
{
if (_needsReset) ResetResources();
if( Input.GetKeyDown( KeyCode.Space ) )
{
ResetResources();
}
// Variable time step.
float deltaTime = Time.smoothDeltaTime;
int steps = 1;
// Time steps.
for (var i = 0; i < steps; i++)
{
_time += deltaTime;
for(var w = 0; w < warps.Count; w++)
{
RhoWarp warp = warps[w];
if( warp == null || warp.enabled == false) continue;
warp.UpdateParameters();
warp.StepKernel( _time, deltaTime, buffer );
}
StepKernel(_time, deltaTime);
}
// Draw lines.
UpdateLineShader();
var matrix = transform.localToWorldMatrix;
var stride = info.LinesPerDraw;
var total = info.TotalLineCount;
var props = new MaterialPropertyBlock();
var uv = new Vector2(0.5f / info.historyLength, 0);
for (var i = 0; i < total; i += stride)
{
uv.y = (0.5f + i) / total;
props.SetVector("_BufferOffset", uv);
Graphics.DrawMesh(
_mesh, matrix, material, 0, null, 0, props,
false, false);
}
}
示例12: Update
void Update()
{
if (_needsReset) ResetResources();
if (Application.isPlaying)
{
float deltaTime;
int steps;
if (_fixTimeStep)
{
// Fixed time step.
deltaTime = 1.0f / _stepsPerSecond;
steps = Mathf.RoundToInt(Time.deltaTime * _stepsPerSecond);
}
else
{
// Variable time step.
deltaTime = Time.smoothDeltaTime;
steps = 1;
}
// Time steps.
for (var i = 0; i < steps; i++)
{
_time += deltaTime;
StepKernel(_time, deltaTime);
}
}
else
{
// Reset simulation state.
Graphics.Blit(null, _positionBuffer2, _kernelMaterial, 0);
Graphics.Blit(null, _velocityBuffer2, _kernelMaterial, 1);
_time = 0;
// Advance for a short period of time.
for (var i = 0; i < 32; i++)
{
_time += 0.1f;
StepKernel(_time, 0.1f);
}
}
// Draw lines.
UpdateLineShader();
var matrix = transform.localToWorldMatrix;
var stride = LinesPerDraw;
var total = TotalLineCount;
var props = new MaterialPropertyBlock();
var uv = new Vector2(0.5f / _historyLength, 0);
for (var i = 0; i < total; i += stride)
{
uv.y = (0.5f + i) / total;
props.SetVector("_BufferOffset", uv);
Graphics.DrawMesh(_mesh, matrix, _lineMaterial, 0, null, 0, props);
}
}
示例13: Update
void Update()
{
if (_needsReset) ResetResources();
// Advance the time variables.
_rotationNoiseTime += _rotationNoiseSpeed * Time.deltaTime;
// Call the kernels.
UpdateKernelShader();
if (_needsReset || _positionUpdateFlag)
Graphics.Blit(null, _positionBuffer, _kernelMaterial, 0);
Graphics.Blit(null, _rotationBuffer, _kernelMaterial, 1);
if (_needsReset || _scaleUpdateFlag)
Graphics.Blit(null, _scaleBuffer, _kernelMaterial, 2);
// Make a material property block for the following drawcalls.
var props = new MaterialPropertyBlock();
props.SetTexture("_PositionTex", _positionBuffer);
props.SetTexture("_RotationTex", _rotationBuffer);
props.SetTexture("_ScaleTex", _scaleBuffer);
// Temporary variables.
var mesh = _bulkMesh.mesh;
var position = transform.position;
var rotation = transform.rotation;
var material = _material ? _material : _defaultMaterial;
var uv = new Vector2(0.5f / _positionBuffer.width, 0);
// Draw mesh segments.
for (var i = 0; i < _positionBuffer.height; i++)
{
uv.y = (0.5f + i) / _positionBuffer.height;
props.SetVector("_BufferOffset", uv);
Graphics.DrawMesh(
mesh, position, rotation,
material, 0, null, 0, props,
_castShadows, _receiveShadows);
}
// Clear flag variables.
_positionUpdateFlag = true;
_scaleUpdateFlag = true;
_needsReset = false;
}