本文整理汇总了C#中UnityEngine.MaterialPropertyBlock.SetTexture方法的典型用法代码示例。如果您正苦于以下问题:C# MaterialPropertyBlock.SetTexture方法的具体用法?C# MaterialPropertyBlock.SetTexture怎么用?C# MaterialPropertyBlock.SetTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.MaterialPropertyBlock
的用法示例。
在下文中一共展示了MaterialPropertyBlock.SetTexture方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdatePropertyBlock
public void UpdatePropertyBlock()
{
MaterialPropertyBlock propBlock = new MaterialPropertyBlock();
render.GetPropertyBlock(propBlock);
propBlock.SetTexture("_MainTex", maskSprite.texture);
propBlock.SetTexture("_SprTex", springSprite);
propBlock.SetTexture("_SumTex", summerSprite);
propBlock.SetTexture("_AutTex", autumnSprite);
propBlock.SetTexture("_WinTex", winterSprite);
render.SetPropertyBlock(propBlock);
}
示例2: Start
void Start()
{
_rnd = GetComponent<Renderer>();
_rnd.GetPropertyBlock(_block = new MaterialPropertyBlock());
_inputs = input.GetPixels();
_width = input.width;
_height = input.height;
_pixelCount = _inputs.Length;
_texSize = new Vector2(_width, _height);
output = new Texture2D(_width, _height, TextureFormat.ARGB32, false);
_outputs = input.GetPixels();
output.SetPixels(_outputs);
output.Apply();
_block.SetTexture(PROP_MAIN_TEX, output);
_rnd.SetPropertyBlock(_block);
_mcmc = new MCMC(output, stdDev);
StartCoroutine (Pinning (0.01f, 200));
}
示例3: Start
void Start()
{
if (width <= 0)
width = Screen.width;
if (height <= 0)
height = Screen.height;
if (depth <= 0f)
depth = srcCamera.nearClipPlane;
_capture = new RenderTexture(width, height, 24, RenderTextureFormat.ARGB32);
_capture.antiAliasing = (QualitySettings.antiAliasing == 0 ? 1 : QualitySettings.antiAliasing);
_capture.filterMode = FilterMode.Bilinear;
_capture.wrapMode = TextureWrapMode.Clamp;
_props = new MaterialPropertyBlock();
_props.SetTexture(PROP_MAIN_TEXTURE, _capture);
GetComponent<Renderer>().SetPropertyBlock(_props);
srcCamera.targetTexture = _capture;
var viewport = srcCamera.rect;
var size = srcCamera.ViewportToWorldPoint(new Vector3(viewport.width, viewport.height, depth))
- srcCamera.ViewportToWorldPoint(new Vector3(0f, 0f, depth));
size.z = 1f;
transform.localScale = size;
}
示例4: UpdateCards
public void UpdateCards()
{
if (!Visible)
foreach (var c in cards)
c.transform.parent = transform;
if (UpdatesDisabled)
return;
//print("Updating cards on deck " + (TopCard == null ? "Empty" : TopCard.ToString()));
var localCardSpacerX = cardSpacerX;
var localCardSpacerY = cardSpacerY;
if ((maxCardsSpace > 0) && (cards.Count > maxCardsSpace))
{
//override the spacers values to squeeze cards
localCardSpacerX = (cardSpacerX * maxCardsSpace) / cards.Count;
localCardSpacerY = (cardSpacerY * maxCardsSpace) / cards.Count;
}
//Loop on the Deck Cards (not playing cards)
var lastTransform = transform;
for (int i = 0; i < cards.Count; i++)
{
//Get the card object
var card = cards[i];
//var spriteRenderer = card.GetComponent<SpriteRenderer>();
//if (spriteRenderer)
// spriteRenderer.sprite = card.desc.sprite;
var meshRenderer = card.GetComponent<MeshRenderer>();
if (meshRenderer)
{
MaterialPropertyBlock mpb = new MaterialPropertyBlock ();
//mpb.SetTexture ("_DetailAlbedoMap", card.desc.texture);
mpb.SetTexture ("_MainTex", card.desc.texture);
meshRenderer.SetPropertyBlock (mpb);
}
card.transform.parent = lastTransform;
//lastTransform = card.transform;
var localSortOrder = sortStep*(i+1) + ((selected == card)?cards.Count:0);
var targetLocalPosition = new Vector3(0, 0, (-localSortOrder) * 0.03f); // z needs to be set for mouse hit detection
targetLocalPosition += new Vector3(localCardSpacerX, localCardSpacerY) * ((float)i - (centered?1:0) * cards.Count/2.0f);
var targetLocalScale = Game.Instance.cardPrefab.transform.localScale;
if (selected == card)
{
targetLocalScale = targetLocalScale * 1.75f;
targetLocalPosition -= Vector3.forward * 0.5f;
}
targetLocalScale += targetLocalScale * (0.1f * (card.multiplier-1));
#if NGUI
TweenPosition.Begin(card.gameObject, 0.25f, targetLocalPosition);
TweenSize.Begin(card.gameObject, 0.25f, targetLocalScale);
#else
iTween.MoveTo(card.gameObject, iTween.Hash("position", targetLocalPosition, "islocal", true, "time", 0.25f));
iTween.ScaleTo(card.gameObject, iTween.Hash("scale", targetLocalScale, "islocal", true, "time", 0.25f));
#endif
card.GetComponent<Collider2D>().enabled = false; // disable the collider until the card is finished moving.
var sortOrder = order + localSortOrder; // Right decks are on top of left decks when squeezing together
card.GetComponent<Renderer>().sortingOrder = sortOrder; // sort order needs to be set for visual to render correctly
StartCoroutine(Delay(() => // schedule this for when the card finishes moving
{
card.GetComponent<Collider2D>().enabled = card.IsDragable;
}, 0.25f));
}
}
示例5: 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);
}
}
示例6: Update
void Update()
{
if (_needsReset) ResetResources();
UpdateKernelShader();
if (Application.isPlaying)
{
// Swap the particle buffers.
var temp = _positionBuffer1;
_positionBuffer1 = _positionBuffer2;
_positionBuffer2 = temp;
temp = _rotationBuffer1;
_rotationBuffer1 = _rotationBuffer2;
_rotationBuffer2 = temp;
// Call the kernel shader.
Graphics.Blit(_positionBuffer1, _positionBuffer2, _kernelMaterial, 2);
Graphics.Blit(_rotationBuffer1, _rotationBuffer2, _kernelMaterial, 3);
}
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", _minScale);
props.SetFloat("_ScaleMax", _maxScale);
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.AddVector("_BufferOffset", uv);
Graphics.DrawMesh(
mesh, position, rotation,
material, 0, null, 0, props,
_castShadows, _receiveShadows);
}
}
示例7: SetProperty
public LUT3D SetProperty(MaterialPropertyBlock block)
{
block.SetFloat (PROP_SCALE, (float)(_dim - 1) / _dim);
block.SetFloat (PROP_OFFSET, 1f / (2f * _dim));
block.SetTexture (PROP_3DLUT, _3dlut);
return this;
}
示例8: 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
}
示例9: CreateMesh
public void CreateMesh()
{
if (meshF == null) {
meshF = GetComponent<MeshFilter>() as MeshFilter;
}
if (rend == null) {
rend = GetComponent<Renderer>() as Renderer;
}
if (meshF.sharedMesh) {
DestroyImmediate(meshF.sharedMesh);
}
if (mesh) {
DestroyImmediate(mesh);
}
if (useSprite == null) {
return;
}
MaterialPropertyBlock pBlock = new MaterialPropertyBlock();
pBlock.SetTexture(0, useSprite.texture);
rend.SetPropertyBlock(pBlock);
float ppu = useSprite.pixelsPerUnit;
float cornerWidth = (float)(slicePixels) / ppu;
float cornerHeight = (float)(slicePixels) / ppu;
mesh = new Mesh();
Vector3[] vertices = new Vector3[16];
Vector3[] normals = new Vector3[16];
Vector2[] uvs = new Vector2[16];
float[] xPValues = new float[4];
float[] yPValues = new float[4];
float cornerWidthP = cornerWidth / width;
float cornerHeightP = cornerHeight / height;
xPValues[0] = 0.0f;
yPValues[0] = 0.0f;
xPValues[1] = cornerWidthP;
yPValues[1] = cornerHeightP;
xPValues[2] = 1.0f - cornerWidthP;
yPValues[2] = 1.0f - cornerHeightP;
xPValues[3] = 1.0f;
yPValues[3] = 1.0f;
for (int x = 0; x < 4; x++) {
for (int y = 0; y < 4; y++) {
float xP = xPValues[x];
float yP = yPValues[y];
int index = OneDee(x, y);
vertices[index] = new Vector3(
Mathf.Lerp(-1.0f, 1.0f, xP) * width * 0.5f,
Mathf.Lerp(-1.0f, 1.0f, yP) * height * 0.5f,
0.0f);
uvs[index] = new Vector2((float)x / 3.0f, (float)y / 3.0f);
normals[index] = -Vector3.forward;
}
}
int[] tris = new int[9 * 2 * 3];
int i = 0;
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
tris[i] = OneDee(x + 1, y);
i++;
tris[i] = OneDee(x, y);
i++;
tris[i] = OneDee(x + 1, y + 1);
i++;
tris[i] = OneDee(x, y);
i++;
tris[i] = OneDee(x, y + 1);
i++;
tris[i] = OneDee(x + 1, y + 1);
i++;
}
}
mesh.MarkDynamic();
mesh.vertices = vertices;
mesh.uv = uvs;
mesh.triangles = tris;
mesh.normals = normals;
mesh.RecalculateBounds();
meshF.sharedMesh = mesh;
}
示例10: UpdateMaterial
void UpdateMaterial()
{
if (! initialised) {
// Parameters changed before Awake() has been run, do a full update when appropriate.
// (Can't rely on Awake() when the GameObject is disabled. It does a lousy job as a constructor.)
regenerateMesh = true;
return;
}
if ((renderer.sharedMaterials.Length != 1) || (renderer.sharedMaterials[0] != m_material)) {
// Update only when necessary to prevent false scene changes.
renderer.sharedMaterials = new Material[] {m_material};
}
MaterialPropertyBlock materialProperties = new MaterialPropertyBlock();
renderer.GetPropertyBlock(materialProperties);
if ((m_sprite != null) && (m_sprite.texture != null)) {
materialProperties.SetTexture("_MainTex", m_sprite.texture);
}
else if (m_material != null) {
if (materialProperties.GetTexture("_MainTex") != null) {
materialProperties.Clear();
}
m_material.SetTexture("_MainTex", null);
}
renderer.SetPropertyBlock(materialProperties);
}
示例11: 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);
}
}
示例12: SetTexture
public override void SetTexture(Texture2D texture)
{
base.SetTexture(texture);
MaterialPropertyBlock props = new MaterialPropertyBlock();
#if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
props.AddTexture("_MainTex", texture);
#else
props.SetTexture("_MainTex", texture);
#endif
spriteRenderer.SetPropertyBlock(props);
}
示例13: 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.SetTexture("_PositionTex", _positionBuffer);
props.SetTexture("_RotationTex", _rotationBuffer);
props.SetTexture("_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.SetVector("_BufferOffset", uv);
Graphics.DrawMesh(
mesh, position, rotation,
material, 0, null, 0, props,
_castShadows, _receiveShadows);
}
}
示例14: 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;
}