- Home /
[FOUND] Mobile shader with those mixed effects : Transparency, specular, diffuse, cubemap reflection ?
Hello everybody
Does you know some free or paid mobile shaders with those combined/mixed effects ?
Transparency
specular
diffuse
cubemap reflection
Thanks a lot for your answers
Edit :
Good news ! I solved my problem with ShaderForge
The shader that matchs my effects is this one :
Shader "Shader Forge/chrome" { Properties { _Color ("Color", Color) = (0.8161765,0.8161765,0.8161765,1) _Diffuse_Tex ("Diffuse_Tex", 2D) = "white" {} _Reflect ("Reflect", Cube) = "_Skybox" {} _Alpha ("Alpha", Range(0, 1)) = 1 [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 } SubShader { Tags { "IgnoreProjector"="True" "Queue"="Transparent" "RenderType"="Transparent" } Pass { Name "ForwardBase" Tags { "LightMode"="ForwardBase" } Blend SrcAlpha OneMinusSrcAlpha ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDBASE
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase
#pragma exclude_renderers xbox360 ps3 flash d3d11_9x
#pragma target 3.0
uniform float4 _LightColor0;
uniform float4 _Color;
uniform samplerCUBE _Reflect;
uniform sampler2D _Diffuse_Tex; uniform float4 _Diffuse_Tex_ST;
uniform float _Alpha;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 texcoord0 : TEXCOORD0;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float4 posWorld : TEXCOORD1;
float3 normalDir : TEXCOORD2;
};
VertexOutput vert (VertexInput v) {
VertexOutput o;
o.uv0 = v.texcoord0;
o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
o.posWorld = mul(_Object2World, v.vertex);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
fixed4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
/////// Normals: float3 normalDirection = i.normalDir; float3 viewReflectDirection = reflect( -viewDirection, normalDirection ); float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz); ////// Lighting: float attenuation = 1; float3 attenColor = attenuation _LightColor0.xyz; /////// Diffuse: float NdotL = dot( normalDirection, lightDirection ); float3 w = texCUBE(_Reflect,viewReflectDirection).rgb*0.5; // Light wrapping float3 NdotLWrap = NdotL ( 1.0 - w ); float3 forwardLight = max(float3(0.0,0.0,0.0), NdotLWrap + w ); float3 diffuse = forwardLight attenColor + UNITY_LIGHTMODEL_AMBIENT.rgb; float3 finalColor = 0; float3 diffuseLight = diffuse; float2 node_58 = i.uv0; finalColor += diffuseLight (tex2D(_Diffuse_Tex,TRANSFORM_TEX(node_58.rg, _Diffuse_Tex)).rgb*_Color.rgb); /// Final Color: return fixed4(finalColor,_Alpha); } ENDCG } Pass { Name "ForwardAdd" Tags { "LightMode"="ForwardAdd" } Blend One One ZWrite Off
Fog { Color (0,0,0,0) }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define UNITY_PASS_FORWARDADD
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#pragma multi_compile_fwdadd
#pragma exclude_renderers xbox360 ps3 flash d3d11_9x
#pragma target 3.0
uniform float4 _LightColor0;
uniform float4 _Color;
uniform samplerCUBE _Reflect;
uniform sampler2D _Diffuse_Tex; uniform float4 _Diffuse_Tex_ST;
uniform float _Alpha;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float2 texcoord0 : TEXCOORD0;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float4 posWorld : TEXCOORD1;
float3 normalDir : TEXCOORD2;
LIGHTING_COORDS(3,4)
};
VertexOutput vert (VertexInput v) {
VertexOutput o;
o.uv0 = v.texcoord0;
o.normalDir = mul(float4(v.normal,0), _World2Object).xyz;
o.posWorld = mul(_Object2World, v.vertex);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
TRANSFER_VERTEX_TO_FRAGMENT(o)
return o;
}
fixed4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
/////// Normals: float3 normalDirection = i.normalDir; float3 viewReflectDirection = reflect( -viewDirection, normalDirection ); float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w)); ////// Lighting: float attenuation = LIGHT_ATTENUATION(i); float3 attenColor = attenuation _LightColor0.xyz; /////// Diffuse: float NdotL = dot( normalDirection, lightDirection ); float3 w = texCUBE(_Reflect,viewReflectDirection).rgb*0.5; // Light wrapping float3 NdotLWrap = NdotL ( 1.0 - w ); float3 forwardLight = max(float3(0.0,0.0,0.0), NdotLWrap + w ); float3 diffuse = forwardLight attenColor; float3 finalColor = 0; float3 diffuseLight = diffuse; float2 node_59 = i.uv0; finalColor += diffuseLight (tex2D(_Diffuse_Tex,TRANSFORM_TEX(node_59.rg, _Diffuse_Tex)).rgb*_Color.rgb); /// Final Color: return fixed4(finalColor * _Alpha,0); } ENDCG } } FallBack "Diffuse" CustomEditor "ShaderForgeMaterialInspector" }
Answer by PommPoirAbricot · Jun 18, 2014 at 12:26 PM
Solution FOUND !! See my Edit in my question !
Answer by screenname_taken · Jun 17, 2014 at 11:51 AM
Unity already has them and they work fine. Do you have any particular issues with the shaders?
No particular issues Do you have please the names of the shaders matching those 4 effects at the same time ?
Reflective/Specular and Transparent/Specular seem to be what you're after.
Almost but
it lacks the transparency for Reflective/Specular
it lacks the reflection for Transparent/Scpecular
And those shader must works for $$anonymous$$obile
The source for the built-in shaders is available at http://download.unity3d.com/download_unity/builtin_shaders-4.5.1.zip
, and it's trivial to combine the bits of each shader that you want.
There's no reason why those shaders won't work on mobile - sure, it's generally not a good idea to use complex shaders on mobile, and you'll be unlikely to get good performance, but if you're set on having all those features then you're inevitably going to take a performance hit.
Ok i will try that, but i still remain open about ideas Thanks tanoshimi
Edit : Ok i have no idea how to add transparancy to Reflective/Specular shader Can someone please help me ?
Your answer
Follow this Question
Related Questions
transparent + reflection shader (river water problems) 2 Answers
Creating realistic glass 4 Answers
Check performance of shader for mobile 1 Answer
Specular map to decide reflection 0 Answers