Jump to content

Shader Problems


MrVR
 Share

Recommended Posts

Hi Guys IM trying to create a water shader from some code I found online, but I having this error , if you guys know how to fix it please let me know how. blow the error and the code 

 

Capture.PNG.3e1a898f06aa834a9c908846b57af78b.PNG

Quote

Shader "BabylonJS/waterShader" {
	Properties {
		_Color ("Color", Color) = (1,1,1,1)
		_Brightness ("Intensity", Range(1.0, 10.0)) = 1.0
		[NoScaleOffset] _MainTex ("Albedo (RGB)", 2D) = "white" {}
		_ScaleX ("Scale Factor X", Range (0.0, 10.0)) = 1.0
		_ScaleY ("Scale Factor Y", Range (0.0, 10.0)) = 1.0
		_Metallic ("Metallic", Range(0,1)) = 0.0
		_Glossiness ("Smoothness", Range(0,1)) = 0.5
		[ToggleOff] _NeedsAlphaTesting ("Needs Alpha Testing", Int) = 0
		[ToggleOff] _NeedsAlphaBlending ("Needs Alpha Blending", Int) = 0
		[Enum(Disable,0,Additive,1,Combine,2,Subtract,3,Multiply,4,Maximized,5,OneOne,6)] _AlphaMode ("Alpha Blending Mode", int) = 2
	}
	SubShader {
		Tags { "RenderType"="Opaque" }
		
			CGPROGRAM

			//////////////////////////////////////////////////////////
			// BABYLON WEBGL RUNTIME SHADER PROGRAM SECTIONS (GLSL) //
			//////////////////////////////////////////////////////////

			#ifdef BABYLON
			// attributes: ["position", "normal", "uv"]
			// uniforms: ["worldViewProjection, _Color, _Brightness, _Glossiness, _Metallic, _ScaleX, _ScaleY"]
			// samplers: []
			// defines: []
			// #endif //BABYLON-END

			attributes: []
			uniforms: ["waterHeight, time, numWaves, amplitude, wavelength, speed, direction, eyePos,envMap, gl_NormalMatrix, gl_ModelViewProjectionMatrix"]
			samplers: []
			defines: []
			#endif //BABYLON-END


			#ifdef VERTEX
			// attribute vec3 position;
			// attribute vec3 normal;
			// attribute vec2 uv;
			// uniform mat4 worldViewProjection;
			// precision highp float;

			// varying vec2 vUV;
			
			// void main(void)
			// {
			// 	gl_Position = worldViewProjection * vec4(position, 1.0);
			// 	vUV = uv;
			// }

			const float pi = 3.14159;
			uniform float waterHeight;
			uniform float time;
			uniform int numWaves;
			uniform float amplitude[8];
			uniform float wavelength[8];
			uniform float speed[8];
			uniform vec2 direction[8];
			varying vec3 position;
			varying vec3 worldNormal;
			varying vec3 eyeNormal;
			highp vec4 gl_Position; // should be written to
			mediump float gl_PointSize;

			float wave(int i, float x, float y) {
				float frequency = 2.0*pi/wavelength[i];
				float phase = speed[i] * frequency;
				float theta = dot(direction[i], vec2(x, y));
				return amplitude[i] * sin(theta * frequency + time * phase);
			}

			float waveHeight(float x, float y) {
				float height = 0.0;
				for (int i = 0.0; i < numWaves; ++i)
					height += wave(i, x, y);
				return height;
			}

			float dWavedx(int i, float x, float y) {
				float frequency = 2.0*pi/wavelength[i];
				float phase = speed[i] * frequency;
				float theta = dot(direction[i], vec2(x, y));
				float A = amplitude[i] * direction[i].x * frequency;
				return A * cos(theta * frequency + time * phase);
			}

			float dWavedy(int i, float x, float y) {
				float frequency = 2.0*pi/wavelength[i];
				float phase = speed[i] * frequency;
				float theta = dot(direction[i], vec2(x, y));
				float A = amplitude[i] * direction[i].y * frequency;
				return A * cos(theta * frequency + time * phase);
			}

			vec3 waveNormal(float x, float y) {
				float dx = 0.0;
				float dy = 0.0;
				for (int i = 0; i < numWaves; ++i) {
					dx += dWavedx(i, x, y);
					dy += dWavedy(i, x, y);
				}
				vec3 n = vec3(-dx, -dy, 1.0);
				return normalize(n);
			}

			void main(void) {
				vec4 pos = gl_Vertex;
				pos.z = waterHeight + waveHeight(pos.x, pos.y);
				position = pos.xyz / pos.w;
				worldNormal = waveNormal(pos.x, pos.y);
				eyeNormal = gl_NormalMatrix * worldNormal;
				gl_Position = gl_ModelViewProjectionMatrix * pos;
			}

			#endif //VERTEX-END


			#ifdef FRAGMENT
			// precision highp float;

			// varying vec2 vUV;
			// uniform vec4 _Color;
			// uniform float _Brightness;
			// uniform float _Glossiness;
			// uniform float _Metallic;
			// uniform float _ScaleX;
			// uniform float _ScaleY;
			// uniform sampler2D _MainTex;

			// void main(void)
			// {
			// 	gl_FragColor = texture2D(_MainTex, vec2(vUV.x * _ScaleX, vUV.y * _ScaleY)) * _Color * _Brightness;
			// }
			varying vec3 position;
			varying vec3 worldNormal;
			varying vec3 eyeNormal;
			uniform vec3 eyePos;
			uniform samplerCube envMap;

			void main(void) {
				vec3 eye = normalize(eyePos - position);
				vec3 r = reflect(eye, worldNormal);
				vec4 color = textureCube(envMap, r);
				color.a = 0.5;
				gl_FragColor = color;
			}

			
			#endif //FRAGMENT-END 


			////////////////////////////////////////////////////////
			// DEFAULT UNITY EDITOR SHADER PROGRAM SECTION (HLSL) //
			////////////////////////////////////////////////////////

			#pragma exclude_renderers d3d11 xbox360 gles
			#pragma surface surf Standard fullforwardshadows
			#pragma target 3.0
			sampler2D _MainTex;
			struct Input {
				float2 uv_MainTex;
			};
			half _Brightness;
			half _Glossiness;
			half _Metallic;
			half _ScaleX;
			half _ScaleY;
			fixed4 _Color;
			void surf (Input IN, inout SurfaceOutputStandard o) {
				// Albedo comes from a texture tinted by color
				float2 vUV = IN.uv_MainTex;
				fixed4 c = tex2D (_MainTex, float2(vUV.x * _ScaleX, vUV.y * _ScaleY)) * _Color * _Brightness;
				o.Albedo = c.rgb;
				// Metallic and smoothness come from slider variables
				o.Metallic = _Metallic;
				o.Smoothness = _Glossiness;
				o.Alpha = c.a;
			}

			ENDCG
		
	}
	FallBack "Diffuse"
}

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...