香港6合总彩透码主论坛
 找回密码
 注册帐号

扫一扫,访问微社区

着色器 求教shader大佬,或者用过GPU Instancer插件的

1
回复
500
查看
打印 上一主题 下一主题
[ 复制链接 ]
6蛮牛粉丝
1318/1500
排名
3287
昨日变化

22

主题

133

帖子

1318

积分

Rank: 6Rank: 6Rank: 6

UID
123454
好友
0
蛮牛币
1216
威望
0
注册时间
2015-9-22
在线时间
709 小时
最后登录
2019-8-16
30蛮牛币
本帖最后由 稻?#36164;?#20102;吗 于 2019-6-20 21:41 编辑

我想用自己的shader代替它?#28304;?#30340;shader,然后实现类似案例里的效果 这是他的shader
[C#] ?#35838;?#26412;查看 复制代码
Shader "GPUInstancer/ColorVariationShader" {
        Properties {
                _Color ("Color", Color) = (1,1,1,1)
                _MainTex ("Albedo (RGB)", 2D) = "white" {}
                _Glossiness ("Smoothness", Range(0,1)) = 0.5
                _Metallic ("Metallic", Range(0,1)) = 0.0
        }
        SubShader {
                Tags { "RenderType"="Opaque" }
                LOD 200

                CGPROGRAM
#include "UnityCG.cginc"
#include "./../../../Shaders/Include/GPUInstancerInclude.cginc"
#pragma instancing_options procedural:setupGPUI
#pragma multi_compile_instancing
                #pragma surface surf Standard addshadow fullforwardshadows

                #pragma target 3.0

                sampler2D _MainTex;

                struct Input {
                        float2 uv_MainTex;
                };

                half _Glossiness;
                half _Metallic;
                fixed4 _Color;

                #if SHADER_API_D3D11
                #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
                        StructuredBuffer<float4> colorBuffer;
                #endif
                #endif
                
                void surf (Input IN, inout SurfaceOutputStandard o) {
                        float4 col = _Color;

                        #if SHADER_API_D3D11
                        #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
                                        uint index = gpuiTransformationMatrix[unity_InstanceID];
                                        col = colorBuffer[index];
                        #endif
                        #endif

                        // Albedo comes from a texture tinted by color
                        fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * saturate(col);
                        o.Albedo = c.rgb;
                        // Metallic and smoothness come from slider variables
                        o.Metallic = _Metallic;
                        o.Smoothness = _Glossiness;
                        o.Alpha = c.a;
                }

                ENDCG
        }
        FallBack "Standard"
}




然后我照着改了一下自己用shaderforge连的一个高亮的shader,想实现每个颜色不同的效果,但是全部实例的颜色始?#24080;?#19968;样的然后不停的?#20102;福?#36825;是我改的shader
[C#] ?#35838;?#26412;查看 复制代码
Shader "Custom/ligthing" {
    Properties {
        _Color ("Color", Color) = (0.07843138,0.3921569,0.7843137,1)
    }
    SubShader {
        Tags {
            "RenderType"="Opaque"
        }
        
        Pass {
            Name "FORWARD"
            Tags {
                "LightMode"="ForwardBase"
            }
            
            
            CGPROGRAM
                        #include "UnityCG.cginc"
            #include "./../../../Shaders/Include/GPUInstancerInclude.cginc"
            #pragma multi_compile_instancing
            #pragma instancing_options procedural:setupGPUI
                        //#pragma surface surf Standard fullforwardshadows
            #pragma vertex vert
            #pragma fragment frag
                        //#pragma surface surf Standard fullforwardshadows
            // #define UNITY_PASS_FORWARDBASE
            #pragma multi_compile_fwdbase_fullshadows
            #pragma only_renderers d3d9 d3d11 glcore gles 
            #pragma target 3.0
            uniform float4 _Color;

                        #if SHADER_API_D3D11
                     #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
                        StructuredBuffer<float4> colorBuffer;
                    #endif
                    #endif
                        
            struct VertexInput {
                float4 vertex : POSITION;
                                UNITY_VERTEX_INPUT_INSTANCE_ID
            };
            struct VertexOutput {
                float4 pos : SV_POSITION;
            };
            VertexOutput vert (VertexInput v) {                            
                VertexOutput o = (VertexOutput)0;        
                                UNITY_SETUP_INSTANCE_ID(v);
                o.pos = UnityObjectToClipPos( v.vertex );
                return o;
            }                        
            float4 frag(VertexOutput i) : COLOR {
////// Lighting:
////// Emissive:
            float4 col = _Color; 

                        #if SHADER_API_D3D11
                        #ifdef UNITY_PROCEDURAL_INSTANCING_ENABLED
                                        uint index = gpuiTransformationMatrix[unity_InstanceID];
                                        col = colorBuffer[index];
                        #endif
                        #endif
                //float3 emissive = _Color.rgb;
                                float3 emissive = saturate(col).rgb;
                float3 finalColor = emissive;
                return fixed4(finalColor,1);
            }
            ENDCG
        }
    }
    FallBack "Diffuse"

}


有没有大佬知道要怎么更改

QQ浏览器截图20190620190653.png (59.11 KB, 下载?#38382;? 0)

QQ浏览器截图20190620190653.png

QQ浏览器截图20190620190703.png (33.72 KB, 下载?#38382;? 1)

QQ浏览器截图20190620190703.png
回复

使用道具 举报

6蛮牛粉丝
1318/1500
排名
3287
昨日变化

22

主题

133

帖子

1318

积分

Rank: 6Rank: 6Rank: 6

UID
123454
好友
0
蛮牛币
1216
威望
0
注册时间
2015-9-22
在线时间
709 小时
最后登录
2019-8-16
沙发
楼主 2019-4-25 17:22:59 只看?#31859;?#32773;
本帖最后由 稻?#36164;?#20102;吗 于 2019-4-25 18:11 编辑

有没有大佬呀
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册帐号

本版积分规则

香港6合总彩透码主论坛