首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定制着色器-统一- Diffuse+Lightmap+normal+cubemap

定制着色器-统一- Diffuse+Lightmap+normal+cubemap
EN

Stack Overflow用户
提问于 2015-01-16 16:57:46
回答 1查看 5K关注 0票数 0

我一直在为一个使用Unity4.6的项目定制着色器,因为团结的着色器提供了很多不同的选项,但不是我想要的。我已经看过关于我的着色器问题的堆栈溢出,但每个问题都是关于使用着色器的棘手和高技术问题。我认为我的很简单(对于一个有经验的开发人员),但还没有发布。

问题是:我想合并两个着色器,以获得一个"Diffuse+normal+cubemap+lighmap“着色器。

,所以,在一边,我有一个“漫射+ NormalMap + LightMap”着色器,看起来像这样(这是遗留的/光图的保险杠规格a,稍微调整一下以获得镜面的光泽):

代码语言:javascript
复制
 Shader "Legacy Shaders/Lightmapped/Custom/BumpedSpec" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 1)
    _Shininess ("Shininess", Range (0.03, 1)) = 0.078125
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _BumpMap ("Normalmap", 2D) = "bump" {}
    _LightMap ("Lightmap (RGB)", 2D) = "black" {}
}

SubShader {
    LOD 200
    Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf BlinnPhong
struct Input {
  float2 uv_MainTex;
  float2 uv_BumpMap;
  float2 uv2_LightMap;
};
sampler2D _MainTex;
sampler2D _LightMap;
sampler2D _BumpMap;
float4 _Color;
float _Shininess;

void surf (Input IN, inout SurfaceOutput o)
{
  half4 tex = tex2D (_MainTex, IN.uv_MainTex);
  o.Albedo = tex.rgb * _Color;
  half4 lm = tex2D (_LightMap, IN.uv2_LightMap);
  o.Emission = lm.rgb*o.Albedo.rgb;
  o.Gloss = tex.a;
  o.Alpha = lm.a * _Color.a;
  o.Specular = _Shininess;
  o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
FallBack "Legacy Shaders/Lightmapped/VertexLit"
}

和另一边,我有一个带有"Diffuse+cubemap+Lightmap“的着色器,看起来像这样:

代码语言:javascript
复制
Shader "Custom/CubeLightmap" {
Properties {
    _Color ("Main Color", Color) = (1,1,1,1)
    _ReflectColor ("Reflection Color", Color) = (1,1,1,0.5)
    _MainTex ("Base (RGB) RefStrength (A)", 2D) = "white" {}
    _Cube ("Reflection Cubemap", Cube) = "_Skybox" { TexGen CubeReflect }
    _LightMap ("Lightmap (RGB)", 2D) = "lightmap" { LightmapMode }
}
SubShader {
    LOD 200
    Tags { "RenderType"="Opaque" }

CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
samplerCUBE _Cube;
sampler2D _LightMap;
fixed4 _Color;
fixed4 _ReflectColor;
struct Input {
    float2 uv_MainTex;
    float3 worldRefl;
    float2 uv2_LightMap;
};
void surf (Input IN, inout SurfaceOutput o) {
    fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
    fixed4 c = tex * _Color;
    o.Albedo = c.rgb;   
    half4 lm = tex2D(_LightMap,IN.uv2_LightMap);   
    fixed4 reflcol = texCUBE (_Cube, IN.worldRefl);
    reflcol *= tex.a;
    o.Emission = lm.rgb * reflcol.rgb * _ReflectColor.rgb;
    o.Alpha = reflcol.a * _ReflectColor.a * lm.a;
}
ENDCG
}   
FallBack "Reflective/VertexLit"
}

所以我想把它们合并(也就是在第一个中包含cubemap或者在第二个中包含标准映射),我暂时还不明白。

所以我需要一些建议或者帮助来实现它。

先谢谢你,问候

EN

回答 1

Stack Overflow用户

发布于 2015-01-19 15:01:42

听起来,我觉得你是想创建一个辐射正常的映射着色器。这将要求您至少了解C++和HSLS的基础知识。

您将遇到的最大问题将是如何计算辐射度正常地图,因为这需要一个精心制作的光地图。我只知道这样做的软件是野兽( AutoDesk )

之后,您将需要一些简单的着色器。有一些详细的说明,以及相关的代码位于

  • 半衰期2阴影
  • 阀门软件
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27988953

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档