对于我的项目,我需要在运行时创建材质。创建材质时,法线贴图不起作用。我尝试了这两种解决方案,但它们对我不起作用。在 Unity 5 中对此有什么改变吗?
我检查的链接:
http://answers.unity3d.com/questions/801670/runtime-loading-normal-texture.html http://answers.unity3d.com/questions/47121/runtime-normal-map-import.html
PS:奇怪的是,当我在 Unity 中切换到“场景视图”时,如果我从“检查器”中展开材质选项卡,法线贴图将应用于对象。
我的代码:
....
Material mat = new Material(Shader.Find("Standard (Specular setup)"));
mat.SetTexture("_MainTex", colortex);
normaltex = getNormalTexture(Texture2D source);
mat.SetTexture("_BumpMap", normaltex);
mat.SetFloat("_Glossiness", 0.1f);
mat.SetFloat("_BumpScale", 1.0f);
....
public static Texture2D getNormalTexture(Texture2D source)
{
Texture2D normalTexture = new Texture2D(source.width, source.height, TextureFormat.ARGB32, true);
Color theColour = new Color();
for (int x = 0; x < source.width; x++)
{
for (int y = 0; y < source.height; y++)
{
theColour.r = 0;
theColour.g = source.GetPixel(x, y).g;
theColour.b …Run Code Online (Sandbox Code Playgroud) 我有3D体积纹理,我用下面的行初始化它:
glTexImage3D(GL_TEXTURE_3D, 0, GL_RED, numX, numY, numZ, 0, GL_RED, GL_UNSIGNED_BYTE, voldata);
Run Code Online (Sandbox Code Playgroud)
在片段着色器中,我想读取此纹理的值,但我无法用texture3d()函数读取.
下面的行在片段着色器中给出编译错误:(没有匹配为texture3d重载)
float value = texture3d(VolumeTexture,vec3(0.2f,0.2f,0.2f);
Run Code Online (Sandbox Code Playgroud)
如何从sampler3d获取数据?
OpenGLPart:
unsigned int texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_3D, texture);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RED, numX, numY, numZ, 0, GL_RED, GL_UNSIGNED_BYTE, voldata);
free(voldata ); //free the texture
...
display()
{
....
glActiveTexture(GL_TEXTURE0);
int texture_location = glGetUniformLocation(shader.id(), "VolumeTexture");
glUniform1i(texture_location, 0);
glBindTexture(GL_TEXTURE_3D,volumetext);
....
}
Run Code Online (Sandbox Code Playgroud)
我的片段着色器:
uniform sampler3D VolumeTexture;
void main()
{ …Run Code Online (Sandbox Code Playgroud) 我有一个简单的程序,找到自动数字达到给定的数字.问题是它只找到square参数绑定int的数字.
例如:90625 x 90625 = 8212890625但程序找不到它.
问题:这里有长型有什么问题?它就像int一样.在代码的任何地方都有一个转换为int的square参数吗?
#include <stdio.h>
int main(void)
{
int n;
long i;
printf ("Enter a value:\n") ;
scanf ("%d",&n) ;
printf ("Automorphic numbers:\n") ;
for (i=1L ; i<=n ; i = i+1L)
{
long square = i*i ;
if (square % 10L == i || square % 100L == i || square % 1000L == i || square % 10000L == i || square % 100000L == i || square % 1000000L == i || square …Run Code Online (Sandbox Code Playgroud)