Unity5:如何绘制纹理添加剂来渲染纹理?
Unity5: How to draw texture additive to rendertexture?
所以我有一个 RenderTexture,我想在其上绘制 "brush" 纹理。这是一个高度贴图,所以画笔中的 watherver 应该添加到 RenderTexture 的值中。
将纹理绘制到 rendertexture 并不难:
RenderTexture.active = _heightMap; //the render texture to be drawn to
Rect screenRect = new Rect(x, y, width, height);
Graphics.DrawTexture(screenRect, _brush, _addBrushMaterial);
我想我现在需要一个 material 来为我的纹理添加画笔的颜色(“_addBrushMaterial”)。但是我找不到如何制作它所以它增加了它的颜色。目前它的片段着色器只是设置颜色,所以这不好,应该添加它:
float4 frag (v2f_img i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
return col * _Scale;
}
关于这方面的文档似乎非常有限,因此非常感谢您的帮助!
谢谢
好的,所以我找到了一些有用的东西。我所要做的就是添加 "Blend One One".
我现在使用以下着色器:
Properties
{
_MainTex ("Brush", 2D) = "white" {}
_Scale("Scaling factor", Float) = 1.0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
Blend One One
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float _Scale;
float4 frag(v2f_img i) : SV_Target
{
return tex2D(_MainTex, i.uv) * _Scale;
}
ENDCG
}
}
所以我有一个 RenderTexture,我想在其上绘制 "brush" 纹理。这是一个高度贴图,所以画笔中的 watherver 应该添加到 RenderTexture 的值中。
将纹理绘制到 rendertexture 并不难:
RenderTexture.active = _heightMap; //the render texture to be drawn to
Rect screenRect = new Rect(x, y, width, height);
Graphics.DrawTexture(screenRect, _brush, _addBrushMaterial);
我想我现在需要一个 material 来为我的纹理添加画笔的颜色(“_addBrushMaterial”)。但是我找不到如何制作它所以它增加了它的颜色。目前它的片段着色器只是设置颜色,所以这不好,应该添加它:
float4 frag (v2f_img i) : SV_Target
{
float4 col = tex2D(_MainTex, i.uv);
return col * _Scale;
}
关于这方面的文档似乎非常有限,因此非常感谢您的帮助!
谢谢
好的,所以我找到了一些有用的东西。我所要做的就是添加 "Blend One One".
我现在使用以下着色器:
Properties
{
_MainTex ("Brush", 2D) = "white" {}
_Scale("Scaling factor", Float) = 1.0
}
SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always
Pass
{
Blend One One
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float _Scale;
float4 frag(v2f_img i) : SV_Target
{
return tex2D(_MainTex, i.uv) * _Scale;
}
ENDCG
}
}