private void RenderToTexture() { InitRenderTexture(); int kernelIndex = RayTracingCS.FindKernel("CSMain"); RayTracingCS.SetTexture(kernelIndex, ShaderProperties.TexResult, _target); RayTracingCS.SetTexture(kernelIndex, ShaderProperties.TexSkybox, SkyboxTexture); RayTracingCS.SetBuffer(kernelIndex, ShaderProperties.CompBuffSpheres, _bufferSpheres); RayTracingCS.SetInt(ShaderProperties.IntBouncesCount, BouncesCount); RayTracingCS.SetMatrix(ShaderProperties.MatCameraToWorld, _camera.cameraToWorldMatrix); RayTracingCS.SetMatrix(ShaderProperties.MatCameraInverseProjection, _camera.projectionMatrix.inverse); RayTracingCS.SetVector(ShaderProperties.VecPixelOffsetAA, new Vector4(Random.value, Random.value, 0.0f, 0.0f)); RayTracingCS.SetVector(ShaderProperties.VecAmbientColor, AmbientColor.linear); RayTracingCS.SetFloat("_Seed", Random.value); var dirLight = -DirectionalLight.transform.forward; RayTracingCS.SetVector(ShaderProperties.VecDirectionalLight, new Vector4(dirLight.x, dirLight.y, dirLight.z, DirectionalLight.intensity)); int threadsGroupX = Mathf.CeilToInt(Screen.width / 8.0f); int threadsGroupY = Mathf.CeilToInt(Screen.height / 8.0f); RayTracingCS.Dispatch(kernelIndex, threadsGroupX, threadsGroupY, 1); }
private void SetShaderParameters() { _shader.SetMatrix("_CameraToWorld", _camera.cameraToWorldMatrix); _shader.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); _shader.SetTexture(0, "_SkyboxTexture", _SkyboxTexture); }
void RunShaderTerrain(Matrix4x4 world, Vector3 start, int channel) { _kernel = computeShader.FindKernel("ComputeTerrainSplatter"); // computeShader.SetMatrix("iL2W", world); computeShader.SetInt("iChannel", channel); computeShader.SetVector("iStartPos", start); computeShader.SetFloat("iRadius", Radius); computeShader.SetVector("iTerrainSize", new Vector2(_terrainSplatter.width, _terrainSplatter.height)); // Setup textures computeShader.SetTexture(_kernel, "TerrainHeightmap", _terrainHeightmap); computeShader.SetTexture(_kernel, "TerrainResult", _terrainSplatter); // Dispatch computeShader.Dispatch(_kernel, Mathf.CeilToInt(_terrainSplatter.width / 8f), Mathf.CeilToInt(_terrainSplatter.height / 8f), 1); // Update terrain material MaterialPropertyBlock mpb = new MaterialPropertyBlock(); terrain.GetSplatMaterialPropertyBlock(mpb); mpb.SetTexture("_Splatter", _terrainSplatter); terrain.SetSplatMaterialPropertyBlock(mpb); }
public void SetCurrentData(ref Matrix4x4 vp, ref Matrix4x4 v, bool updatePos) { if (updatePos) { lastMatrices.Clear(); for (int i = 0; i < matrices.Count; ++i) { lastMatrices.Add(matrices[i].MTW); } lastMvpBuffer.SetData(lastMatrices); matrices.Clear(); for (int i = 0; i < transforms.Length; ++i) { Matrix matrix; matrix.MTW = transforms[i].localToWorldMatrix; matrix.MV = new Matrix4x4(); matrix.MVP = new Matrix4x4(); matrices.Add(matrix); } mvpBuffer.SetData(matrices); } matrixComputeShader.SetBuffer(shaderKernal, _Matrices, mvpBuffer); matrixComputeShader.SetMatrix(_ViewMatrix, v); matrixComputeShader.SetMatrix(_VPMatrix, vp); matrixComputeShader.Dispatch(shaderKernal, mvpBuffer.count, 1, 1); }
private void UpdateShaderParameters() { //update target dimensions if (_width != _camera.pixelWidth || _height != _camera.pixelHeight) { _width = _camera.pixelWidth; _height = _camera.pixelHeight; RayMarchingShader.SetInt("_Width", _width); RayMarchingShader.SetInt("_Height", _height); } //update camera position if (transform.hasChanged) { RayMarchingShader.SetMatrix("_Camera2World", _camera.cameraToWorldMatrix); RayMarchingShader.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); transform.hasChanged = false; } //update light direction if (directionalLight.transform.hasChanged) { Vector3 l = directionalLight.transform.forward; RayMarchingShader.SetVector("_DirectionalLight", new Vector4(l.x, l.y, l.z, directionalLight.intensity)); } //update entities if (RaymarchingEntityManager.Dirty) { RayMarchingShader.SetBuffer(_mainKernelID, "_RMEntities", RaymarchingEntityManager.EntityBuffer); RayMarchingShader.SetInt("_RMEntitiesCount", RaymarchingEntityManager.EntityBuffer.count); } }
protected void ComputeTrails(Kernel kernel, float dt) { dt = Mathf.Clamp(dt, 0f, 0.1f); trailCompute.SetInt(kInstancesCountKey, instancesCount); trailCompute.SetBuffer(kernel.Index, kTrailsKey, trailBuffer); trailCompute.SetBuffer(kernel.Index, kBonesKey, boneBuffer); trailCompute.SetInt(kBonesCountKey, boneCount); trailCompute.SetFloat(kBonesCountInvKey, 1f / boneCount); var t = Time.timeSinceLevelLoad; trailCompute.SetVector(kTimeKey, new Vector4(t / 20f, t, t * 2f, t * 3f)); trailCompute.SetVector(kDTKey, new Vector2(dt, (dt < float.Epsilon) ? 0f : 1f / dt)); trailCompute.SetMatrix(kWorldToLocalKey, transform.worldToLocalMatrix); trailCompute.SetMatrix(kLocalToWorldKey, transform.localToWorldMatrix); trailCompute.SetFloat(kTrailFollowIntensityKey, trailFollowIntensity); trailCompute.SetVector(kTrailFollowDelayKey, new Vector2(trailFollowDelayMin, trailFollowDelayMax)); trailCompute.SetVector(kDamperKey, new Vector2(Mathf.Exp(-drag * dt), speedLimit)); trailCompute.SetVector(kGravityKey, gravity * dt); trailCompute.SetVector(kNoiseParamsKey, new Vector2(noiseFrequency, noiseAmplitude * dt)); var noiseDir = (gravity == Vector3.zero) ? Vector3.up : gravity.normalized; noiseOffset += noiseDir * noiseMotion * dt; trailCompute.SetVector(kNoiseOffsetKey, noiseOffset); trailCompute.Dispatch(kernel.Index, instancesCount / kernel.ThreadX + 1, kernel.ThreadY, kernel.ThreadZ); }
private void UpdateShaderParameters() { visualizer.SetMatrix("CameraToWorld", camera.cameraToWorldMatrix); visualizer.SetMatrix("CameraInverseProjection", camera.projectionMatrix.inverse); //visualizer.SetVector("PixelOffset", new Vector2(UnityEngine.Random.value, UnityEngine.Random.value)); visualizer.SetVector("PixelOffset", new Vector2(0.5f, 0.5f)); }
public void SetData(ComputeShader compute) { compute.SetFloat("_LensRadius", lensRadius); compute.SetFloat("_ImageDistance", imagePlaneDistance); compute.SetMatrix("_Camera2World", _camera.cameraToWorldMatrix); compute.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); }
private void SetShaderParameters() { RayTracingShader.SetTexture(0, "Result", _target); RayTracingShader.SetTexture(0, "_SkyboxTexture", SkyboxTexture); RayTracingShader.SetFloat("_GroundPlane", plane.GetComponent <Transform>().position.y); RayTracingShader.SetInt("nbBounces", numberOfBounces); if (withAntiAliassing) { RayTracingShader.SetVector("_PixelOffset", new Vector2(Random.value, Random.value)); } else { RayTracingShader.SetVector("_PixelOffset", new Vector2(0.5f, 0.5f)); } //light direction Vector3 l = light.transform.forward; RayTracingShader.SetVector("_DirectionalLight", new Vector4(l.x, l.y, l.z, light.intensity)); //array of Spheres RayTracingShader.SetBuffer(0, "_Spheres", _SphereBuffer); //camera matrix RayTracingShader.SetMatrix("_CameraToWorld", _camera.cameraToWorldMatrix); RayTracingShader.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); }
void SetParameters() { fractalShader.SetTexture(0, "Destination", target); fractalShader.SetFloat("power", Mathf.Max(fractalPower, 1.01f)); fractalShader.SetFloat("darkness", darkness); fractalShader.SetFloat("blackAndWhite", blackAndWhite); fractalShader.SetFloat("maxDst", drawDistance); fractalShader.SetVector("colourAMix", new Vector3(redA, greenA, blueA)); fractalShader.SetVector("colourBMix", new Vector3(redB, greenB, blueB)); fractalShader.SetInt("maxStepCount", maxStepCount); if (LODChangeWithDist) { maxIterations = Mathf.FloorToInt(5f / minDist); } else { maxIterations = 15; } fractalShader.SetInt("maxIterations", maxIterations); fractalShader.SetMatrix("_CameraToWorld", cam.cameraToWorldMatrix); fractalShader.SetMatrix("_CameraInverseProjection", cam.projectionMatrix.inverse); fractalShader.SetVector("_LightDirection", directionalLight.transform.forward); fractalShader.SetBuffer(handleCSMain, "GroupMinBuffer", groupMinBuffer); }
void TransferData() { var width = _positionMap.width; var height = _positionMap.height; var vcount = _positionList.Count; var vcount_x3 = vcount * 3; var l2w = _source.transform.localToWorldMatrix; _compute.SetInt("VertexCount", vcount); _compute.SetMatrix("Transform", l2w); _compute.SetMatrix("OldTransform", _previousTransform); _compute.SetFloat("FrameRate", 1 / Time.deltaTime); _positionBuffer1.SetData(_positionList); _normalBuffer.SetData(_normalList); _compute.SetBuffer(0, "PositionBuffer", _positionBuffer1); _compute.SetBuffer(0, "OldPositionBuffer", _positionBuffer2); _compute.SetBuffer(0, "NormalBuffer", _normalBuffer); _compute.SetTexture(0, "PositionMap", _positionMap); _compute.SetTexture(0, "VelocityMap", _velocityMap); _compute.SetTexture(0, "NormalMap", _normalMap); _compute.Dispatch(0, width / 8, height / 8, 1); }
void Update() { if (m_skinnedMesh == null || m_computeShader == null || m_positionRT == null || m_velocityRT == null) { return; } m_skinnedMesh.BakeMesh(m_mesh); CheckInternalResources(); m_mesh.GetVertices(m_positionList); m_positionBuffer.SetData(m_positionList); m_computeShader.SetInt("m_vertexCount", m_positionBuffer.count); m_computeShader.SetFloat("m_deltaTime", Time.deltaTime); //- m_computeShader.SetMatrix("m_transformMatrix", m_skinnedMesh.transform.localToWorldMatrix); m_computeShader.SetMatrix("m_prevTransformMatrix", m_prevTransformMatrix); //- m_computeShader.SetBuffer(m_kernel, "m_positionBuffer", m_positionBuffer); m_computeShader.SetBuffer(m_kernel, "m_prevPositionBuffer", m_prevPositionBuffer); //- m_computeShader.SetTexture(m_kernel, "m_positionRT", m_tempPosRT); m_computeShader.SetTexture(m_kernel, "m_velocityRT", m_tempVelRT); m_computeShader.Dispatch(m_kernel, m_positionRT.width / 8, m_positionRT.height / 8, 1); //Update Result Graphics.Blit(m_tempPosRT, m_positionRT); Graphics.Blit(m_tempVelRT, m_velocityRT); //Update Prev Data m_prevTransformMatrix = m_skinnedMesh.transform.localToWorldMatrix; m_prevPositionBuffer.SetData(m_positionList); }
private void UpdateShaderParameters() { //update target dimensions if (_width != _camera.pixelWidth || _height != _camera.pixelHeight) { _width = _camera.pixelWidth; _height = _camera.pixelHeight; RayMarchingShader.SetInt("_Width", _width); RayMarchingShader.SetInt("_Height", _height); } //update camera position if (transform.hasChanged) { RayMarchingShader.SetMatrix("_Camera2World", _camera.cameraToWorldMatrix); RayMarchingShader.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); transform.hasChanged = false; } //update light direction if (light.transform.hasChanged) { Vector3 l = light.transform.forward; RayMarchingShader.SetVector("_DirectionalLight", new Vector4(l.x, l.y, l.z, light.intensity)); } }
private void SetShaderParameters() { _pathTracingShader.SetTexture(0, "Result", _target); _pathTracingShader.SetTexture(0, "_SkyboxTexture", _skyboxTexture); _pathTracingShader.SetTexture(0, "_BlueNoiseTexture", _noiseTextures[_currentSample % _noiseTextures.Length]); if (_computeError && _squaredDifferencesBuffer != null && _referenceTexture != null) { _pathTracingShader.SetTexture(0, "_ReferenceImage", _referenceTexture); _pathTracingShader.SetBuffer(0, "_SquaredDifferences", _squaredDifferencesBuffer); } SetBuffer("_Planes", _planeBuffer); SetBuffer("_Spheres", _sphereBuffer); SetBuffer("_Vertices", _vertexBuffer); SetBuffer("_Indices", _indexBuffer); SetBuffer("_Meshes", _meshBuffer); SetBuffer("_Materials", _materialBuffer); Vector3 l = _directionalLight.transform.forward; _pathTracingShader.SetVector("_DirectionalLight", new Vector4(l.x, l.y, l.z, _directionalLight.intensity)); _pathTracingShader.SetMatrix("_CameraToWorld", _camera.cameraToWorldMatrix); _pathTracingShader.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); _pathTracingShader.SetVector("_PixelOffset", new Vector2(Random.value, Random.value)); _pathTracingShader.SetFloat("_Seed", Random.value); _pathTracingShader.SetVector("_SharedSeed", new Vector3(Random.value, Random.value, Random.value)); }
void SetCamParams(ComputeShader cs) { var worldToCam = m_camera.worldToCameraMatrix.inverse; var camToWorld = m_camera.cameraToWorldMatrix; var projection = GL.GetGPUProjectionMatrix(m_camera.projectionMatrix, false); var inverseP = projection.inverse; var vp = projection * worldToCam; var projectionParams = new Vector4(1f, m_camera.nearClipPlane, m_camera.farClipPlane, 1f / m_camera.farClipPlane); var screenParams = new Vector4(m_camera.pixelWidth, m_camera.pixelHeight, 1f + 1f / (float)m_camera.pixelWidth, 1f + 1f / (float)m_camera.pixelHeight); if (cs != null) { cs.SetMatrix(prefix + propWorldToCam, worldToCam); cs.SetMatrix(prefix + propCamProjection, projection); cs.SetMatrix(prefix + propCamVP, vp); cs.SetMatrix(prefix + propScreenToCam, inverseP); cs.SetMatrix(prefix + propCamToWorld, camToWorld); cs.SetVector(prefix + propProjectionParams, projectionParams); cs.SetVector(prefix + propScreenParams, screenParams); } else { Shader.SetGlobalMatrix(prefix + propWorldToCam, worldToCam); Shader.SetGlobalMatrix(prefix + propCamProjection, projection); Shader.SetGlobalMatrix(prefix + propCamVP, vp); Shader.SetGlobalMatrix(prefix + propScreenToCam, inverseP); Shader.SetGlobalMatrix(prefix + propCamToWorld, camToWorld); Shader.SetGlobalVector(prefix + propProjectionParams, projectionParams); Shader.SetGlobalVector(prefix + propScreenParams, screenParams); } }
private void UpdateRaytracerParams() { // Textures. int height = Mathf.Clamp(maxResolution, 1, cachedCamera.pixelHeight); if (height > 1 && Mathf.IsPowerOfTwo(height)) { height++; // Weird black screen bug that happens when setting resolution to a power of 2... } int width = Mathf.CeilToInt(height * cachedCamera.aspect); CreateRenderBufferIfNeeded(width, height); raytracer.SetTexture(0, _Skybox, skybox); // Camera. raytracer.SetMatrix(_CameraToWorld, cachedCamera.cameraToWorldMatrix); raytracer.SetMatrix(_CameraInvProjection, cachedCamera.projectionMatrix.inverse); raytracer.SetVector(_CameraPosition, cachedTrans.position); raytracer.SetInt(_MaxBounces, Mathf.Max(0, maxRayBounces) + 1); // Other rendering. raytracer.SetBool(_HighQuality, highQuality); raytracer.SetFloat(_NoiseTime, (Time.unscaledTime * 1000f) % height); // Environment. raytracer.SetVector(_AmbientColor, ColorToVector(ambientColor, 1f)); raytracer.SetVector(_FogParams, ColorToVector(fogColor, fogDensity)); raytracer.SetVector(_LightDirection, dirLightTransform.forward); raytracer.SetVector(_LightColor, ColorToVector(dirLight.color, dirLight.intensity)); }
void OnRenderObject() { if (FocusObject != null) { FocusDistance = (transform.position - FocusObject.position).magnitude; transform.LookAt(FocusObject.position); } var camInverse = Camera.main.cameraToWorldMatrix; var ProjInverse = Camera.main.projectionMatrix.inverse; RayTraceKernels.SetFloat("_Seed01", (float)m_rng.NextDouble()); RayTraceKernels.SetFloat("_R0", (float)m_rng.NextDouble()); RayTraceKernels.SetFloat("_R1", (float)m_rng.NextDouble()); RayTraceKernels.SetFloat("_R2", (float)m_rng.NextDouble()); if (m_sceneChanged || m_lastAperture != Aperture || m_lastFocusDistance != FocusDistance || m_maxBounces != MaxBounces || camInverse != m_lastCam || ProjInverse != m_lastProj) { RayTraceKernels.SetMatrix("_Camera", Camera.main.worldToCameraMatrix); RayTraceKernels.SetMatrix("_CameraI", Camera.main.cameraToWorldMatrix); RayTraceKernels.SetMatrix("_ProjectionI", ProjInverse); RayTraceKernels.SetMatrix("_Projection", Camera.main.projectionMatrix); RayTraceKernels.SetFloat("_FocusDistance", FocusDistance); RayTraceKernels.SetFloat("_Aperture", Aperture); m_sceneChanged = false; m_lastAperture = Aperture; m_lastFocusDistance = FocusDistance; m_lastCam = camInverse; m_lastProj = ProjInverse; var rayStart = new Vector3(0, 0, 0); var rayEnd = new Vector3(0, 0, 1); rayStart = Camera.main.projectionMatrix.inverse.MultiplyPoint(rayStart); rayEnd = Camera.main.projectionMatrix.inverse.MultiplyPoint(rayEnd); m_maxBounces = MaxBounces; m_sampleCount = 0; RayTraceKernels.Dispatch(m_normalizeSamplesKernel, m_accumulatedImage.width / 8, m_accumulatedImage.height / 8, m_superSamplingFactor); } m_sampleCount++; RayTraceKernels.Dispatch(m_initCameraRaysKernel, m_accumulatedImage.width / 8, m_accumulatedImage.height / 8, m_superSamplingFactor); float t = Time.time; RayTraceKernels.SetVector("_Time", new Vector4(t / 20, t, t * 2, t * 3)); RayTraceKernels.SetInt("_MaxBounces", MaxBounces); RayTraceKernels.Dispatch(m_rayTraceKernel, m_accumulatedImage.width / 8, m_accumulatedImage.height / 8, m_superSamplingFactor * m_bouncesPerPixel); }
private void Update() { Matrix4x4 vp = GetVPMatrix(); Matrix4x4 p = obstacleProjectionCamera.projectionMatrix; crowdSimulationShader.SetMatrix("MATRIX_VP", vp); crowdSimulationShader.SetMatrix("INVERSE_MATRIX_VP", vp.inverse); crowdSimulationShader.SetMatrix("INVERSE_MATRIX_P", p.inverse); crowdSimulationShader.SetFloat("dt", Time.deltaTime); crowdSimulationShader.SetFloat("resolutionScale", resolutionScale); crowdSimulationShader.SetVector("screenSize", new Vector2( obstacleProjectionCamera.scaledPixelWidth, obstacleProjectionCamera.scaledPixelHeight)); crowdSimulationShader.SetVector("textureSize", new Vector2( obstaclesTexture.width, obstaclesTexture.height)); //RenderWorldStateTex(); //Move(); ComputeBuffer agentsBuffer = new ComputeBuffer(data.Count, sizeof(float) * 26); agentsBuffer.SetData <Walker>(data); Walker[] resultData = new Walker[data.Count]; AvoidStaticObstales(ref agentsBuffer); MoveV2(ref agentsBuffer); //TestMove(ref agentsBuffer); agentsBuffer.GetData(resultData); data = resultData.ToList(); UpdateAgents(); agentsBuffer.Dispose(); }
private void SetShaderParameters() { RayTracingShader.SetMatrix("_CameraToWorld", _camera.cameraToWorldMatrix); RayTracingShader.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); RayTracingShader.SetTexture(0, "_SkyboxTexture", SkyboxTexture); RayTracingShader.SetVector("_PixelOffset", new Vector2(Random.value, Random.value)); }
private void SetShaderParameters() { RayMarchingShader.SetFloat("_MinimumDistance", MinimumDistance); RayMarchingShader.SetFloat("_BreakeOffDistance", BreakeOffDistance); RayMarchingShader.SetInt("_ItterationLimit", ItterationLimit); RayMarchingShader.SetVector("_DirectionalLight", DirectionalLight.transform.forward * DirectionalLight.intensity); RayMarchingShader.SetFloat("_DirectionalLightAngle", DirectionalLightAngle); RayMarchingShader.SetFloat("_Blendingcoefficient", Blendingcoefficient); //RayMarchingShader.SetFloat("_RecursionDistance", RecursionDistance); UpdateBuffers(); //RayMarchingShader.SetBuffer(0, "_Spheres", _SphereBuffer); //RayMarchingShader.SetBuffer(0, "_Boxes", _BoxBuffer); RayMarchingShader.SetBuffer(0, "_Sponges", _BoxBuffer); RayMarchingShader.SetBuffer(0, "_DistanceBuffer", _DistanceBuffer); RayMarchingShader.SetMatrix("_CameraToWorld", cam.cameraToWorldMatrix); RayMarchingShader.SetMatrix("_CameraInverseProjection", cam.projectionMatrix.inverse); RayMarchingShader.SetTexture(0, "_SkyboxTexture", SkyboxTexture); if (pass == 0) { RayMarchingShader.SetVector("_PixelOffset", new Vector2(0.5f, 0.5f)); } else { RayMarchingShader.SetVector("_PixelOffset", new Vector2(Random.value, Random.value)); } RayMarchingShader.SetBool("_DynamicShadows", DynamicShadows); }
// Passes all the needed uniforms to the shader // TODO: Add more light types and the possibility of multiple lights void SetupComputeShader(RenderTexture srcTex, RenderTexture outTex) { // Pass the shapes buffer m_raymarchingShader.SetBuffer(0, "_shapes", m_shapesBuffer); m_raymarchingShader.SetInt("_numShapes", m_shapesData.Length); // Pass the lights buffer m_raymarchingShader.SetBuffer(0, "_lights", m_lightsBuffer); m_raymarchingShader.SetInt("_numLights", m_lights.Length); // Pass the needed matrices m_raymarchingShader.SetMatrix("_Camera2WorldMatrix", m_camera.cameraToWorldMatrix); m_raymarchingShader.SetMatrix("_InverseProjectionMatrix", m_camera.projectionMatrix.inverse); // Pass the textures m_raymarchingShader.SetTexture(0, "_srcTex", srcTex); m_raymarchingShader.SetTexture(0, "_outTex", outTex); // Pass the ambient light information m_raymarchingShader.SetFloat("_Ka", m_ambientIntensity); m_raymarchingShader.SetVector("_ambientColor", m_ambientColor); m_raymarchingShader.SetFloat("_Ksh", m_softShadowCoef); m_raymarchingShader.SetInt("_paintNormals", (m_paintNormals) ? 1:0); }
private void SetShaderParameters(RenderTexture source) { shader.SetMatrix("CameraToWorld", _camera.cameraToWorldMatrix); shader.SetMatrix("CameraInverseProjection", _camera.projectionMatrix.inverse); shader.SetVector("containerSize", Container.lossyScale); shader.SetVector("containerPos", Container.position); shader.SetVector("sampleScale", sampleScale * new Vector3(1, 2, 1)); shader.SetFloat("lowbound", lowbound); shader.SetFloat("scartterX", scartterX); shader.SetFloat("extinctionX", extinctionX); shader.SetFloat("densityScale", densityScale); shader.SetFloat("ambientStrength", ambientStrength); shader.SetFloat("erodeStrength", erodeStrength); shader.SetFloat("HGg", HGg); shader.SetFloat("Hgmin", Hgmin); shader.SetInt("channel", channel); Vector3 lightPos = Shader.GetGlobalVector("_WorldSpaceLightPos0"); shader.SetVector("lightDir", lightPos); shader.SetVector("lightCol", new Vector3(1.0f, 1.0f, 1.0f)); shader.SetVector("ambientCol", ambientCol); shader.SetVector("offset", offset); shader.SetTextureFromGlobal(0, "Depth", "_CameraDepthTexture"); shader.SetTexture(0, "Cloud", noiseGen.cloud); shader.SetTexture(0, "Worely", noiseGen.worelyTexture); shader.SetTexture(0, "Source", source); }
void OnRenderImage(RenderTexture source, RenderTexture dest) { if (computeShader == null) { Graphics.Blit(source, dest); return; } InitRenderTexture(); FindObjects(); ComputeBuffer buffer = new ComputeBuffer(objects.Count, 108); buffer.SetData(objects.ToArray()); computeShader.SetMatrix("_CameraToWorld", cam.cameraToWorldMatrix); computeShader.SetMatrix("_CameraInverseProjection", cam.projectionMatrix.inverse); computeShader.SetInt("_numShapes", objects.Count); computeShader.SetBuffer(raymarchKernel, "dataBuffer", buffer); //computeShader.SetTexture(raymarchKernel, "_SkyboxTexture", RenderSettings.skybox.mainTexture); computeShader.SetTexture(raymarchKernel, "Result", target); computeShader.Dispatch(raymarchKernel, cam.pixelWidth / 8, cam.pixelHeight / 8, 1); buffer.Release(); Graphics.Blit(target, dest); }
private void SetShaderParameters() { // Set the target and dispatch the compute shader RaymarchingShader.SetTexture(0, "Result", _target); RaymarchingShader.SetMatrix("_CameraToWorld", _camera.cameraToWorldMatrix); // _CameraToWorld declared in compute shader RaymarchingShader.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); // _CameraInverseProjection declared in compute shader RaymarchingShader.SetTexture(0, "_SkyboxTexture", SkyboxTexture); Vector3 l = DirectionalLight.transform.forward; RaymarchingShader.SetVector("_DirectionalLight", new Vector4(l.x, l.y, l.z, DirectionalLight.intensity)); RaymarchingShader.SetVector("_PixelOffset", new Vector2(Random.value, Random.value)); RaymarchingShader.SetVector("_Albedo", new Vector3(color.r, color.g, color.b)); RaymarchingShader.SetInt("_NumberOfReflections", numberOfReflections); RaymarchingShader.SetBool("_SmoothBlend", smoothBlend); RaymarchingShader.SetFloat("_BlendCoefficient", blendCoefficient); RaymarchingShader.SetVector("_Ground", ground.transform.position); RaymarchingShader.SetVector("_GroundScale", ground.transform.localScale); RaymarchingShader.SetVector("_Sphere", new Vector4(sphere.transform.position.x, sphere.transform.position.y, sphere.transform.position.z, sphereRadius)); RaymarchingShader.SetVector("_Box", box.transform.position); RaymarchingShader.SetVector("_BoxScale", box.transform.localScale); RaymarchingShader.SetVector("_Prism", prism.transform.position); RaymarchingShader.SetVector("_PrismSize", new Vector2(prism.transform.localScale.x, prism.transform.localScale.y)); RaymarchingShader.SetVector("_Torus", torus.transform.position); RaymarchingShader.SetVector("_TorusSize", new Vector2(torus.transform.localScale.x, torus.transform.localScale.y)); RaymarchingShader.SetVector("_Mandelbulb", mandelbulb.transform.position); RaymarchingShader.SetVector("_Tetrahedron", tetrahedron.transform.position); }
private void SetShaderParameters() { var kernel = rtxShader.FindKernel("CSMain"); rtxShader.SetMatrix("_CameraToWorld", _camera.cameraToWorldMatrix); rtxShader.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); rtxShader.SetVector("_PixelOffset", new Vector2(UnityEngine.Random.value - 0.5f, UnityEngine.Random.value - 0.5f)); rtxShader.SetInt("_Seed", Mathf.FloorToInt(UnityEngine.Random.value * 500)); if (_planeBuffer != null) { rtxShader.SetBuffer(kernel, "_Planes", _planeBuffer); } if (_boxBuffer != null) { rtxShader.SetBuffer(kernel, "_Boxes", _boxBuffer); } if (_sphereBuffer != null) { rtxShader.SetBuffer(kernel, "_Spheres", _sphereBuffer); } if (_discBuffer != null) { rtxShader.SetBuffer(kernel, "_Discs", _discBuffer); } if (_quadBuffer != null) { rtxShader.SetBuffer(kernel, "_Quads", _quadBuffer); } rtxShader.SetBuffer(kernel, "_Sizes", _sizeBuffer); }
private void SetShaderParameters() { RayTracingShader.SetTexture(0, "_SkyboxTexture", SkyboxTexture); RayTracingShader.SetMatrix("_CameraToWorld", _camera.transform.localToWorldMatrix); RayTracingShader.SetMatrix("_CameraInverseProjection", invProjection); RayTracingShader.SetVector("_PixelOffset", new Vector2(Random.value, Random.value)); RayTracingShader.SetFloat("_Seed", Random.value); RayTracingShader.SetVector("u_paramA", ParamA); RayTracingShader.SetVector("u_paramB", ParamB); RayTracingShader.SetVector("u_paramC", ParamC); RayTracingShader.SetVector("u_paramD", ParamD); RayTracingShader.SetVector("_SkyColor", SkyColor); RayTracingShader.SetVector("_EmisisonRange", Emission); RayTracingShader.SetVector("_ColorParam", ColorParam); RayTracingShader.SetFloat("_Palette", Palette); RayTracingShader.SetFloat("_Specular", Specular); RayTracingShader.SetFloat("_Smoothness", Smoothness); RayTracingShader.SetFloat("_Threshold", Threshold); RayTracingShader.SetFloat("_Steps", Steps); RayTracingShader.SetFloat("_LEVELS", Levels); _addMaterial.SetFloat("_Sample", _currentSample); _addMaterial.SetFloat("_Exposure", Exposure); _addMaterial.SetTexture("_Depth", _targetDepth); }
public virtual void SetDynamicShaderParameters() { rayMarchingShader.SetMatrix("cameraToWorld", _camera.cameraToWorldMatrix); rayMarchingShader.SetMatrix("cameraInverseProjection", _camera.projectionMatrix.inverse); float[] light = new float[3]; if (lighting != null) { if (lighting.type == LightType.Directional) { light[0] = lighting.transform.forward.x; light[1] = lighting.transform.forward.y; light[2] = lighting.transform.forward.z; rayMarchingShader.SetBool("lightIsPoint", false); } else { light[0] = lighting.transform.position.x; light[1] = lighting.transform.position.y; light[2] = lighting.transform.position.z; rayMarchingShader.SetBool("lightIsPoint", true); } } else { light[0] = -1; light[1] = 0; light[2] = 0; rayMarchingShader.SetBool("lightIsPoint", false); } rayMarchingShader.SetFloats("light", light); }
private void OnRenderImage(RenderTexture source, RenderTexture destination) { if (mActive) { PreRender(); InitTexture(); mShader.SetTexture(0, "Source", source); mShader.SetTexture(0, "Destination", mResult); mShader.SetMatrix("CameraToWorldMatrix", mCamera.cameraToWorldMatrix); mShader.SetMatrix("CameraInverseProjectionMatrix", mCamera.projectionMatrix.inverse); mShader.SetVector("LightDirection", mDirectionalLight.transform.forward); mShader.SetTexture(0, "GrassTexture", Grass); mShader.SetTexture(0, "RockTexture", Rock); mShader.SetTexture(0, "GrassNormal", GrassNormal); mShader.SetTexture(0, "RockNormal", RockNormal); int XThreads = Mathf.CeilToInt(mCamera.pixelWidth / 32.0f); int YThreads = Mathf.CeilToInt(mCamera.pixelHeight / 32.0f); mShader.Dispatch(0, XThreads, YThreads, 1); Graphics.Blit(mResult, destination); } else { Graphics.Blit(source, destination); } }
private void SetShaderParameters() { RayMarchingShader.SetMatrix("_CameraToWorld", _camera.cameraToWorldMatrix); RayMarchingShader.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); RayMarchingShader.SetTexture(0, "_SkyboxTexture", SkyboxTexture); Vector3 l = DirectionalLight.transform.forward; var lc = DirectionalLight.color; RayMarchingShader.SetVector("_DirectionalLight", new Vector4(l.x, l.y, l.z, DirectionalLight.intensity)); RayMarchingShader.SetVector("_DirectionalLightColor", new Vector3(lc.r / 255f, lc.g / 255f, lc.b / 255f)); RayMarchingShader.SetFloat("_SoftShadowStrength", SoftShadowStrength); RayMarchingShader.SetInt("_Bounces", Bounces); RayMarchingShader.SetFloat("_Specular", Specular); RayMarchingShader.SetVector("_Albedo", new Vector3(Albedo.r, Albedo.g, Albedo.b)); RayMarchingShader.SetFloat("_Time", Time.time); RayMarchingShader.SetVector("_GlowColor", new Vector3(GlowColor.r, GlowColor.g, GlowColor.b)); RayMarchingShader.SetFloat("_GlowStrength", GlowStrength); RayMarchingShader.SetInt("_GlowCutoff", GlowCutoff); RayMarchingShader.SetFloat("_SurfaceDistance", SurfaceDistance); RayMarchingShader.SetFloat("_DofSmoothness", DofSmoothness); RayMarchingShader.SetFloat("_DofRadius", DofRadius); RayMarchingShader.SetFloat("_DofRange", DofRange); }
private void SetShaderParameters() { RayTracingShader.SetTexture(0, "_SkyboxTexture", SkyboxTexture); RayTracingShader.SetMatrix("_CameraToWorld", _camera.cameraToWorldMatrix); RayTracingShader.SetMatrix("_CameraInverseProjection", _camera.projectionMatrix.inverse); RayTracingShader.SetVector("_PixelOffset", 1024f * new Vector2(UnityEngine.Random.value, UnityEngine.Random.value)); RayTracingShader.SetFloat("_Seed", UnityEngine.Random.value); RayTracingShader.SetVector("u_paramA", ParamA); RayTracingShader.SetVector("u_paramB", ParamB); RayTracingShader.SetVector("u_paramC", ParamC); RayTracingShader.SetVector("u_paramD", ParamD); RayTracingShader.SetVector("_SkyColorA", SkyColorA); RayTracingShader.SetVector("_SkyColorB", SkyColorB); RayTracingShader.SetVector("_EmisisonRange", Emission); RayTracingShader.SetVector("_ColorParam", ColorParam); if (m_quaternionTransform != null) { RayTracingShader.SetVector("_Quaternion", new Vector4( m_quaternionTransform.localRotation.x, m_quaternionTransform.localRotation.y, m_quaternionTransform.localRotation.y, m_quaternionTransform.localRotation.w)); } RayTracingShader.SetFloat("_StepRatio", _StepRatio); RayTracingShader.SetFloat("_Palette", Palette); RayTracingShader.SetFloat("_Saturation", Saturation); RayTracingShader.SetFloat("_Specular", Specular); RayTracingShader.SetFloat("_Smoothness", Smoothness); RayTracingShader.SetFloat("_Threshold", Threshold); RayTracingShader.SetFloat("_Steps", Steps); RayTracingShader.SetFloat("_LEVELS", Levels); RayTracingShader.SetFloat("_Gamma", Gamma); RayTracingShader.SetFloat("_RNG", UnityEngine.Random.value); RayTracingShader.SetFloat("_TFAR", _camera.farClipPlane); RayTracingShader.SetFloat("_SPP", SPP); RayTracingShader.SetFloat("_Bounces", Bounces); _addMaterial.SetFloat("_Sample", _currentSample); _addMaterial.SetTexture("_Depth", _targetDepth); if (!_previz) { _tonemapper.SetFloat("_Exposure", Exposure); _tonemapper.SetFloat("_Gamma", Gamma); } else { _tonemapper.SetFloat("_Exposure", 1); _tonemapper.SetFloat("_Gamma", 0.5f); } }